change build number calculation to be more accurate
[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         return $max;
43 }
44
45 sub new
46 {
47         my $pkg = shift;
48         my $call = uc shift;
49         my $ncall = uc shift;
50         my $flags = shift;
51         confess "already have $call in $pkg" if $list{$call};
52         
53         my $self = $pkg->SUPER::new($call);
54         $self->{parent} = [ $ncall ];
55         $self->{flags} = $flags;
56         $list{$call} = $self;
57
58         return $self;
59 }
60
61 sub del
62 {
63         my $self = shift;
64         my $pref = shift;
65         my $ref = $self->delparent($pref->{call});
66         return () if @$ref;
67         my @out = delete $list{$self->{call}};
68         return @out;
69 }
70
71 sub get
72 {
73         my $call = shift;
74         $call = shift if ref $call;
75         my $ref = $list{uc $call};
76         dbg("Failed to get User $call" ) if !$ref && isdbg('routerr');
77         return $ref;
78 }
79
80 sub addparent
81 {
82         my $self = shift;
83     return $self->_addlist('parent', @_);
84 }
85
86 sub delparent
87 {
88         my $self = shift;
89     return $self->_dellist('parent', @_);
90 }
91
92 #
93 # generic AUTOLOAD for accessors
94 #
95
96 sub AUTOLOAD
97 {
98         no strict;
99
100         my $self = shift;
101         $name = $AUTOLOAD;
102         return if $name =~ /::DESTROY$/;
103         $name =~ s/.*:://o;
104   
105         confess "Non-existant field '$AUTOLOAD'" unless $valid{$name} || $Route::valid{$name};
106
107         # this clever line of code creates a subroutine which takes over from autoload
108         # from OO Perl - Conway
109 #       *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}} ;
110     @_ ? $self->{$name} = shift : $self->{$name} ;
111 }
112
113 1;