in reply to Extending objects
#### Foobar.pm ##### package Foobar; use Foo; use Bar; our @ISA = qw[Foo Bar]; sub new {bless {}, shift} sub init { my $self = shift; my %args = @_; $self->Foo::init(name => $args{name}) ->Bar::init(age => $args{age}); $self; } 1; #### Foo.pm #### package Foo; sub new {bless {}, shift} sub init { my $self = shift; my %args = @_; $self->{name} = $args{name}; $self; } sub name {$_[0]{name}} 1; #### Bar.pm #### package Bar; sub new {bless {}, shift} sub init { my $self = shift; my %args = @_; $self->{age} = $args{age}; $self; } sub age {$_[0]{age}} 1; #### foobar.pl #### use Foobar; my $o = Foobar->new->init(name => 'Tom', age => 23);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Extending objects
by punkish (Priest) on Jul 07, 2010 at 15:23 UTC | |
by JavaFan (Canon) on Jul 07, 2010 at 15:33 UTC |