line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Graph::Reader::UnicodeTree; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
5
|
|
|
5
|
|
78164
|
use base qw(Graph::Reader); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
3158
|
|
5
|
5
|
|
|
5
|
|
29
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
167
|
|
6
|
5
|
|
|
5
|
|
25
|
use warnings; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
197
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Modules. |
9
|
5
|
|
|
5
|
|
4011
|
use Encode qw(decode_utf8); |
|
5
|
|
|
|
|
58908
|
|
|
5
|
|
|
|
|
433
|
|
10
|
5
|
|
|
5
|
|
3873
|
use Readonly; |
|
5
|
|
|
|
|
13268
|
|
|
5
|
|
|
|
|
2456
|
|
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.01; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Read graph subroutine. |
20
|
|
|
|
|
|
|
sub _read_graph { |
21
|
0
|
|
|
0
|
|
|
my ($self, $graph, $fh) = @_; |
22
|
0
|
|
|
|
|
|
my @indent = ([0, undef]); |
23
|
0
|
|
|
|
|
|
while (my $line = decode_utf8(<$fh>)) { |
24
|
0
|
|
|
|
|
|
chomp $line; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Remove indent. |
27
|
0
|
|
|
|
|
|
my $parseable_line = substr $line, $indent[-1]->[0]; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Split to vertexes. |
30
|
0
|
|
|
|
|
|
my @new_indent; |
31
|
|
|
|
|
|
|
my @vertexes; |
32
|
0
|
|
|
|
|
|
my $new_indent = $indent[-1]->[0]; |
33
|
0
|
|
|
|
|
|
my $last_indent; |
34
|
0
|
|
|
|
|
|
foreach my $new_block (split m/$GR_TREE/ms, $parseable_line) { |
35
|
0
|
0
|
|
|
|
|
if (defined $last_indent) { |
36
|
0
|
|
|
|
|
|
push @new_indent, $last_indent; |
37
|
0
|
|
|
|
|
|
$last_indent = undef; |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
|
my $last_vertex; |
40
|
0
|
|
|
|
|
|
foreach my $new_vertex (split m/$GR_LINE/ms, $new_block) { |
41
|
0
|
|
|
|
|
|
push @vertexes, $new_vertex; |
42
|
0
|
|
|
|
|
|
$last_vertex = $new_vertex; |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
|
$new_indent += (length $new_block) + 3; |
45
|
0
|
|
|
|
|
|
$last_indent = [$new_indent, $last_vertex]; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Add vertexes and edges. |
49
|
0
|
|
|
|
|
|
my $first_v; |
50
|
0
|
0
|
|
|
|
|
if (defined $indent[-1]->[1]) { |
51
|
0
|
|
|
|
|
|
$first_v = $indent[-1]->[1]; |
52
|
|
|
|
|
|
|
} else { |
53
|
0
|
|
|
|
|
|
$first_v = shift @vertexes; |
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
|
$graph->add_vertex($first_v); |
56
|
0
|
|
|
|
|
|
foreach my $second_v (@vertexes) { |
57
|
0
|
|
|
|
|
|
$graph->add_vertex($second_v); |
58
|
0
|
|
|
|
|
|
$graph->add_edge($first_v, $second_v); |
59
|
0
|
|
|
|
|
|
$first_v = $second_v; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Update indent. |
63
|
0
|
|
|
|
|
|
my $end_pos = $indent[-1]->[0] - 2; |
64
|
0
|
0
|
|
|
|
|
if ($end_pos > 0) { |
65
|
0
|
|
|
|
|
|
my $end_char = substr $line, $end_pos, 1; |
66
|
0
|
0
|
|
|
|
|
if ($end_char eq decode_utf8('└')) { |
67
|
0
|
|
|
|
|
|
pop @indent; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
0
|
0
|
|
|
|
|
if (@new_indent) { |
71
|
0
|
|
|
|
|
|
push @indent, @new_indent; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
0
|
|
|
|
|
|
return; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |