Commits

Herbert Breunung  committed 3c2c449

rename App::Helper to App::Util

  • Participants
  • Parent commits 2973208

Comments (0)

Files changed (10)

File lib/Kephra/App/Bar/Document.pm

 use Wx;
 use Wx::DND;
 use Kephra::App::Editor;
-use Kephra::App::Helper;
+use Kephra::App::Util;
 
 package Kephra::App::Bar::Document;
 our @ISA = 'Wx::AuiNotebook';
 
-my $put_on_panel = Kephra::App::Helper::get('put_on_panel');
+my $put_on_panel = Kephra::App::Util::get('put_on_panel');
 
 sub new {
     my( $class, $parent) = @_;

File lib/Kephra/App/Editor.pm

 #use Wx::DND;
 #use Wx::STC;
 use Wx::Scintilla;
-use Kephra::App::Helper;
+use Kephra::App::Util;
 
 package Kephra::App::Editor;
 #our @ISA = 'Wx::StyledTextCtrl';
 our @ISA = 'Wx::ScintillaTextCtrl';
     
-my $mk_color = Kephra::App::Helper::get('make_color');
+my $mk_color = Kephra::App::Util::get('make_color');
 
 sub new {
     my( $class, $parent, $style) = @_;
 
 sub set_colors {
     my $self = shift;
-    my $color = Kephra::App::Helper::get('make_color');
+    my $color = Kephra::App::Util::get('make_color');
     $self->SetCaretLineBack( $mk_color->(245,245,161) );
     $self->SetCaretPeriod( 500 );
     $self->SetCaretWidth( 2 );

File lib/Kephra/App/Helper.pm

-use strict;
-use warnings;
-
-package Kephra::App::Helper;
-
-sub get {
-    my ($ref, @method_ref);
-    die unless @_;
-    for my $subname (@_){
-        eval { $ref = \&{__PACKAGE__ . "::$subname"} };
-        if ($@) { die "__PACKAGE__::get : no $subname sub in this Module." }
-        else    { push @method_ref, $ref }
-    }
-    if (wantarray){ return @method_ref }
-    else          { return $method_ref[0] }
-}
-
-sub is_object { ( ref $_[0] and index(ref $_[0], '=') == -1) ? 1 : 0 }
-sub is_widget { ( is_object( $_[0] ) and $_[0]->isa('Wx::Control') ) ? 1 : 0 }
-sub is_panel  { ( is_object( $_[0] ) and $_[0]->isa('Wx::Panel') ) ? 1 : 0 }
-sub is_sizer  { ( is_object( $_[0] ) and $_[0]->isa('Wx::Sizer') ) ? 1 : 0 }
-
-sub put_on_panel {
-    my ($widget, $parent) = @_;
-    my ($panel, $sizer);
-    my $name = __PACKAGE__ . '::put_on_panel';
-    if ( is_widget($widget) ){
-        $panel = Wx::Panel->new( $widget->GetParent );
-        $widget->Reparent( $panel );
-        $sizer = Wx::BoxSizer->new( &Wx::wxVERTICAL );
-        $sizer->Add( $widget, 1, &Wx::wxGROW );
-    } 
-    elsif ( is_sizer($widget) ) {
-        die "$name needs parent widget when andling a sizer"
-            unless is_widget( $parent );
-        $panel = Wx::Panel->new( $parent );
-        $sizer = $widget;
-        my $cc = 0;
-        while (my $child = $sizer->GetItem($cc++)){
-            $child->Reparent( $panel );
-        }
-    }
-    else { die "$name needs widget or sizer as first parameter" }
-
-    $panel->SetSizer( $sizer );
-    return $panel;
-}
-
-sub is_color { ( is_object( $_[0] ) and $_[0]->isa('Wx::Colour') and $_[0]->IsOk ) ? 1 : 0 }
-
-sub make_color {
-    my ($r, $g, $b, $t ) = @_;
-    my $name = __PACKAGE__ . '::make_color';
-    my $usage = "$name takes 1 parameter (hex-'12345f' or dec-'0,0,1' or name) or 3 parameters (R, G, B)";
-    die "not enough parmaters\n$usage" unless defined $r;
-    unless (defined $g){
-        # handle hex format like in HTML: #234567
-        if ( $r =~ /^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i ) {
-            ($r,$g,$b) = ( hex $1, hex $2, hex $3 );
-        }
-        # handle comma-seperated format: 0,0,125
-        elsif ( $r =~ /^(\d+),\s*(\d+),\s*(\d+)$/ ) {
-            ($r,$g,$b) = ( $1+0, $2+0, $3+0 );
-        } else {
-            my %color = (
-                'white' => [255, 255, 255],
-                'red'   => [255,   0,   0],
-                'orange'=> [255, 127,   0],
-                'yellow'=> [255, 255,   0],
-                'green' => [  0, 255,   0],
-                'cyan'  => [  0, 255, 255],
-                'blue'  => [  0,   0, 255],
-                'purple'=> [255,   0, 255],
-                'violet'=> [255,   0, 255],
-                'grey'  => [180, 180, 180],
-                'black' => [  0,   0,   0],
-            );
-            if ( exists $color{lc $r} ) {  ( $r, $g, $b ) = @{ $color{lc $r} }  }
-            else {
-                my $c = Wx::ColourDatabase::Find( $r );
-                return $c if is_color( $c );
-            }
-            unless (defined $g) {
-                my @clist = ( (keys %color),
-                    'AQUAMARINE', 'BLACK', 'BLUE', 'BLUE VIOLET', 'BROWN',
-                    'CADET BLUE', 'CORAL', 'CORNFLOWER BLUE', 'CYAN', 'DARK GREY',
-                    'DARK GREEN', 'DARK OLIVE GREEN', 'DARK ORCHID', 'DARK SLATE BLUE',
-                    'DARK SLATE GREY', 'DARK TURQUOISE, DIM GREY, FIREBRICK',
-                    'FOREST GREEN', 'GOLD', 'GOLDENROD', 'GREY, GREEN', 'GREEN YELLOW',
-                    'INDIAN RED', 'KHAKI', 'LIGHT BLUE', 'LIGHT GREY', 'LIGHT STEEL BLUE',
-                    'LIME GREEN', 'MAGENTA', 'MAROON', 'MEDIUM AQUAMARINE', 'MEDIUM BLUE',
-                    'MEDIUM FOREST GREEN', 'MEDIUM GOLDENROD', 'MEDIUM ORCHID', 
-                    'MEDIUM SEA GREEN', 'MEDIUM SLATE BLUE', 'MEDIUM SPRING GREEN',
-                    'MEDIUM TURQUOISE', 'MEDIUM VIOLET RED', 'MIDNIGHT BLUE, NAVY',
-                    'ORANGE', 'ORANGE RED', 'ORCHID', 'PALE GREEN', 'PINK', 'PLUM',
-                    'PURPLE', 'RED, SALMON', 'SEA GREEN', 'SIENNA', 'SKY BLUE',
-                    'SLATE BLUE', 'SPRING GREEN', 'STEEL BLUE', 'TAN', 'THISTLE',
-                    'TURQUOISE', 'VIOLET', 'VIOLET RED', 'WHEAT', 'WHITE', 'YELLOW',
-                    'YELLOW GREEN',
-                );
-                die "$r is an unknow color name, just know @clist";
-            }
-        }
-    }
-    die "not enough parmaters or bad format\n$usage" unless defined $b;
-    die "too much parmaters\n$usage" if defined $t;
-    die "red definition is outside of 0..255" unless int $r == $r && $r>=0 && $r<=255;
-    die "green definition is outside of 0..255" unless int $g == $g && $g>=0 && $g<=255;
-    die "blue definition is outside of 0..255" unless int $b == $b && $b>=0 && $b<=255;
-    return Wx::Colour->new($r, $g, $b);
-}
-
-1;
-
-__END__
-
-    #my $normal_font = Wx::Font->new (
-        #12, 
-        #&Wx::wxFONTFAMILY_DEFAULT,
-        #&Wx::wxFONTSTYLE_NORMAL,
-        #&Wx::wxFONTWEIGHT_NORMAL,
-        #0,
-    #);
-    #my $highlight_font = Wx::Font->new (
-        #12, 
-        #&Wx::wxFONTFAMILY_TELETYPE,
-        #&Wx::wxFONTSTYLE_NORMAL,
-        #&Wx::wxFONTWEIGHT_BOLD,
-        #1,
-    #);

File lib/Kephra/App/Panel/IOUnit.pm

 use strict;
 use warnings;
 use Wx::AUI;
-use Kephra::App::Helper;
+use Kephra::App::Util;
 
 package Kephra::App::Panel::IOUnit;
 our @ISA = 'Wx::Panel';

File lib/Kephra/App/Util.pm

+use strict;
+use warnings;
+
+package Kephra::App::Util;
+
+sub get {
+    my ($ref, @method_ref);
+    die unless @_;
+    for my $subname (@_){
+        eval { $ref = \&{__PACKAGE__ . "::$subname"} };
+        if ($@) { die "__PACKAGE__::get : no $subname sub in this Module." }
+        else    { push @method_ref, $ref }
+    }
+    if (wantarray){ return @method_ref }
+    else          { return $method_ref[0] }
+}
+
+sub is_object { ( ref $_[0] and index(ref $_[0], '=') == -1) ? 1 : 0 }
+sub is_widget { ( is_object( $_[0] ) and $_[0]->isa('Wx::Control') ) ? 1 : 0 }
+sub is_panel  { ( is_object( $_[0] ) and $_[0]->isa('Wx::Panel') ) ? 1 : 0 }
+sub is_sizer  { ( is_object( $_[0] ) and $_[0]->isa('Wx::Sizer') ) ? 1 : 0 }
+
+sub put_on_panel {
+    my ($widget, $parent) = @_;
+    my ($panel, $sizer);
+    my $name = __PACKAGE__ . '::put_on_panel';
+    if ( is_widget($widget) ){
+        $panel = Wx::Panel->new( $widget->GetParent );
+        $widget->Reparent( $panel );
+        $sizer = Wx::BoxSizer->new( &Wx::wxVERTICAL );
+        $sizer->Add( $widget, 1, &Wx::wxGROW );
+    } 
+    elsif ( is_sizer($widget) ) {
+        die "$name needs parent widget when andling a sizer"
+            unless is_widget( $parent );
+        $panel = Wx::Panel->new( $parent );
+        $sizer = $widget;
+        my $cc = 0;
+        while (my $child = $sizer->GetItem($cc++)){
+            $child->Reparent( $panel );
+        }
+    }
+    else { die "$name needs widget or sizer as first parameter" }
+
+    $panel->SetSizer( $sizer );
+    return $panel;
+}
+
+sub is_color { ( is_object( $_[0] ) and $_[0]->isa('Wx::Colour') and $_[0]->IsOk ) ? 1 : 0 }
+
+sub make_color {
+    my ($r, $g, $b, $t ) = @_;
+    my $name = __PACKAGE__ . '::make_color';
+    my $usage = "$name takes 1 parameter (hex-'12345f' or dec-'0,0,1' or name) or 3 parameters (R, G, B)";
+    die "not enough parmaters\n$usage" unless defined $r;
+    unless (defined $g){
+        # handle hex format like in HTML: #234567
+        if ( $r =~ /^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i ) {
+            ($r,$g,$b) = ( hex $1, hex $2, hex $3 );
+        }
+        # handle comma-seperated format: 0,0,125
+        elsif ( $r =~ /^(\d+),\s*(\d+),\s*(\d+)$/ ) {
+            ($r,$g,$b) = ( $1+0, $2+0, $3+0 );
+        } else {
+            my %color = (
+                'white' => [255, 255, 255],
+                'red'   => [255,   0,   0],
+                'orange'=> [255, 127,   0],
+                'yellow'=> [255, 255,   0],
+                'green' => [  0, 255,   0],
+                'cyan'  => [  0, 255, 255],
+                'blue'  => [  0,   0, 255],
+                'purple'=> [255,   0, 255],
+                'violet'=> [255,   0, 255],
+                'grey'  => [180, 180, 180],
+                'black' => [  0,   0,   0],
+            );
+            if ( exists $color{lc $r} ) {  ( $r, $g, $b ) = @{ $color{lc $r} }  }
+            else {
+                my $c = Wx::ColourDatabase::Find( $r );
+                return $c if is_color( $c );
+            }
+            unless (defined $g) {
+                my @clist = ( (keys %color),
+                    'AQUAMARINE', 'BLACK', 'BLUE', 'BLUE VIOLET', 'BROWN',
+                    'CADET BLUE', 'CORAL', 'CORNFLOWER BLUE', 'CYAN', 'DARK GREY',
+                    'DARK GREEN', 'DARK OLIVE GREEN', 'DARK ORCHID', 'DARK SLATE BLUE',
+                    'DARK SLATE GREY', 'DARK TURQUOISE, DIM GREY, FIREBRICK',
+                    'FOREST GREEN', 'GOLD', 'GOLDENROD', 'GREY, GREEN', 'GREEN YELLOW',
+                    'INDIAN RED', 'KHAKI', 'LIGHT BLUE', 'LIGHT GREY', 'LIGHT STEEL BLUE',
+                    'LIME GREEN', 'MAGENTA', 'MAROON', 'MEDIUM AQUAMARINE', 'MEDIUM BLUE',
+                    'MEDIUM FOREST GREEN', 'MEDIUM GOLDENROD', 'MEDIUM ORCHID', 
+                    'MEDIUM SEA GREEN', 'MEDIUM SLATE BLUE', 'MEDIUM SPRING GREEN',
+                    'MEDIUM TURQUOISE', 'MEDIUM VIOLET RED', 'MIDNIGHT BLUE, NAVY',
+                    'ORANGE', 'ORANGE RED', 'ORCHID', 'PALE GREEN', 'PINK', 'PLUM',
+                    'PURPLE', 'RED, SALMON', 'SEA GREEN', 'SIENNA', 'SKY BLUE',
+                    'SLATE BLUE', 'SPRING GREEN', 'STEEL BLUE', 'TAN', 'THISTLE',
+                    'TURQUOISE', 'VIOLET', 'VIOLET RED', 'WHEAT', 'WHITE', 'YELLOW',
+                    'YELLOW GREEN',
+                );
+                die "$r is an unknow color name, just know @clist";
+            }
+        }
+    }
+    die "not enough parmaters or bad format\n$usage" unless defined $b;
+    die "too much parmaters\n$usage" if defined $t;
+    die "red definition is outside of 0..255" unless int $r == $r && $r>=0 && $r<=255;
+    die "green definition is outside of 0..255" unless int $g == $g && $g>=0 && $g<=255;
+    die "blue definition is outside of 0..255" unless int $b == $b && $b>=0 && $b<=255;
+    return Wx::Colour->new($r, $g, $b);
+}
+
+1;
+
+__END__
+
+    #my $normal_font = Wx::Font->new (
+        #12, 
+        #&Wx::wxFONTFAMILY_DEFAULT,
+        #&Wx::wxFONTSTYLE_NORMAL,
+        #&Wx::wxFONTWEIGHT_NORMAL,
+        #0,
+    #);
+    #my $highlight_font = Wx::Font->new (
+        #12, 
+        #&Wx::wxFONTFAMILY_TELETYPE,
+        #&Wx::wxFONTSTYLE_NORMAL,
+        #&Wx::wxFONTWEIGHT_BOLD,
+        #1,
+    #);

File t/200-apphelper.t

-#!usr/bin/perl
-
-# making local lib favoured
-BEGIN { unshift @INC, -d 't' ? 'lib' : '../lib' }
-
-use Test::More tests => 15;
-#use Text::Exception;
-use Test::NoWarnings;
-
-use Wx;
-use Kephra::App::Helper;
-
-# testing the function that gives references to the helper functions
-my $testcolor = Kephra::App::Helper::get('is_color');
-my @chref = Kephra::App::Helper::get('is_color', 'make_color');
-is( $testcolor, \&Kephra::App::Helper::is_color, 'get a helper function reference');
-is_deeply( \@chref, [ \&Kephra::App::Helper::is_color, \&Kephra::App::Helper::make_color ], 
-    'get several helper references');
-my $mk_color = $chref[1];
-
-# color helper
-my $white = Wx::Colour->new(255, 255, 255);
-is( Kephra::App::Helper::is_color(0),      0, 'can detect what is not a color object');
-is( Kephra::App::Helper::is_color($white), 1, 'can detect what is a color object');
-is( $testcolor->($white), 1, 'refernce works too');
-is( $testcolor->( $mk_color->(0,0,255) ), 1, 'R,G,B input layout works ');
-is( $testcolor->( $mk_color->("0,0,255") ), 1, '"R,G,B" input layout works');
-is( $testcolor->( $mk_color->("#0000FF") ), 1, '"#RRGGBB" input layout works');
-is( $testcolor->( $mk_color->("0000ff") ), 1, '"RRGGBB" input layout works');
-is( $testcolor->( $mk_color->("blue") ), 1,'"colorname" input layout works');
-is( $testcolor->( $mk_color->("WHEAT") ), 1,'"colorname" input layout works with db names');
-
-# gui contruction helper
-my $popanel = Kephra::App::Helper::get('put_on_panel');
-my $testpanel = Kephra::App::Helper::get('is_panel');
-my $button = Wx::Button->new(undef,-1,'');
-my $panel = Wx::Panel->new(undef);
-is( $testpanel->( $white ), 0, 'can detect what is not a panel');
-is( $testpanel->( $panel ), 1, 'can detect panel');
-is( $testpanel->( $popanel->($button) ), 1, 'can detect panel');
-
-exit(0);
-

File t/200-apputil.t

+#!usr/bin/perl
+
+# making local lib favoured
+BEGIN { unshift @INC, -d 't' ? 'lib' : '../lib' }
+
+use Test::More tests => 15;
+#use Text::Exception;
+use Test::NoWarnings;
+
+use Wx;
+use Kephra::App::Util;
+
+# testing the function that gives references to the helper functions
+my $testcolor = Kephra::App::Util::get('is_color');
+my @chref = Kephra::App::Util::get('is_color', 'make_color');
+is( $testcolor, \&Kephra::App::Util::is_color, 'get a helper function reference');
+is_deeply( \@chref, [ \&Kephra::App::Util::is_color, \&Kephra::App::Util::make_color ], 
+    'get several helper references');
+my $mk_color = $chref[1];
+
+# color helper
+my $white = Wx::Colour->new(255, 255, 255);
+is( Kephra::App::Util::is_color(0),      0, 'can detect what is not a color object');
+is( Kephra::App::Util::is_color($white), 1, 'can detect what is a color object');
+is( $testcolor->($white), 1, 'refernce works too');
+is( $testcolor->( $mk_color->(0,0,255) ), 1, 'R,G,B input layout works ');
+is( $testcolor->( $mk_color->("0,0,255") ), 1, '"R,G,B" input layout works');
+is( $testcolor->( $mk_color->("#0000FF") ), 1, '"#RRGGBB" input layout works');
+is( $testcolor->( $mk_color->("0000ff") ), 1, '"RRGGBB" input layout works');
+is( $testcolor->( $mk_color->("blue") ), 1,'"colorname" input layout works');
+is( $testcolor->( $mk_color->("WHEAT") ), 1,'"colorname" input layout works with db names');
+
+# gui contruction helper
+my $popanel = Kephra::App::Util::get('put_on_panel');
+my $testpanel = Kephra::App::Util::get('is_panel');
+my $button = Wx::Button->new(undef,-1,'');
+my $panel = Wx::Panel->new(undef);
+is( $testpanel->( $white ), 0, 'can detect what is not a panel');
+is( $testpanel->( $panel ), 1, 'can detect panel');
+is( $testpanel->( $popanel->($button) ), 1, 'can detect panel');
+
+exit(0);
+

File t/310-editor.t

+#!usr/bin/perl
+
+# making local lib favoured
+BEGIN { unshift @INC, -d 't' ? 'lib' : '../lib' }
+
+use Test::More tests => 2;
+use Test::NoWarnings;
+
+ok(1, 'there will be tests');
+
+exit(0);

File t/310-editpanel.t

-#!usr/bin/perl
-
-# making local lib favoured
-BEGIN { unshift @INC, -d 't' ? 'lib' : '../lib' }
-
-use Test::More tests => 2;
-use Test::NoWarnings;
-
-ok(1, 'there will be tests');
-
-exit(0);

File t/KephraTesting.pod

 
 1  Config: 	load, manipulate and store file and default configs
 
-2  helper functions (App::Helper)   
+2  helper functions (App::Util)   
 
 3  app namespace