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