c:\@Work\Perl\monks>perl -wMstrict -le
"use 5.014;
;;
package Foo {
sub defaults {
return { 'default' => 'zing' };
}
sub new {
my $class = shift;
my ($hr_args) = @_;
my $obj = { %{ $class->defaults }, %{ $hr_args || {} } };
return bless $obj => $class;
}
sub show {
my $self = shift;
print qq{@{[ %$self ]} @_};
}
}
;;
package Bar {
use parent -norequire, qw(Foo);
sub show {
my $self = shift;
$self->SUPER::show('from ' . __PACKAGE__, @_);
}
}
;;
my $b = Bar->new({ 'hi' => 'there' });
$b->show('zoot');
;;
use Data::Dump qw(dd);
;;
dd $b;
"
hi there default zing from Bar zoot
bless({ default => "zing", hi => "there" }, "Bar")
####
...
print ref $b;
####
Bar