Algorithm-TSort
view release on metacpan or search on metacpan
lib/Algorithm/TSort.pm view on Meta::CPAN
my $node = shift;
return $$self->($node);
}
package Algorithm::TSort::ADJSUB_ARRAYREF;
sub adj_nodes {
my $array = $_[0]->( $_[1] );
return $array ? @$array : ();
}
package Algorithm::TSort::Guard;
sub new{
return bless $_[1], $_[0];
}
sub DESTROY { $_[0]->() };
}
sub Graph($$) {
my $what = shift;
my $data = shift;
die "Graph: undefined input" unless defined $what;
if ( $what eq 'IO' || $what eq 'SCALAR' ) {
my %c;
lib/Algorithm/TSort.pm view on Meta::CPAN
else {
$fh = $data;
}
local $/ = "\n";
while ( defined( $line = <$fh> ) ) {
chomp $line;
next unless $line =~ m/\S/;
my ( $node, @deps ) = split ' ', $line;
$c{$node} = \@deps;
}
return bless \%c, 'Algorithm::TSort::ADJ';
}
elsif ( $what eq 'ADJSUB' ) {
return bless \( my $s = $data ), 'Algorithm::TSort::ADJSUB';
}
elsif ( $what eq 'ADJSUB_ARRAYREF' ) {
return bless $data, 'Algorithm::TSort::ADJSUB_ARRAYREF';
}
elsif ( $what eq 'ADJ' ) {
my %c = %$data;
return bless \%c, 'Algorithm::TSort::ADJ';
}
else {
require Carp;
Carp::croak("Graph: don't know about \$what='$what'");
}
}
# Preloaded methods go here.
sub tsort($;@) {
( run in 0.311 second using v1.01-cache-2.11-cpan-de7293f3b23 )