Parser/Tree.pm

filter: Statementstmt 85.9% 61 / 71 Branchbran 66.6% 12 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 14 / 16 Podpod 0.0% 0 / 15 totaltotal 72.5% 87 / 120 CC 10 SCAR 11.0
CC
10
Cov
82%
print_tree
12.0
is_loop_start
3.0
is_root
2.1
CRAP 3.0
« Parser.pm ↑ Summary
1 # Copyright 2009 by Prasad Balan
2 # All rights reserved.
3 #
4 # This library is free software; you can redistribute it and/or modify
5 # it under the same terms as Perl itself.
6 package X12::Parser::Tree;
7 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 require Exporter;
9 4 our @ISA = qw(Exporter);
10  
11 # Items to export into callers namespace by default. Note: do not export
12 # names by default without a very good reason. Use EXPORT_OK instead.
13 # Do not simply export all your public functions/methods/constants.
14 # This allows declaration use X12::Parser::Tree ':all';
15 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
16 # will save memory.
17 4 our %EXPORT_TAGS = (
18 'all' => [
19 qw(
20 )
21 ]
22 );
23 4 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
24 4 our @EXPORT = qw(
25 );
26 4 our $VERSION = '0.80';
27  
28 # Preloaded methods go here.
29 #use X12::Parser::Tree;
30 #This class holds the loop structure of the X12 transaction.
31 #The class is populated by X12::Parser::Cf and loaded from the *.cf file.
32 #constructor.
33 139 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
34 139 my $self = {
35 _PARENT => undef,
36 _CHILDREN => undef,
37 _NAME => undef,
38 _SEG => undef,
39 _SEG_QUAL => undef,
40 _SEG_QUAL_POS => undef,
41 _DEPTH => 0,
42 };
43 139 return bless $self;
44 }
45  
46 139 ▶sub set_name {
Subroutine set_name: called CC=1 SCAR=0.0
Pod undocumented
47 139 my ( $self, $name ) = @_;
48 139 $self->{_NAME} = $name;
49 }
50  
51 37 ▶sub get_name {
Subroutine get_name: called CC=1 SCAR=0.0
Pod undocumented
52 37 my $self = shift;
53 37 return $self->{_NAME};
54 }
55  
56 1 ▶sub is_root {
Subroutine is_root: called CC=2 SCAR=7.2
Pod undocumented
57 1 my $self = shift;
58 1 ▶ return ( defined $self->{_PARENT} ) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'_PARENT'} ? : 0 1 1
59 }
60  
61 132 ▶sub set_parent {
Subroutine set_parent: called CC=1 SCAR=0.0
Pod undocumented
62 132 my ( $self, $parent ) = @_;
63 132 $self->{_PARENT} = $parent;
64 }
65  
66 100 ▶sub get_parent {
Subroutine get_parent: called CC=1 SCAR=0.0
Pod undocumented
67 100 my $self = shift;
68 100 return $self->{_PARENT};
69 }
70  
71 2 ▶sub has_children {
Subroutine has_children: called CC=2 SCAR=7.2
Pod undocumented
72 2 my $self = shift;
73 2 ▶ return ( defined $self->{_CHILDREN} ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'_CHILDREN'} ? : 2 0 2
74 }
75  
76 417 ▶sub get_child {
Subroutine get_child: called CC=1 SCAR=0.0
Pod undocumented
77 417 my ( $self, $index ) = @_;
78 417 return $self->{_CHILDREN}->[$index];
79 }
80  
81 0 ▶sub get_children {
Subroutine get_children: not called CC=1 SCAR=6.9
Pod undocumented
82 0 my $self = shift;
83 0 return $self->{_CHILDREN};
84 }
85  
86 646 ▶sub get_child_count {
Subroutine get_child_count: called CC=2 SCAR=6.9
Pod undocumented
87 646 my $self = shift;
88 646 ▶ if ( defined $self->{_CHILDREN} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_CHILDREN"}) 581 65 646
89 581 return scalar @{ $self->{_CHILDREN} };
90 }
91 65 return 0;
92 }
93  
94 132 ▶sub add_child {
Subroutine add_child: called CC=2 SCAR=6.9
Pod undocumented
95 132 my ( $self, $child ) = @_;
96 132 ▶ if ( $self->get_child_count() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_child_count) { } 104 28 132
97 104 $child->{_DEPTH} = $self->{_DEPTH} + 1;
98 104 push( @{ $self->{_CHILDREN} }, $child );
99 }
100 else {
101 28 $child->{_DEPTH} = $self->{_DEPTH} + 1;
102 28 my @children;
103 28 $self->{_CHILDREN} = \@children;
104 28 push( @{ $self->{_CHILDREN} }, $child );
105 }
106 }
107  
108 132 ▶sub set_loop_start_parm {
Subroutine set_loop_start_parm: called CC=2 SCAR=6.9
Pod undocumented
109 132 my ( $self, @args ) = @_;
110 132 $self->{_SEG} = $args[0];
111 132 ▶ if ( $args[1] eq '' ) { $self->{_SEG_QUAL_POS} = undef; }
Branch: 1 branch
BranchTrueFalseTotal
if ($args[1] eq '') { } 59 73 132
112 else {
113 73 $self->{_SEG_QUAL_POS} = $args[1];
114 73 my @array = split( /,/, $args[2] );
115 73 $self->{_SEG_QUAL} = \@array;
116 }
117 }
118  
119 414 ▶sub is_loop_start {
Subroutine is_loop_start: called CC=3 SCAR=11.0
Pod undocumented
120 414 my ( $self, $elements ) = @_;
121 414 ▶ if ( $self->{_SEG} eq @{$elements}[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_SEG"} eq @{$elements;}[0]) 33 381 414
122 33 ▶ if ( defined( $self->{_SEG_QUAL_POS} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'_SEG_QUAL_POS'}) { } 16 17 33
123 return
124 20 scalar grep { /@{$elements}[$self->{_SEG_QUAL_POS}]/ }
125 16 @{ $self->{_SEG_QUAL} };
126 }
127 else {
128 17 return 1;
129 }
130 }
131 381 return 0;
132 }
133  
134 17 ▶sub get_depth {
Subroutine get_depth: called CC=1 SCAR=0.0
Pod undocumented
135 17 my $self = shift;
136 17 return $self->{_DEPTH};
137 }
138  
139 0 ▶sub print_tree {
Subroutine print_tree: not called CC=3 SCAR=24.8
Pod undocumented
140 0 my $self = shift;
141 0 my $node = shift;
142 0 ▶ if ( !defined $node ) { $node = $self; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $node) 0 0 0
143 0 my $pad = ' ' x $node->get_depth();
144 0 print $pad . $node->get_name . "\n";
145 0 ▶ for ( my $i = 0 ; $i < $node->get_child_count() ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $node->get_child_count) 0 0 0
146 0 $self->print_tree( $node->get_child($i) );
147 }
148 }
149 4 1;
150 __END__
« Parser.pm ↑ Summary