blob: cfdfa470c2329d25ce098a02829db983c35d25ff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
package Fripost::Tests;
use 5.010_000;
use strict;
use warnings;
use utf8;
=head1 NAME
Tests.pm
=cut
our @EXPORT = qw/build_alias_graph search_path/;
our @ISA = qw(Exporter);
use FindBin qw($Bin);
use lib "$Bin/lib";
use Fripost::Schema;
sub build_alias_graph {
my $graph;
foreach (@_) {
my $to = $_->{goto};
foreach my $from (@{$_->{address}}) {
push @{$graph->{$from}}, $to;
}
}
return $graph;
}
sub search_path {
my ($graph, $from, $to) = @_;
my @stack;
push @stack, [$from];
while (@stack) {
my $path = pop @stack;
my $last = @{$path}[$#$path];
return @$path if $last eq $to;
foreach (@{$graph->{$last}}) {
push @stack, [@$path,$_];
}
}
}
=head1 AUTHOR
Stefan Kangas C<< <skangas at skangas.se> >>
Guilhem Moulin C<< <guilhem at fripost.org> >>
=head1 COPYRIGHT
Copyright 2010,2011 Stefan Kangas.
Copyright 2012 Guilhem Moulin.
=head1 LICENSE
This program is free software; you can redistribute it and/or modify it
under the same terms as perl itself.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
=cut
1; # End of Tests.pm
__END__
|