line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Map::Tube::Graph; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
3
|
|
|
3
|
|
30320
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
118
|
|
5
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
98
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# Modules. |
8
|
3
|
|
|
3
|
|
1729
|
use Class::Utils qw(set_params); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Error::Pure qw(err); |
10
|
|
|
|
|
|
|
use Graph; |
11
|
|
|
|
|
|
|
use List::MoreUtils qw(none); |
12
|
|
|
|
|
|
|
use Scalar::Util qw(blessed); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Version. |
15
|
|
|
|
|
|
|
our $VERSION = 0.03; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Constructor. |
18
|
|
|
|
|
|
|
sub new { |
19
|
|
|
|
|
|
|
my ($class, @params) = @_; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Create object. |
22
|
|
|
|
|
|
|
my $self = bless {}, $class; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Edge callback. |
25
|
|
|
|
|
|
|
$self->{'callback_edge'} = sub { |
26
|
|
|
|
|
|
|
my ($self, $node, $link) = @_; |
27
|
|
|
|
|
|
|
$self->{'graph'}->add_edge($node->id, $link); |
28
|
|
|
|
|
|
|
return; |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Vertex callback. |
32
|
|
|
|
|
|
|
$self->{'callback_vertex'} = sub { |
33
|
|
|
|
|
|
|
my ($self, $node) = @_; |
34
|
|
|
|
|
|
|
$self->{'graph'}->add_vertex($node->id); |
35
|
|
|
|
|
|
|
return; |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Graph object. |
39
|
|
|
|
|
|
|
$self->{'graph'} = undef; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Map::Tube object. |
42
|
|
|
|
|
|
|
$self->{'tube'} = undef; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Process params. |
45
|
|
|
|
|
|
|
set_params($self, @params); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Check Map::Tube object. |
48
|
|
|
|
|
|
|
if (! defined $self->{'tube'}) { |
49
|
|
|
|
|
|
|
err "Parameter 'tube' is required."; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
if (! blessed($self->{'tube'}) |
52
|
|
|
|
|
|
|
|| ! $self->{'tube'}->DOES('Map::Tube')) { |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
err "Parameter 'tube' must be 'Map::Tube' object."; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Graph object. |
58
|
|
|
|
|
|
|
if (! defined $self->{'graph'}) { |
59
|
|
|
|
|
|
|
$self->{'graph'} = Graph->new; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Object. |
63
|
|
|
|
|
|
|
return $self; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Get graph. |
67
|
|
|
|
|
|
|
sub graph { |
68
|
|
|
|
|
|
|
my $self = shift; |
69
|
|
|
|
|
|
|
foreach my $node (values %{$self->{'tube'}->nodes}) { |
70
|
|
|
|
|
|
|
$self->{'callback_vertex'}->($self, $node); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
my @processed; |
73
|
|
|
|
|
|
|
foreach my $node (values %{$self->{'tube'}->nodes}) { |
74
|
|
|
|
|
|
|
foreach my $link (split m/,/ms, $node->link) { |
75
|
|
|
|
|
|
|
if (none { |
76
|
|
|
|
|
|
|
($_->[0] eq $node->id && $_->[1] eq $link) |
77
|
|
|
|
|
|
|
|| |
78
|
|
|
|
|
|
|
($_->[0] eq $link && $_->[1] eq $node->id) |
79
|
|
|
|
|
|
|
} @processed) { |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$self->{'callback_edge'}->($self, $node, $link); |
82
|
|
|
|
|
|
|
push @processed, [$node->id, $link]; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
return $self->{'graph'}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
__END__ |