Highlife/AST.pm

filter: Statementstmt 13.1% 8 / 61 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 14.2% 2 / 14 Podpod 0.0% 0 / 11 totaltotal 9.6% 10 / 104 CC 10 SCAR 20.5
CC
10
Cov
10%
nth_child
20.0
ancestors
12.0
value
6.0
CRAP 7.7
« Highlife/Transformer.pm ↑ Summary Highlife/Rule/Token.pm »
1 package Parse::Highlife::AST;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Parse::Highlife::Utils qw(params);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $ASTElementCounter = 0;
7  
8 sub new
9 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
10 0 my( $class, @args ) = @_;
11 0 my $self = bless {}, $class;
12 0 return $self -> _init( @args );
13 }
14  
15 sub _init
16 0 ▶{
Subroutine _init: not called CC=1 SCAR=6.9
17 0 my( $self, $category, $rulename, $value ) = @_;
18 0 $ASTElementCounter ++;
19 0 $self->{'category'} = $category;
20 0 $self->{'id'} = $ASTElementCounter;
21 0 $self->{'children'} = $value;
22 0 $self->{'parent'} = undef;
23 0 $self->{'parent-id'} = 0;
24 0 $self->{'rulename'} = $rulename;
25 0 return $self;
26 }
27  
28 # returns the first leaf value
29 sub value
30 0 ▶{
Subroutine value: not called CC=2 SCAR=17.9
Pod undocumented
31 0 my( $self ) = @_;
32 0 my @values = $self->values();
33 0 ▶ return ( scalar @values ? $values[0] : '' );
Branch: 1 branch
BranchTrueFalseTotal
scalar @values ? : 0 0 0
34 }
35  
36 # returns all leaf values
37 sub values
38 0 ▶{
Subroutine values: not called CC=2 SCAR=17.9
Pod undocumented
39 0 my( $self ) = @_;
40 0 my @values;
41 0 ▶ if( $self->{'category'} eq 'leaf' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'category'} eq 'leaf') { } 0 0 0
42 0 push @values, $self->{'children'};
43 }
44 else { # group
45 0 map { push @values, $_->values() } @{$self->{'children'}};
46 }
47 0 return @values;
48 }
49  
50 sub has_ancestor
51 0 ▶{
Subroutine has_ancestor: not called CC=1 SCAR=6.9
Pod undocumented
52 0 my( $self, $rulename ) = @_;
53 0 return ref $self->ancestor( $rulename );
54 }
55  
56 sub ancestor
57 0 ▶{
Subroutine ancestor: not called CC=2 SCAR=17.9
Pod undocumented
58 0 my( $self, $rulename ) = @_;
59 0 my @asts = $self->ancestors( $rulename );
60 0 ▶ return scalar @asts ? $asts[0] : 0;
Branch: 1 branch
BranchTrueFalseTotal
scalar @asts ? : 0 0 0
61 }
62  
63 sub ancestors
64 0 ▶{
Subroutine ancestors: not called CC=3 SCAR=24.8
Pod undocumented
65 0 my( $self, $rulename ) = @_;
66 0 ▶ if( $self->{'rulename'} eq $rulename ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'rulename'} eq $rulename) { } 0 0 0
elsif ($self->{'category'} eq 'group') { } 0 0 0
67 0 return ($self);
68 }
69 elsif( $self->{'category'} eq 'group' ) {
70 0 return map { $_->ancestors( $rulename ) } @{$self->{'children'}};
71 }
72 0 return ();
73 }
74  
75 sub nth_child
76 0 ▶{
Subroutine nth_child: not called CC=4 SCAR=30.0
Pod undocumented
77 0 my( $self, $n ) = @_;
78 0 ▶ if( $self->{'category'} eq 'group' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'category'} eq 'group') { } 0 0 0
elsif ($self->{'category'} eq 'leaf') { } 0 0 0
79 0 ▶ if( scalar @{$self->{'children'}} >= $n ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$self->{'children'};} >= $n) { } 0 0 0
80 0 return $self->{'children'}->[$n-1];
81 }
82 else {
83 0 return 0;
84 }
85 }
86 elsif( $self->{'category'} eq 'leaf' ) {
87 0 return $self->{'children'};
88 }
89 }
90  
91 sub children
92 0 ▶{
Subroutine children: not called CC=2 SCAR=17.9
Pod undocumented
93 0 my( $self ) = @_;
94 0 ▶ if( $self->{'category'} eq 'group' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"category"} eq "group") 0 0 0
95 0 return @{$self->{'children'}};
96 }
97 0 return ();
98 }
99  
100 sub first_child
101 0 ▶{
Subroutine first_child: not called CC=1 SCAR=6.9
Pod undocumented
102 0 my( $self ) = @_;
103 0 return $self->nth_child(1);
104 }
105  
106 sub second_child
107 0 ▶{
Subroutine second_child: not called CC=1 SCAR=6.9
Pod undocumented
108 0 my( $self ) = @_;
109 0 return $self->nth_child(2);
110 }
111  
112 sub third_child
113 0 ▶{
Subroutine third_child: not called CC=1 SCAR=6.9
Pod undocumented
114 0 my( $self ) = @_;
115 0 return $self->nth_child(3);
116 }
117  
118 1 1;
« Highlife/Transformer.pm ↑ Summary Highlife/Rule/Token.pm »