Highlife/Transformer.pm

filter: Statementstmt 21.2% 10 / 47 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 23.0% 3 / 13 Podpod 0.0% 0 / 7 totaltotal 14.6% 13 / 89 CC 9 SCAR 22.4
CC
9
Cov
15%
transform
20.0
stringify
20.0
transform_children
6.0
CRAP 9.4
« Highlife/Rule/Sequence.pm ↑ Summary Highlife/AST.pm »
1 package Parse::Highlife::Transformer;
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 1 ▶use Data::Dump qw(dump);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 sub new
8 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
9 0 my( $class, @args ) = @_;
10 0 my $self = bless {}, $class;
11 0 return $self -> _init( @args );
12 }
13  
14 sub _init
15 0 ▶{
Subroutine _init: not called CC=1 SCAR=6.9
16 0 my( $self, @args ) = @_;
17 0 $self->{'transformers'} = {};
18 0 $self->{'stringifiers'} = {};
19 0 return $self;
20 }
21  
22 sub transformer
23 0 ▶{
Subroutine transformer: not called CC=1 SCAR=6.9
Pod undocumented
24 my( $self, $name, $coderef )
25 = params( \@_,
26 -rule => '',
27 0 ▶ -fn => sub {},
Subroutine __ANON__: not called CC=1 SCAR=0.0
28 0 );
29 0 $self->{'transformers'}->{$name} = $coderef;
30 0 return 1;
31 }
32  
33 sub stringifier
34 0 ▶{
Subroutine stringifier: not called CC=1 SCAR=6.9
Pod undocumented
35 my( $self, $name, $coderef )
36 = params( \@_,
37 -rule => '',
38 0 ▶ -fn => sub {},
Subroutine __ANON__: not called CC=1 SCAR=0.0
39 0 );
40 0 $self->{'stringifiers'}->{$name} = $coderef;
41 0 return 1;
42 }
43  
44 sub transform
45 0 ▶{
Subroutine transform: not called CC=4 SCAR=30.0
Pod undocumented
46 0 my( $self, $ast, @params ) = @_;
47
48 0 my $transformer_name = $ast->{'rulename'};
49 #print "-- TRANSFORM $transformer_name --\n";
50
51 0 ▶ if( exists $self->{'transformers'}->{$transformer_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'transformers'}{$transformer_name}) { } 0 0 0
52 0 my $new_ast = $self->{'transformers'}->{$transformer_name}->( $self, $ast, @params );
53 0 ▶ return ( defined $new_ast && ref $new_ast eq 'Parse::Highlife::AST' ? $new_ast : $ast );
Branch: 1 branch
BranchTrueFalseTotal
defined $new_ast && ref $new_ast eq 'Parse::Highlife::AST' ? : 0 0 0
Condition0%0/3
defined $new_ast and ref $new_ast eq "Parse::Highlife::AST"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $new_ast and ref $new_ast eq "Parse::Highlife::AST"
defined $new_ast ref $new_ast eq "Parse::Highlife::AST"
Truth table0%0/3
A and B
A= defined $new_astB= ref $new_ast eq "Parse::Highlife::AST"
ABresult
0X0
100
111
54 }
55 else {
56 0 return $self->transform_children( $ast, @params );
57 }
58 }
59  
60 sub transform_children
61 0 ▶{
Subroutine transform_children: not called CC=2 SCAR=17.9
Pod undocumented
62 0 my( $self, $ast, @params ) = @_;
63 0 ▶ if( $ast->{'category'} eq 'group' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ast->{"category"} eq "group") 0 0 0
64 $ast->{'children'} =
65 [
66 0 map { $self->transform( $_, @params ) } @{$ast->{'children'}}
67 ];
68 }
69 # leaf's are not transformed by default
70 0 return $ast;
71 }
72  
73 sub stringify
74 0 ▶{
Subroutine stringify: not called CC=4 SCAR=30.0
Pod undocumented
75 0 my( $self, $ast, @params ) = @_;
76
77 0 my $stringifier_name = $ast->{'rulename'};
78 #print "-- STRINGIFY $stringifier_name --\n";
79
80 0 ▶ if( exists $self->{'stringifiers'}->{$stringifier_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'stringifiers'}{$stringifier_name}) { } 0 0 0
81 0 my $string = $self->{'stringifiers'}->{$stringifier_name}->( $self, $ast, @params );
82 0 ▶ return ( defined $string && ! ref $string ? $string : '?' );
Branch: 1 branch
BranchTrueFalseTotal
defined $string && !ref($string) ? : 0 0 0
Condition0%0/3
defined $string and not ref $string
!ll&&!rl&&r
000
MC/DC0%0/2
defined $string and not ref $string
defined $string not ref $string
Truth table0%0/3
A and not(B)
A= defined $stringB= not ref $string
ABresult
0X0
100
111
83 }
84 else {
85 0 return $self->stringify_children( $ast, @params );
86 }
87 }
88  
89 sub stringify_children
90 0 ▶{
Subroutine stringify_children: not called CC=2 SCAR=17.9
Pod undocumented
91 0 my( $self, $ast, @params ) = @_;
92 0 ▶ if( $ast->{'category'} eq 'group' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ast->{"category"} eq "group") 0 0 0
93 0 return join '', map { $self->stringify( $_, @params ) } @{$ast->{'children'}};
94 }
95 # leaf's are not stringified by default
96 0 return $ast->{'children'};
97 }
98  
99 1 1;
100  
« Highlife/Rule/Sequence.pm ↑ Summary Highlife/AST.pm »