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