line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Graph::Reader::UnicodeTree; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
127809
|
use base qw(Graph::Reader); |
|
4
|
|
|
|
|
29
|
|
|
4
|
|
|
|
|
2321
|
|
4
|
4
|
|
|
4
|
|
189928
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
94
|
|
5
|
4
|
|
|
4
|
|
25
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
147
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
2344
|
use Encode qw(decode_utf8); |
|
4
|
|
|
|
|
32623
|
|
|
4
|
|
|
|
|
298
|
|
8
|
4
|
|
|
4
|
|
1813
|
use Readonly; |
|
4
|
|
|
|
|
12253
|
|
|
4
|
|
|
|
|
1809
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Constants. |
11
|
|
|
|
|
|
|
Readonly::Scalar our $GR_LINE => decode_utf8(q{───}); |
12
|
|
|
|
|
|
|
Readonly::Scalar our $GR_TREE => decode_utf8(q{─┬─}); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = 0.03; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Read graph subroutine. |
17
|
|
|
|
|
|
|
sub _read_graph { |
18
|
5
|
|
|
5
|
|
10075
|
my ($self, $graph, $fh) = @_; |
19
|
5
|
|
|
|
|
19
|
my @indent = ([0, undef]); |
20
|
5
|
|
|
|
|
113
|
while (my $line = decode_utf8(<$fh>)) { |
21
|
17
|
|
|
|
|
351
|
chomp $line; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Remove indent. |
24
|
17
|
|
|
|
|
61
|
my $parseable_line = substr $line, $indent[-1]->[0]; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Split to vertexes. |
27
|
17
|
|
|
|
|
28
|
my @new_indent; |
28
|
|
|
|
|
|
|
my @vertexes; |
29
|
17
|
|
|
|
|
27
|
my $new_indent = $indent[-1]->[0]; |
30
|
17
|
|
|
|
|
26
|
my $last_indent; |
31
|
17
|
|
|
|
|
79
|
foreach my $new_block (split m/$GR_TREE/ms, $parseable_line) { |
32
|
23
|
100
|
|
|
|
52
|
if (defined $last_indent) { |
33
|
6
|
|
|
|
|
7
|
push @new_indent, $last_indent; |
34
|
6
|
|
|
|
|
11
|
$last_indent = undef; |
35
|
|
|
|
|
|
|
} |
36
|
23
|
|
|
|
|
29
|
my $last_vertex; |
37
|
23
|
|
|
|
|
61
|
foreach my $new_vertex (split m/$GR_LINE/ms, $new_block) { |
38
|
44
|
|
|
|
|
78
|
push @vertexes, $new_vertex; |
39
|
44
|
|
|
|
|
74
|
$last_vertex = $new_vertex; |
40
|
|
|
|
|
|
|
} |
41
|
23
|
|
|
|
|
51
|
$new_indent += (length $new_block) + 3; |
42
|
23
|
|
|
|
|
52
|
$last_indent = [$new_indent, $last_vertex]; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Add vertexes and edges. |
46
|
17
|
|
|
|
|
30
|
my $first_v; |
47
|
17
|
100
|
|
|
|
41
|
if (defined $indent[-1]->[1]) { |
48
|
12
|
|
|
|
|
19
|
$first_v = $indent[-1]->[1]; |
49
|
|
|
|
|
|
|
} else { |
50
|
5
|
|
|
|
|
37
|
$first_v = shift @vertexes; |
51
|
|
|
|
|
|
|
} |
52
|
17
|
|
|
|
|
54
|
$graph->add_vertex($first_v); |
53
|
17
|
|
|
|
|
621
|
foreach my $second_v (@vertexes) { |
54
|
39
|
|
|
|
|
96
|
$graph->add_vertex($second_v); |
55
|
39
|
|
|
|
|
1909
|
$graph->add_edge($first_v, $second_v); |
56
|
39
|
|
|
|
|
2097
|
$first_v = $second_v; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Update indent. |
60
|
17
|
|
|
|
|
31
|
my $end_pos = $indent[-1]->[0] - 2; |
61
|
17
|
100
|
|
|
|
38
|
if ($end_pos > 0) { |
62
|
12
|
|
|
|
|
33
|
my $end_char = substr $line, $end_pos, 1; |
63
|
12
|
100
|
|
|
|
30
|
if ($end_char eq decode_utf8('└')) { |
64
|
6
|
|
|
|
|
109
|
pop @indent; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
17
|
100
|
|
|
|
225
|
if (@new_indent) { |
68
|
5
|
|
|
|
|
32
|
push @indent, @new_indent; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
5
|
|
|
|
|
52
|
return; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |