| 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
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 76 | chomp($line); | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 76 | ▶ | next if !$line || $line =~ /^#/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $line or $line =~ /^#/
MC/DC0%0/2
not $line or $line =~ /^#/
not $line
$line =~ /^#/
Truth table33%1/3
not(A) or B
A= not $lineB= $line =~ /^#/
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 76 | my ($depth, $node, @rest) = $self->parse_line($line); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 76 | ▶ | if ( $depth > @stack ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 58 | 38 | ▶ | if ( $depth = @stack + 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||