1 2 3 4 5 6 7 8 9
sub AUTOLOAD { my $self = shift; my ($method) = (our $AUTOLOAD) =~ /^SUPER::Package::MyPackage::(\w+)$/ or die "Curious value at AUTOLOAD: $AUTOLOAD"; bless $self, 'SUPER::Package'; $self->$method(@_); bless $self, 'SUPER::Package::MyPackage'; }
1 2 3 4
sub AUTOLOAD { my ($namespace,$method) = (our $AUTOLOAD) =~ /(.*)::(.*)/; # ... }
1 2 3 4 5 6
sub AUTOLOAD { my $self = shift; my ($package, $method) = (our $AUTOLOAD =~ m/^(.*)::(.*)$/); $method = "Foo::$method"; return $self->$method(@_); }
1 2 3 4
sub AUTOLOAD { my ($package, $method) = (our $AUTOLOAD =~ m/^(.*)::(.*)$/); goto &{"Foo::$method"}; }
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
sub AUTOLOAD{ my $self = shift; my $fname = do{ our $AUTOLOAD =~ /(\w+)$/; $1; }; require "factory/$fname.pm"; return $self->can($fname) ? do{ my $code = $self->can($fname); $self->$code(@_); } : undef; } # Beispiel einer Methode use strict; use warnings; sub localtime{ my $self = shift; my $time = shift || time; my %hunt = (); my @fields = qw(sec min hour mday mon year wday yday isdst); @hunt{@fields} = localtime($time); $hunt{year} += 1900; $hunt{mon} += 1; return \%hunt; }; 1; # UNIT TEST use Data::Dumper; $, = "\n"; my $m = bless{}; print Dumper $m->localtime();