3 # This module impliments the abstracted routing for all protocols and
4 # is probably what I SHOULD have done the first time.
8 # This is just a container class which I expect to subclass
10 # Copyright (c) 2001 Dirk Koopman G1TLH
21 use vars qw(%list %valid);
25 flags => "0,Flags,phex",
30 my ($pkg, $call) = @_;
32 dbg('routelow', "create " . (ref($pkg) || $pkg) ." with $call");
34 return bless {call => $call}, (ref $pkg || $pkg);
38 # get a callsign from a passed reference or a string
45 $thingy = $self unless $thingy;
46 $thingy = $thingy->call if ref $thingy;
47 $thingy = uc $thingy if $thingy;
52 # add and delete a callsign to/from a list
60 my $call = _getcall($c);
61 unless (grep {$_ eq $call} @{$self->{$field}}) {
62 push @{$self->{$field}}, $call;
63 dbg('routelow', ref($self) . " adding $call to " . $self->{call} . "->\{$field\}");
66 return $self->{$field};
74 my $call = _getcall($c);
75 if (grep {$_ eq $call} @{$self->{$field}}) {
76 $self->{$field} = [ grep {$_ ne $call} @{$self->{$field}} ];
77 dbg('routelow', ref($self) . " deleting $call from " . $self->{call} . "->\{$field\}");
80 return $self->{$field};
84 # flag field constructors/enquirers
91 return $self ? 2 : 0 unless ref $self;
92 return $self->{flags} & 2 unless $r;
93 $self->{flags} = (($self->{flags} & ~2) | ($r ? 2 : 0));
101 return $self ? 1 : 0 unless ref $self;
102 return $self->{flags} & 1 unless $r;
103 $self->{flags} = (($self->{flags} & ~1) | ($r ? 1 : 0));
114 my $call = sprintf "%s", $self->{call};
115 return $self->here ? "$call" : "($call)";
121 my $nodes_only = shift;
125 my $call = $self->user_call;
127 $line = ' ' x ($level*2) . "$call";
128 $call = ' ' x length $call;
129 unless ($nodes_only) {
130 if (@{$self->{users}}) {
132 foreach my $ucall (sort @{$self->{users}}) {
133 my $uref = Route::User::get($ucall);
136 $c = $uref->user_call;
140 if ((length $line) + (length $c) + 1 < 79) {
145 $line = ' ' x ($level*2) . "$call->";
152 push @out, $line if length $line;
154 foreach my $ncall (sort @{$self->{nodes}}) {
155 my $nref = Route::Node::get($ncall);
156 next if @_ && !grep $ncall =~ m|$_|, @_;
159 my $c = $nref->user_call;
160 push @out, $nref->config($nodes_only, $level+1, @_);
162 push @out, ' ' x (($level+1)*2) . "$ncall?";
183 dbg('routelow', "$pkg $self->{call} destroyed");
188 # return a list of valid elements
194 $pkg = ref $pkg if ref $pkg;
195 my $val = "${pkg}::valid";
196 my @out = keys %$val;
197 push @out, keys %valid;
202 # return a prompt for a field
207 my ($self, $ele) = @_;
209 my $val = "${pkg}::valid";
210 return $val->{$ele} || $valid{$ele};
214 # generic AUTOLOAD for accessors
219 my $name = $AUTOLOAD;
220 return if $name =~ /::DESTROY$/;
223 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
225 # this clever line of code creates a subroutine which takes over from autoload
226 # from OO Perl - Conway
227 # *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}} ;
228 @_ ? $self->{$name} = shift : $self->{$name} ;