7 Einträge, 1 Seite |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
package classes::module_proto; our %ActionsHash = ( "list" => { 'postaction' => \&list_all, }, "edit" => { 'postaction' => \&edit_one, }, ); sub new { my ($pkg, $name ) = @_; #------------------ my $Self = {}; #------------------ bless( $Self, (ref $pkg || $pkg) ); $Self->{'ActionHash'} = \%ActionsHash; # ... return $Self; } sub _handle_event { my $Self = shift; my $action = shift; # ... my $func = $actionshash->{ $action }->{'postaction'} ; # ... ($result, $error) = $func->(@_) ; # ... return ($result, $error); } sub edit_one { my $Self = shift; # ... return ( 1, undef); } sub list_all { my $Self = shift; # ... return ( 1, undef); } #------- package classes::module_sources; use classes::module_proto; our @ISA = qw(classes::module_proto); my %SourcesActionsHash = ( "list" => { 'postaction' => \&list_all, }, "edit" => { 'postaction' => \&edit_one, }, ); sub new { my ($pkg, $name ) = @_; #------------------ my $Self = $pkg->SUPER::new( $name ); bless( $Self, (ref $pkg || $pkg) ); $Self->{'ActionHash'} = \%SourcesActionsHash; return $Self; } sub list_all { my $Self = shift; # ... tu etwas spezielles mit sources return ( 1, undef); } #------- 1;
"edit" => { 'postaction' => \&classes::module_proto::edit_one }
"edit" => { 'postaction' => sub { $_[0]->edit_one } }
quellen:module_proto::_handle_event(15): Eintrag gefunden:'CODE(0x1947640)'; $_0='classes::module_sources=HASH(0x197828c)'!;
1
2
3
4
Undefined subroutine &classes::module_sources::edit_one called at
../../../cgi-bin/classes/module_sources.pm line 66, <file1> line 162 (#4)
(F) The subroutine indicated hasn't been defined, or if it was, it has
since been undefined.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
#!/usr/bin/perl package classes::module_proto; use strict; use warnings; our %ActionsHash = ( "list" => { 'postaction' => sub { $_[0]->list_all() } }, "edit" => { 'postaction' => sub { $_[0]->edit_one() } }, ); sub new { my ($pkg, $name ) = @_; #------------------ my $Self = {}; #------------------ bless( $Self, (ref $pkg || $pkg) ); $Self->{'ActionHash'} = \%ActionsHash; # ... return $Self; } sub _handle_event { my $Self = shift; my $action = shift; # ... my $func = $ActionsHash{ $action }{'postaction'} ; # ... my ($result, $error) = $func->( $Self, $action ) ; # ... return ($result, $error); } sub edit_one { my $Self = shift; # ... return ( 1, undef); } sub list_all { my $Self = shift; # ... return ( 1, undef); } #------- package classes::module_sources; use strict; use warnings; our @ISA = qw( classes::module_proto ); my %SourcesActionsHash = ( "list" => { 'postaction' => sub { $_[0]->list_all() } }, "edit" => { 'postaction' => sub { $_[0]->edit_one() } }, ); sub new { my ($pkg, $name ) = @_; #------------------ my $Self = $pkg->SUPER::new( $name ); bless( $Self, (ref $pkg || $pkg) ); $Self->{'ActionHash'} = \%SourcesActionsHash; return $Self; } sub list_all { my $Self = shift; # ... tu etwas spezielles mit sources return ( 1, undef); } #------- package main; use strict; use warnings; use Data::Dumper; my $sources = classes::module_sources->new(); print Dumper $sources->_handle_event( 'edit' ); <STDIN>; __END__
%ActionsHash
032: my $func = $Self->{'ActionHash'}->{ $action }->{'postaction'} ;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
sub _handle_event { my $Self = $_[0]; #my $actionarr = $_[1]; #---- my $dphase = 0; #$actionarr->[0]; my $module = ''; #$actionarr->[1]; my $action = 'edit'; #$actionarr->[2] ; #---- my $phase = $dphase ? 'doaction' : 'postaction'; my $result; my $error; my $actionshash = $Self->{'ActionHash'}; #------- if( exists $actionshash->{ $action }->{ $phase } && defined $actionshash->{ $action }->{ $phase } && ref( $actionshash->{ $action }->{ $phase } ) eq 'CODE') { my $func = $actionshash->{ $action }->{$phase} ; #------- if(!$dphase) { ($result, $error) = $func->( @_ ) ; } else { } } else { die "Kein ausfuehrbarer Eintrag gefunden!;"; } return ($result, $error); }
Gast+2008-08-01 01:06:41--Bei Dir gehts, aber Du hast auch etwas geflunkert, denn in Zeile 032 greifst Du direkt auf den Klassen-Hash ActionsHash und so wird die Vererbung nicht gefordert.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
my %SourcesActionsHash = ( "new" => { 'right' => {"admin" => ''}, 'doaction' => undef, 'nextaction' => \&edit_one, 'erroraction' => 'list_all', }, );
7 Einträge, 1 Seite |