2 # User routing routines
4 # Copyright (c) 2001 Dirk Koopman G1TLH
15 use Time::HiRes qw(gettimeofday);
19 use vars qw(%list %valid @ISA $max $filterdef);
22 $filterdef = $Route::filterdef;
26 our $cachefn = localdata('route_user_cache');
30 my $n = scalar(keys %list);
31 $max = $n if $n > $max;
49 confess "already have $call in $pkg" if $list{$call};
51 my $self = $pkg->SUPER::new($call);
52 $self->{parent} = [ $ncall ];
53 $self->{flags} = $flags || Route::here(1);
54 $self->{ip} = $ip if defined $ip;
56 dbg("CLUSTER: user $call added") if isdbg('cluster');
70 my $call = $self->{call};
71 $self->delparent($pref);
72 unless (@{$self->{parent}}) {
74 dbg("CLUSTER: user $call deleted") if isdbg('cluster');
83 $call = shift if ref $call;
84 my $ref = $list{uc $call};
85 dbg("Failed to get User $call" ) if !$ref && isdbg('routerr');
92 return $self->_addlist('parent', @_);
98 return $self->_dellist('parent', @_);
101 sub TO_JSON { return { %{ shift() } }; }
105 my $json = DXJSON->new;
106 $json->canonical(isdbg('routecache'));
108 my $ta = [ gettimeofday ];
111 while (my ($k, $v) = each %list) {
112 push @s, "$k:" . $json->encode($v) . "\n";
116 my $fh = IO::File->new(">$cachefn") or confess("writing $cachefn $!");
117 if (isdbg("routecache")) {
125 dbg("Route::User:Write_cache error '$@'");
128 my $diff = _diffms($ta);
129 dbg("Route::User:WRITE_CACHE time to write: $diff mS");
133 # generic AUTOLOAD for accessors
139 my ($pkg,$name) = $AUTOLOAD =~ /^(.*)::(\w+)$/;
140 return if $name eq 'DESTROY';
142 confess "Non-existant field '$AUTOLOAD'" unless $valid{$name} || $Route::valid{$name};
144 # this clever line of code creates a subroutine which takes over from autoload
145 # from OO Perl - Conway
146 *$AUTOLOAD = sub {$_[0]->{$name} = $_[1] if @_ > 1; return $_[0]->{$name}};
148 # *{"${pkg}::$name"} = sub {$_[0]->{$name} = $_[1] if @_ > 1; return $_[0]->{$name}};
149 # goto &{"${pkg}::$name"};