line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Graph::Reader::UnicodeTree; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
4
|
|
|
4
|
|
72786
|
use base qw(Graph::Reader); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
3172
|
|
5
|
4
|
|
|
4
|
|
541262
|
use strict; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
100
|
|
6
|
4
|
|
|
4
|
|
20
|
use warnings; |
|
4
|
|
|
|
|
17
|
|
|
4
|
|
|
|
|
153
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Modules. |
9
|
4
|
|
|
4
|
|
2621
|
use Encode qw(decode_utf8); |
|
4
|
|
|
|
|
29576
|
|
|
4
|
|
|
|
|
271
|
|
10
|
4
|
|
|
4
|
|
2512
|
use Readonly; |
|
4
|
|
|
|
|
8818
|
|
|
4
|
|
|
|
|
1763
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Constants. |
13
|
|
|
|
|
|
|
Readonly::Scalar our $GR_LINE => decode_utf8(q{───}); |
14
|
|
|
|
|
|
|
Readonly::Scalar our $GR_TREE => decode_utf8(q{─┬─}); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Version. |
17
|
|
|
|
|
|
|
our $VERSION = 0.02; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Read graph subroutine. |
20
|
|
|
|
|
|
|
sub _read_graph { |
21
|
5
|
|
|
5
|
|
6720
|
my ($self, $graph, $fh) = @_; |
22
|
5
|
|
|
|
|
12
|
my @indent = ([0, undef]); |
23
|
5
|
|
|
|
|
102
|
while (my $line = decode_utf8(<$fh>)) { |
24
|
17
|
|
|
|
|
287
|
chomp $line; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Remove indent. |
27
|
17
|
|
|
|
|
56
|
my $parseable_line = substr $line, $indent[-1]->[0]; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Split to vertexes. |
30
|
17
|
|
|
|
|
21
|
my @new_indent; |
31
|
|
|
|
|
|
|
my @vertexes; |
32
|
17
|
|
|
|
|
21
|
my $new_indent = $indent[-1]->[0]; |
33
|
17
|
|
|
|
|
18
|
my $last_indent; |
34
|
17
|
|
|
|
|
74
|
foreach my $new_block (split m/$GR_TREE/ms, $parseable_line) { |
35
|
23
|
100
|
|
|
|
45
|
if (defined $last_indent) { |
36
|
6
|
|
|
|
|
8
|
push @new_indent, $last_indent; |
37
|
6
|
|
|
|
|
9
|
$last_indent = undef; |
38
|
|
|
|
|
|
|
} |
39
|
23
|
|
|
|
|
29
|
my $last_vertex; |
40
|
23
|
|
|
|
|
61
|
foreach my $new_vertex (split m/$GR_LINE/ms, $new_block) { |
41
|
44
|
|
|
|
|
59
|
push @vertexes, $new_vertex; |
42
|
44
|
|
|
|
|
63
|
$last_vertex = $new_vertex; |
43
|
|
|
|
|
|
|
} |
44
|
23
|
|
|
|
|
54
|
$new_indent += (length $new_block) + 3; |
45
|
23
|
|
|
|
|
52
|
$last_indent = [$new_indent, $last_vertex]; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Add vertexes and edges. |
49
|
17
|
|
|
|
|
28
|
my $first_v; |
50
|
17
|
100
|
|
|
|
34
|
if (defined $indent[-1]->[1]) { |
51
|
12
|
|
|
|
|
20
|
$first_v = $indent[-1]->[1]; |
52
|
|
|
|
|
|
|
} else { |
53
|
5
|
|
|
|
|
7
|
$first_v = shift @vertexes; |
54
|
|
|
|
|
|
|
} |
55
|
17
|
|
|
|
|
45
|
$graph->add_vertex($first_v); |
56
|
17
|
|
|
|
|
450
|
foreach my $second_v (@vertexes) { |
57
|
39
|
|
|
|
|
85
|
$graph->add_vertex($second_v); |
58
|
39
|
|
|
|
|
993
|
$graph->add_edge($first_v, $second_v); |
59
|
39
|
|
|
|
|
1495
|
$first_v = $second_v; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Update indent. |
63
|
17
|
|
|
|
|
30
|
my $end_pos = $indent[-1]->[0] - 2; |
64
|
17
|
100
|
|
|
|
37
|
if ($end_pos > 0) { |
65
|
12
|
|
|
|
|
24
|
my $end_char = substr $line, $end_pos, 1; |
66
|
12
|
100
|
|
|
|
26
|
if ($end_char eq decode_utf8('└')) { |
67
|
6
|
|
|
|
|
84
|
pop @indent; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
17
|
100
|
|
|
|
179
|
if (@new_indent) { |
71
|
5
|
|
|
|
|
29
|
push @indent, @new_indent; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
5
|
|
|
|
|
34
|
return; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |