*** empty log message ***
[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,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         
53         my $self = $pkg->SUPER::new($call);
54         $self->{parent} = [ $ncall ];
55         $self->{flags} = $flags;
56
57         return $self;
58 }
59
60 sub register
61 {
62         my $self = shift;
63         
64         confess "already have $call in $pkg" if $list{$self->{call}};
65         
66         $list{$call} = $self;
67 }
68
69 sub get_all
70 {
71         return values %list;
72 }
73
74 sub del
75 {
76         my $self = shift;
77         my $pref = shift;
78         $self->delparent($pref);
79         unless (@{$self->{parent}}) {
80                 delete $list{$self->{call}};
81                 return $self;
82         }
83         return undef;
84 }
85
86 sub get
87 {
88         my $call = shift;
89         $call = shift if ref $call;
90         my $ref = $list{uc $call};
91         dbg("Failed to get User $call" ) if !$ref && isdbg('routerr');
92         return $ref;
93 }
94
95 sub addparent
96 {
97         my $self = shift;
98     return $self->_addlist('parent', @_);
99 }
100
101 sub delparent
102 {
103         my $self = shift;
104     return $self->_dellist('parent', @_);
105 }
106
107 #
108 # generic AUTOLOAD for accessors
109 #
110
111 sub AUTOLOAD
112 {
113         no strict;
114
115         my $self = shift;
116         $name = $AUTOLOAD;
117         return if $name =~ /::DESTROY$/;
118         $name =~ s/.*:://o;
119   
120         confess "Non-existant field '$AUTOLOAD'" unless $valid{$name} || $Route::valid{$name};
121
122         *$AUTOLOAD = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}};
123         &$AUTOLOAD($self, @_);
124 }
125
126 1;