Forest/Tree/Builder/SimpleTextFile.pm

filter: Statementstmt 86.9% 40 / 46 Branchbran 85.7% 12 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 71.4% 5 / 7 Podpod 0.0% 0 / 2 totaltotal 78.3% 58 / 74 CC 11 SCAR 20.5
CC
11
Cov
84%
_build_subtrees
11.2
build_parser
2.0
__ANON__
2.0
CRAP 7.7
« Forest/Tree/Constructor.pm ↑ Summary Forest/Tree/Loader/SimpleUIDLoader.pm »
1 package Forest::Tree::Builder::SimpleTextFile;
2 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 10 our $VERSION = '0.10';
5 10 our $AUTHORITY = 'cpan:STEVAN';
6  
7 10 ▶no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 10 with qw(Forest::Tree::Builder::Callback); # for compatibility with overriding create_new_subtree, otherwise invisible
10  
11 10 has fh => (
12 isa => "FileHandle",
13 is => "ro",
14 required => 1,
15 );
16  
17 10 has 'tab_width' => (
18 is => 'rw',
19 isa => 'Int',
20 default => 4
21 );
22  
23 10 has 'parser' => (
24 is => 'rw',
25 isa => 'CodeRef',
26 lazy => 1,
27 builder => 'build_parser',
28 );
29  
30 0 ▶sub build_parser {
Subroutine build_parser: not called CC=1 SCAR=6.9
Pod undocumented
31 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 0 my ($self, $line) = @_;
33 0 my ($indent, $node) = ($line =~ /^(\s*)(.*)$/);
34 0 my $depth = ((length $indent) / $self->tab_width);
35 0 return ($depth, $node);
36 }
37 0 }
38  
39 76 ▶sub parse_line { $_[0]->parser->(@_) }
Subroutine parse_line: called CC=1 SCAR=0.0
Pod undocumented
40  
41 8 ▶sub _build_subtrees {
Subroutine _build_subtrees: called CC=11 SCAR=24.2
42 8 my $self = shift;
43  
44 8 my $cur_children = [];
45 8 my @stack;
46  
47 8 my $fh = $self->fh;
48  
49 8 ▶ while ( defined(my $line = <$fh>) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 76 8 84
50  
51 76 chomp($line);
52  
53 76 ▶ next if !$line || $line =~ /^#/;
Branch: 1 branch
BranchTrueFalseTotal
if not $line or $line =~ /^#/ 0 76 76
Condition33%1/3
not $line or $line =~ /^#/
l!l&&r!l&&!r
0076
MC/DC0%0/2
not $line or $line =~ /^#/
not $line $line =~ /^#/
Truth table33%1/3
not(A) or B
A= not $lineB= $line =~ /^#/
ABresult
1X1
011
000
54  
55 76 my ($depth, $node, @rest) = $self->parse_line($line);
56  
57 76 ▶ if ( $depth > @stack ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($depth > @stack) { } 38 38 76
elsif ($depth < @stack) { } 14 24 38
58 38 ▶ if ( $depth = @stack + 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth = @stack + 1) { } 38 0 38
59 38 push @stack, $cur_children;
60 38 $cur_children = $cur_children->[-1]{children} = [];
61 } else {
62 0 die "Parse Error : the difference between the depth ($depth) and " .
63 "the tree depth (" . scalar(@stack) . ") is too much (" .
64 ($depth - @stack) . ") at line:\n'$line'";
65 }
66 } elsif ( $depth < @stack ) {
67 14 ▶ while ( $depth < @stack ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth < @stack) 21 14 35
68 21 foreach my $node ( @$cur_children ) {
69 28 $node = $self->create_new_subtree(%$node);
70 }
71  
72 21 $cur_children = pop @stack;
73 }
74 }
75  
76 76 push @$cur_children, { node => $node, @rest };
77 }
78  
79 8 ▶ while ( @stack ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stack) 17 8 25
80 17 $_ = $self->create_new_subtree(%$_) for @$cur_children;
81 17 $cur_children = pop @stack;
82 }
83  
84 8 return [ map { $self->create_new_subtree(%$_) } @$cur_children ];
85 }
86  
87  
88 10 __PACKAGE__->meta->make_immutable;
89  
90 10 ▶no Moose; 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
91  
92 __END__
« Forest/Tree/Constructor.pm ↑ Summary Forest/Tree/Loader/SimpleUIDLoader.pm »