in reply to Multiple Prototypes for Object Constructor
The point is that the subroutine can deal with the arguments itself, including the number of arguments, in any way it sees fit. If you want specifically to disallow the Edge->new("from_node"); case (not unreasonable), then you could do something like# reworked slightly, for conciseness. sub new { my %self; ( my $class, $self{qw( from_node to_node label )} ) = @_; bless \%self, $class; }
or evensub new { @_ == 2 and die "Error: can't set just one of the links!"; my %self; ( my $class, $self{qw( from_node to_node label )} ) = @_; bless \%self, $class; }
sub new { my %self; ( my $class, $self{qw( from_node to_node label )} ) = @_; $self{'from_node'} && ! $self{'to_node'} and die "Error: can't set just one of the links!"; bless \%self, $class; }
jdporter
The 6th Rule of Perl Club is -- There is no Rule #6.
|
|---|