Skip to content

Instantly share code, notes, and snippets.

@simonamor
Created September 12, 2016 11:22
Show Gist options
  • Save simonamor/83a0859498359c8ad598b482214adfc3 to your computer and use it in GitHub Desktop.
Save simonamor/83a0859498359c8ad598b482214adfc3 to your computer and use it in GitHub Desktop.
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