Created
September 12, 2016 11:22
-
-
Save simonamor/83a0859498359c8ad598b482214adfc3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package MyApp::Base; | |
sub new { | |
my $class = shift; | |
my $self = { abc => "def", xyz => "123" }; | |
bless $self, $class; | |
return $self; | |
} | |
sub get_abc { | |
my $self = shift; | |
return "base: " . $self->{ abc }; | |
} | |
sub get_xyz { | |
my $self = shift; | |
return "base: " . $self->{ xyz }; | |
} | |
package MyApp::Obj; | |
use base 'MyApp::Base'; | |
sub get_abc { | |
my $self = shift; | |
return "obj: " . $self->SUPER::get_abc(@_); | |
} | |
foreach my $fn (qw/get_xyz/) { | |
warn $fn; | |
*$fn = sub { | |
my $self = shift; | |
# warn "$fn: " . Dumper(\@); | |
# return $self->SUPER::$fn(@_); | |
return $self->SUPER::$fn(@_); | |
}; | |
} | |
package main; | |
my $o = MyApp::Obj->new(); | |
print "abc = " . $o->get_abc() . "\n"; | |
print "xyz = " . $o->get_xyz() . "\n"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment