line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Graph::Reader::TGF; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
4
|
|
|
4
|
|
75916
|
use base qw(Graph::Reader); |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
3019
|
|
5
|
4
|
|
|
4
|
|
568591
|
use strict; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
106
|
|
6
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
150
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Modules. |
9
|
4
|
|
|
4
|
|
2868
|
use Encode qw(decode_utf8); |
|
4
|
|
|
|
|
31973
|
|
|
4
|
|
|
|
|
301
|
|
10
|
4
|
|
|
4
|
|
1320284
|
use Error::Pure qw(err); |
|
4
|
|
|
|
|
39657
|
|
|
4
|
|
|
|
|
593
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Version. |
13
|
|
|
|
|
|
|
our $VERSION = 0.03; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Edge callback. |
16
|
|
|
|
|
|
|
sub _edge_callback { |
17
|
5
|
|
|
5
|
|
9
|
my ($self, $graph, $id1, $id2, $edge_label) = @_; |
18
|
5
|
|
|
|
|
26
|
$graph->set_edge_attribute($id1, $id2, 'label', $edge_label); |
19
|
5
|
|
|
|
|
3070
|
return; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Init. |
23
|
|
|
|
|
|
|
sub _init { |
24
|
7
|
|
|
7
|
|
13834
|
my ($self, $param_hr) = @_; |
25
|
7
|
|
|
|
|
32
|
$self->SUPER::_init(); |
26
|
7
|
100
|
100
|
|
|
61
|
if (exists $param_hr->{'edge_callback'} |
|
|
|
100
|
|
|
|
|
27
|
|
|
|
|
|
|
&& defined $param_hr->{'edge_callback'} |
28
|
|
|
|
|
|
|
&& ref $param_hr->{'edge_callback'} ne 'CODE') { |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
5
|
err "Parameter 'edge_callback' isn't reference to code."; |
31
|
|
|
|
|
|
|
} |
32
|
6
|
|
|
|
|
26
|
$self->{'edge_callback'} = $param_hr->{'edge_callback'}; |
33
|
6
|
100
|
100
|
|
|
44
|
if (exists $param_hr->{'vertex_callback'} |
|
|
|
100
|
|
|
|
|
34
|
|
|
|
|
|
|
&& defined $param_hr->{'vertex_callback'} |
35
|
|
|
|
|
|
|
&& ref $param_hr->{'vertex_callback'} ne 'CODE') { |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
7
|
err "Parameter 'vertex_callback' isn't reference to code."; |
38
|
|
|
|
|
|
|
} |
39
|
5
|
|
|
|
|
12
|
$self->{'vertex_callback'} = $param_hr->{'vertex_callback'}; |
40
|
5
|
|
|
|
|
12
|
return; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Read graph subroutine. |
44
|
|
|
|
|
|
|
sub _read_graph { |
45
|
6
|
|
|
6
|
|
6016
|
my ($self, $graph, $fh) = @_; |
46
|
6
|
|
|
|
|
10
|
my $vertexes = 1; |
47
|
6
|
|
|
|
|
115
|
while (my $line = decode_utf8(<$fh>)) { |
48
|
24
|
|
|
|
|
664
|
chomp $line; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# End of vertexes section. |
51
|
24
|
100
|
|
|
|
72
|
if ($line =~ m/^#/ms) { |
52
|
6
|
|
|
|
|
11
|
$vertexes = 0; |
53
|
6
|
|
|
|
|
25
|
next; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Vertexes. |
57
|
18
|
100
|
|
|
|
35
|
if ($vertexes) { |
58
|
12
|
|
|
|
|
43
|
my ($id, $vertex_label) = split m/\s+/ms, $line, 2; |
59
|
12
|
100
|
|
|
|
28
|
if (! defined $vertex_label) { |
60
|
6
|
|
|
|
|
13
|
$vertex_label = $id; |
61
|
|
|
|
|
|
|
} |
62
|
12
|
|
|
|
|
32
|
$graph->add_vertex($id); |
63
|
12
|
100
|
|
|
|
586
|
if ($self->{'vertex_callback'}) { |
64
|
2
|
|
|
|
|
7
|
$self->{'vertex_callback'}->($self, $graph, |
65
|
|
|
|
|
|
|
$id, $vertex_label); |
66
|
|
|
|
|
|
|
} else { |
67
|
10
|
|
|
|
|
23
|
$self->_vertex_callback($graph, $id, |
68
|
|
|
|
|
|
|
$vertex_label); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Edges. |
72
|
|
|
|
|
|
|
} else { |
73
|
6
|
|
|
|
|
26
|
my ($id1, $id2, $edge_label) = split m/\s+/ms, $line, 3; |
74
|
6
|
|
|
|
|
22
|
$graph->add_edge($id1, $id2); |
75
|
6
|
100
|
|
|
|
939
|
if ($self->{'edge_callback'}) { |
76
|
1
|
|
|
|
|
6
|
$self->{'edge_callback'}->($self, $graph, $id1, |
77
|
|
|
|
|
|
|
$id2, $edge_label); |
78
|
|
|
|
|
|
|
} else { |
79
|
5
|
|
|
|
|
16
|
$self->_edge_callback($graph, $id1, $id2, |
80
|
|
|
|
|
|
|
$edge_label); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} |
85
|
6
|
|
|
|
|
643
|
return; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Vertex callback. |
89
|
|
|
|
|
|
|
sub _vertex_callback { |
90
|
10
|
|
|
10
|
|
15
|
my ($self, $graph, $id, $vertex_label) = @_; |
91
|
10
|
|
|
|
|
30
|
$graph->set_vertex_attribute($id, 'label', $vertex_label); |
92
|
10
|
|
|
|
|
1095
|
return; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |