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;
130 $printit = grep $call =~ m|$_|, @_;
134 $line = ' ' x ($level*2) . "$call";
135 $call = ' ' x length $call;
136 unless ($nodes_only) {
137 if (@{$self->{users}}) {
139 foreach my $ucall (sort @{$self->{users}}) {
140 my $uref = Route::User::get($ucall);
143 $c = $uref->user_call;
147 if ((length $line) + (length $c) + 1 < 79) {
152 $line = ' ' x ($level*2) . "$call->";
159 push @out, $line if length $line;
162 foreach my $ncall (sort @{$self->{nodes}}) {
163 my $nref = Route::Node::get($ncall);
166 my $c = $nref->user_call;
167 push @out, $nref->config($nodes_only, $level+1, @_);
169 push @out, ' ' x (($level+1)*2) . "$ncall?" if @_ == 0 || (@_ && grep $ncall =~ m|$_|, @_);
190 dbg('routelow', "$pkg $self->{call} destroyed");
195 # return a list of valid elements
201 $pkg = ref $pkg if ref $pkg;
202 my $val = "${pkg}::valid";
203 my @out = keys %$val;
204 push @out, keys %valid;
209 # return a prompt for a field
214 my ($self, $ele) = @_;
216 my $val = "${pkg}::valid";
217 return $val->{$ele} || $valid{$ele};
221 # generic AUTOLOAD for accessors
226 my $name = $AUTOLOAD;
227 return if $name =~ /::DESTROY$/;
230 confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
232 # this clever line of code creates a subroutine which takes over from autoload
233 # from OO Perl - Conway
234 # *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}} ;
235 @_ ? $self->{$name} = shift : $self->{$name} ;