2 # User routing routines
4 # Copyright (c) 2001 Dirk Koopman G1TLH
16 use vars qw($VERSION $BRANCH);
17 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
18 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
19 $main::build += $VERSION;
20 $main::branch += $BRANCH;
22 use vars qw(%list %valid @ISA $max $filterdef);
26 dxchan => '0,Dxchan Calls,parray',
29 $filterdef = $Route::filterdef;
35 my $n = scalar(keys %list);
36 $max = $n if $n > $max;
51 my $flags = shift || Route::here(1);
52 confess "already have $call in $pkg" if $list{$call};
54 my $self = $pkg->SUPER::new($call);
56 $self->{flags} = $flags;
58 dbg("creating Route::User $self->{call}") if isdbg('routelow');
66 dbg("deleting Route::User $self->{call}") if isdbg('routelow');
67 delete $list{$self->{call}};
78 $call = shift if ref $call;
79 my $ref = $list{uc $call};
80 dbg("Failed to get User $call" ) if !$ref && isdbg('routerr');
84 # add a user to this node
85 # returns Route::User if it is a new user;
88 my ($self, $nref) = @_;
89 my $r = $self->is_empty('nodes');
90 $self->_addlist('nodes', $nref);
91 $nref->_addlist('users', $self);
92 $nref->{usercount} = scalar @{$nref->{users}};
93 return $r ? ($self) : ();
96 # delete a user from this node
99 my ($self, $nref) = @_;
101 $self->_dellist('nodes', $nref);
102 $nref->_dellist('users', $self);
103 $nref->{usercount} = scalar @{$nref->{users}};
104 return $self->is_empty('nodes') ? ($self) : ();
110 return @{$self->{nodes}};
114 # generic AUTOLOAD for accessors
120 my ($pkg,$name) = $AUTOLOAD =~ /^(.*)::(\w+)$/;
121 return if $name eq 'DESTROY';
123 confess "Non-existant field '$AUTOLOAD'" unless $valid{$name} || $Route::valid{$name};
125 # this clever line of code creates a subroutine which takes over from autoload
126 # from OO Perl - Conway
127 *$AUTOLOAD = sub {$_[0]->{$name} = $_[1] if @_ > 1; return $_[0]->{$name}};
129 # *{"${pkg}::$name"} = sub {$_[0]->{$name} = $_[1] if @_ > 1; return $_[0]->{$name}};
130 # goto &{"${pkg}::$name"};