1. make spot dups look back 5 mins.
[spider.git] / perl / Route / User.pm
1 #
2 # User routing routines
3 #
4 # Copyright (c) 2001 Dirk Koopman G1TLH
5 #
6 # $Id$
7
8
9 package Route::User;
10
11 use DXDebug;
12 use Route;
13
14 use strict;
15
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;
19 $main::build += $VERSION;
20 $main::branch += $BRANCH;
21
22 use vars qw(%list %valid @ISA $max $filterdef);
23 @ISA = qw(Route);
24
25 %valid = (
26                   parent => '0,Parent Calls,parray',
27 );
28
29 $filterdef = $Route::filterdef;
30 %list = ();
31 $max = 0;
32
33 sub count
34 {
35         my $n = scalar(keys %list);
36         $max = $n if $n > $max;
37         return $n;
38 }
39
40 sub max
41 {
42         count();
43         return $max;
44 }
45
46 sub new
47 {
48         my $pkg = shift;
49         my $call = uc shift;
50         my $ncall = uc shift;
51         my $flags = shift;
52         confess "already have $call in $pkg" if $list{$call};
53         
54         my $self = $pkg->SUPER::new($call);
55         $self->{parent} = [ $ncall ];
56         $self->{flags} = $flags;
57         $list{$call} = $self;
58
59         return $self;
60 }
61
62 sub del
63 {
64         my $self = shift;
65         my $pref = shift;
66         my @out = $self->delparent($pref);
67         return @out;
68 }
69
70 sub get
71 {
72         my $call = shift;
73         $call = shift if ref $call;
74         my $ref = $list{uc $call};
75         dbg("Failed to get User $call" ) if !$ref && isdbg('routerr');
76         return $ref;
77 }
78
79 sub addparent
80 {
81         my $self = shift;
82     return $self->_addlist('parent', @_);
83 }
84
85 sub delparent
86 {
87         my $self = shift;
88     return $self->_dellist('parent', @_);
89 }
90
91 #
92 # generic AUTOLOAD for accessors
93 #
94
95 sub AUTOLOAD
96 {
97         no strict;
98
99         my $self = shift;
100         $name = $AUTOLOAD;
101         return if $name =~ /::DESTROY$/;
102         $name =~ s/.*:://o;
103   
104         confess "Non-existant field '$AUTOLOAD'" unless $valid{$name} || $Route::valid{$name};
105
106         # this clever line of code creates a subroutine which takes over from autoload
107         # from OO Perl - Conway
108 #       *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}} ;
109     @_ ? $self->{$name} = shift : $self->{$name} ;
110 }
111
112 1;