one way to do it is to use named parameters
package Dragon; sub _init { my $self = shift; my %args = @_; foreach my $key qw(NAME AGE COLOR) { $self->{$key} = $args{$key}; } $self->awaken(); } package Trogdor; sub new { my $class = shift; $class->new(@_, NAME => "Trogdor", AGE => "one year old"; COLOR => "green"); }
If the values are overridable, put @_ at the end of the parameter list.
In reply to Re: oo design q: SUPER::_init
by lestrrat
in thread oo design q: SUPER::_init
by alienhuman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |