1 2 3 4 5 6 7 8 9 10 11 12
#!/usr/bin/perl use strict; use MyModels::Main::Result::User; use DecoratorHistory; my $prj = new MyModels::Main::Result::User( ... ); $prj = new DecoratorHistory($prj); my $p = $prj->search( {project_id => 12 } , {} )->single();
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
package DecoratorHistory; use strict; use vars '$AUTOLOAD'; sub new { my ($class, @args) = @_; my $self = bless {}, ref($class) || $class; $self->_init(@args); return $self; } sub _init { my ($self, @args) = @_; $self->{_object} = shift @args; } sub AUTOLOAD { my ($self, @args) = @_; my $function = $AUTOLOAD; $function =~ s/^(.*::)//; return if ($function eq 'DESTROY'); # - - my $o = "$self->{_object}->$function"; my $r = $o->( @args ); ###### <- klappt nicht... # - add extra behaviour - if ($function eq 'update') { # eigene weitere Aktionen... } # if return $r; } 1;
my $o = "$self->{_object}->$function";
my $r = $self->{_object}->$function( ... );
my $coderef = $self->{_object}->can($function)
my $r = $self->{_object}->$function( ... );