blib/lib/Graph/Reader/UnicodeTree.pm

filter: Statementstmt 100% 54 / 54 Branchbran 100% 12 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 100% 72 / 72 CC 10 SCAR 19.5
CC
10
Cov
100%
_read_graph
10.0
BEGIN
1.0
BEGIN
1.0
CRAP 7.0
↑ Summary
1 package Graph::Reader::UnicodeTree;
2  
3 4 ▶use base qw(Graph::Reader);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use Encode qw(decode_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # Constants.
11 4 Readonly::Scalar our $GR_LINE => decode_utf8(q{───});
12 4 Readonly::Scalar our $GR_TREE => decode_utf8(q{─┬─});
13  
14 4 our $VERSION = 0.03;
15  
16 # Read graph subroutine.
17 5 ▶sub _read_graph {
Subroutine _read_graph: called CC=10 SCAR=23.0
18 5 my ($self, $graph, $fh) = @_;
19 5 my @indent = ([0, undef]);
20 5 ▶ while (my $line = decode_utf8(<$fh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = &decode_utf8(scalar readline $fh)) 17 5 22
21 17 chomp $line;
22  
23 # Remove indent.
24 17 my $parseable_line = substr $line, $indent[-1]->[0];
25  
26 # Split to vertexes.
27 17 my @new_indent;
28 my @vertexes;
29 17 my $new_indent = $indent[-1]->[0];
30 17 my $last_indent;
31 17 foreach my $new_block (split m/$GR_TREE/ms, $parseable_line) {
32 23 ▶ if (defined $last_indent) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_indent) 6 17 23
33 6 push @new_indent, $last_indent;
34 6 $last_indent = undef;
35 }
36 23 my $last_vertex;
37 23 foreach my $new_vertex (split m/$GR_LINE/ms, $new_block) {
38 44 push @vertexes, $new_vertex;
39 44 $last_vertex = $new_vertex;
40 }
41 23 $new_indent += (length $new_block) + 3;
42 23 $last_indent = [$new_indent, $last_vertex];
43 }
44  
45 # Add vertexes and edges.
46 17 my $first_v;
47 17 ▶ if (defined $indent[-1]->[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $indent[-1][1]) { } 12 5 17
48 12 $first_v = $indent[-1]->[1];
49 } else {
50 5 $first_v = shift @vertexes;
51 }
52 17 $graph->add_vertex($first_v);
53 17 foreach my $second_v (@vertexes) {
54 39 $graph->add_vertex($second_v);
55 39 $graph->add_edge($first_v, $second_v);
56 39 $first_v = $second_v;
57 }
58  
59 # Update indent.
60 17 my $end_pos = $indent[-1]->[0] - 2;
61 17 ▶ if ($end_pos > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end_pos > 0) 12 5 17
62 12 my $end_char = substr $line, $end_pos, 1;
63 12 ▶ if ($end_char eq decode_utf8('└')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($end_char eq &decode_utf8("\342\224\224")) 6 6 12
64 6 pop @indent;
65 }
66 }
67 17 ▶ if (@new_indent) {
Branch: 1 branch
BranchTrueFalseTotal
if (@new_indent) 5 12 17
68 5 push @indent, @new_indent;
69 }
70 }
71 5 return;
72 }
73  
74 4 1;
75  
76 __END__
↑ Summary