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 List,parray',
27 nodes => '0,On Node(s),parray',
30 $filterdef = $Route::filterdef;
36 my $n = scalar(keys %list);
37 $max = $n if $n > $max;
52 my $flags = shift || Route::here(1);
53 confess "already have $call in $pkg" if $list{$call};
55 my $self = $pkg->SUPER::new($call);
57 $self->{flags} = $flags;
59 dbg("creating Route::User $self->{call}") if isdbg('routelow');
67 dbg("deleting Route::User $self->{call}") if isdbg('routelow');
68 delete $list{$self->{call}};
79 $call = shift if ref $call;
80 my $ref = $list{uc $call};
81 dbg("Failed to get User $call" ) if !$ref && isdbg('routerr');
85 # add a user to this node
86 # returns Route::User if it is a new user;
89 my ($self, $nref) = @_;
90 my $r = $self->is_empty('nodes');
91 $self->_addlist('nodes', $nref);
92 $nref->_addlist('users', $self);
93 $nref->{usercount} = scalar @{$nref->{users}};
94 return $r ? ($self) : ();
97 # delete a user from this node
100 my ($self, $nref) = @_;
102 $self->_dellist('nodes', $nref);
103 $nref->_dellist('users', $self);
104 $nref->{usercount} = scalar @{$nref->{users}};
105 return $self->is_empty('nodes') ? ($self) : ();
111 return @{$self->{nodes}};
115 # generic AUTOLOAD for accessors
121 my ($pkg,$name) = $AUTOLOAD =~ /^(.*)::(\w+)$/;
122 return if $name eq 'DESTROY';
124 confess "Non-existant field '$AUTOLOAD'" unless $valid{$name} || $Route::valid{$name};
126 # this clever line of code creates a subroutine which takes over from autoload
127 # from OO Perl - Conway
128 *$AUTOLOAD = sub {$_[0]->{$name} = $_[1] if @_ > 1; return $_[0]->{$name}};
130 # *{"${pkg}::$name"} = sub {$_[0]->{$name} = $_[1] if @_ > 1; return $_[0]->{$name}};
131 # goto &{"${pkg}::$name"};