in reply to OO Perl: calling a constructor within a class
BTW, there'll be a new version of Class::Multimethods out in the next month or two that lets you define multimethods like they will (probably) be written in Perl 6:package MyClass; use Class::Multimethods; multimethod new =>('$') => sub { my ($class) = @_; bless { name => '', rank => '', cereal_number => '', }, $class; } multimethod new =>('$','$','$','$') => sub { my ($class, $name, $rank, $c_num ) = @_; bless { name => $name, rank => $rank, cereal_number => $cnum, }, $class; }
Damianpackage MyClass; use Class::Multimethods::Attributes; sub new :multi ($class) { bless { name => '', rank => '', cereal_number => '', }, $class; } sub new :multi ($class, $name, $rank, $c_num) { bless { name => $name, rank => $rank, cereal_number => $cnum, }, $class; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: OO Perl: calling a constructor within a class
by dragonchild (Archbishop) on Sep 28, 2001 at 00:50 UTC | |
by TheDamian (Vicar) on Sep 28, 2001 at 11:06 UTC | |
by blakem (Monsignor) on Sep 28, 2001 at 11:20 UTC | |
by TheDamian (Vicar) on Sep 28, 2001 at 14:12 UTC | |
by davorg (Chancellor) on Sep 28, 2001 at 16:18 UTC | |
by runrig (Abbot) on Sep 28, 2001 at 01:02 UTC | |
by dragonchild (Archbishop) on Sep 28, 2001 at 01:13 UTC |