X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=perl%2FRoute.pm;h=d4fb95d4205eae5143959c9c6efd130b0da1eb43;hb=99e970eab7e843c6810039bc85f462b270534a62;hp=afce3a042d850200af3b9478d8e6b88cd8527403;hpb=6230850db2f82835e5ef75da4f418615ba4261da;p=spider.git diff --git a/perl/Route.pm b/perl/Route.pm index afce3a04..d4fb95d4 100644 --- a/perl/Route.pm +++ b/perl/Route.pm @@ -285,6 +285,34 @@ sub get return Route::Node::get($call) || Route::User::get($call); } +sub findroutes +{ + my $call = shift; + my $level = shift || 0; + my $seen = shift || {}; + my @out; + + dbg("findroutes: $call level: $level calls: " . join(',', @_)) if isdbg('routec'); + + # recursion detector + return () if $seen->{$call}; + if (my $dxchan = DXChannel::get($call)) { + $seen->{$call}++; + push @out, $level ? [$level, $dxchan] : $dxchan; + return @out; + } + + # deal with more nodes + my $nref = Route::get($call); + foreach my $ncall (@{$nref->{parent}}) { + dbg("recursing from $call -> $ncall") if isdbg('routec'); + my @rout = findroutes($ncall, $level+1, $seen); + push @out, @rout; + } + + return $level == 0 ? map {$_->[1]} sort {$a->[0] <=> $b->[0]} @out : @out; +} + # find all the possible dxchannels which this object might be on sub alldxchan {