X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FRoute%2FNode.pm;h=a3cded54f095b08e565236b7f19f7bf5427d3aa5;hb=942cdc8c6434db4e2cf77b43ec26c0059768f853;hp=ff3351b3d6aaac0ea698b3e3ca3f12ec0dac7e65;hpb=148f4d43135748ba5aff985c50720b370ca1e336;p=spider.git diff --git a/perl/Route/Node.pm b/perl/Route/Node.pm index ff3351b3..a3cded54 100644 --- a/perl/Route/Node.pm +++ b/perl/Route/Node.pm @@ -16,7 +16,7 @@ use strict; use vars qw($VERSION $BRANCH); $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ ); -$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ ) || 0; +$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0)); $main::build += $VERSION; $main::branch += $BRANCH; @@ -74,6 +74,7 @@ sub add return undef; } $self = $parent->new($call, @_); + $self->register; $parent->_addnode($self); return $self; } @@ -145,6 +146,7 @@ sub add_user @out = $uref->addparent($self); } else { $uref = Route::User->new($ucall, $self->{call}, @_); + $uref->register; @out = $uref; } $self->_adduser($uref); @@ -215,9 +217,6 @@ sub new { my $pkg = shift; my $call = uc shift; - - confess "already have $call in $pkg" if $list{$call}; - my $self = $pkg->SUPER::new($call); $self->{parent} = ref $pkg ? [ $pkg->{call} ] : [ ]; $self->{version} = shift; @@ -226,11 +225,16 @@ sub new $self->{nodes} = []; $self->{lid} = 0; - $list{$call} = $self; - return $self; } +sub register +{ + my $self = shift; + confess "already have $call in $pkg" if $list{$self->{call}}; + $list{$call} = $self; +} + sub get { my $call = shift; @@ -323,11 +327,8 @@ sub AUTOLOAD confess "Non-existant field '$AUTOLOAD'" unless $valid{$name} || $Route::valid{$name}; - # this clever line of code creates a subroutine which takes over from autoload - # from OO Perl - Conway -# print "AUTOLOAD: $AUTOLOAD\n"; -# *{$AUTOLOAD} = sub {my $self = shift; @_ ? $self->{$name} = shift : $self->{$name}} ; - @_ ? $self->{$name} = shift : $self->{$name} ; + *$AUTOLOAD = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}}; + &$AUTOLOAD($self, @_); } 1;