DEC/Declaration.pm

filter: Statementstmt 15.4% 11 / 71 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 23.0% 3 / 13 Podpod 0.0% 0 / 9 totaltotal 11.5% 14 / 121 CC 14 SCAR 28.8
CC
14
Cov
12%
subvalues
42.0
_init
20.0
dump
20.0
CRAP 17.8
« DEC.pm ↑ Summary
1 package Data::DEC::Declaration;
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::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $UnnamedCounter = 0;
8  
9 sub new
10 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
11 0 my( $class, @args ) = @_;
12 0 my $self = bless {}, $class;
13 0 return $self -> _init( @args );
14 }
15  
16 sub _init
17 0 ▶{
Subroutine _init: not called CC=4 SCAR=30.0
18 # type: identifier | string | number | real | map
19 # valuetype: name of the map declaration
20 0 my( $self, $name, $type, $value, $valuetype ) = @_;
21 0 ▶ $valuetype = '' unless defined $valuetype;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $valuetype 0 0 0
22 0 ▶ if( ! defined $name || ! length $name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name and length $name) 0 0 0
Condition0%0/3
defined $name and length $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table0%0/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
23 0 $name = $UnnamedCounter;
24 0 $UnnamedCounter ++;
25 }
26 0 $self->{'name'} = $name;
27 0 $self->{'type'} = $type;
28 0 $self->{'value'} = $value;
29 0 $self->{'value-type'} = $valuetype;
30 0 return $self;
31 }
32  
33 sub name
34 0 ▶{
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
35 0 my( $self ) = @_;
36 0 return $self->{'name'};
37 }
38  
39 sub type
40 0 ▶{
Subroutine type: not called CC=1 SCAR=6.9
Pod undocumented
41 0 my( $self ) = @_;
42 0 return $self->{'type'};
43 }
44  
45 sub value
46 0 ▶{
Subroutine value: not called CC=1 SCAR=6.9
Pod undocumented
47 0 my( $self ) = @_;
48 0 return $self->{'value'};
49 }
50  
51 sub valuetype
52 0 ▶{
Subroutine valuetype: not called CC=1 SCAR=6.9
Pod undocumented
53 0 my( $self ) = @_;
54 0 return $self->{'value-type'};
55 }
56  
57 sub subvalue
58 0 ▶{
Subroutine subvalue: not called CC=1 SCAR=6.9
Pod undocumented
59 0 my( $self, @args ) = @_;
60 0 return $self->subvalues( @args );
61 }
62  
63 sub subvalues
64 0 ▶{
Subroutine subvalues: not called CC=6 SCAR=37.4
Pod undocumented
65 0 my( $self, $subvalue_key_name ) = @_;
66 0 ▶ return () if ref $self->{'value'} ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"value"} ne "ARRAY" 0 0 0
67 0 my @subvalues;
68 0 foreach my $pair ( @{ $self->{'value'} } ) {
69 0 my( $name, $value ) = @{$pair};
70 0 ▶ push @subvalues, $value
Branch: 1 branch
BranchTrueFalseTotal
if not defined $subvalue_key_name or $name eq $subvalue_key_name 0 0 0
Condition0%0/3
not defined $subvalue_key_name or $name eq $subvalue_key_name
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $subvalue_key_name or $name eq $subvalue_key_name
not defined $subvalue_key_name $name eq $subvalue_key_name
Truth table0%0/3
not(A) or B
A= not defined $subvalue_key_nameB= $name eq $subvalue_key_name
ABresult
1X1
011
000
71 if ! defined $subvalue_key_name || $name eq $subvalue_key_name;
72 }
73 0 ▶ return (wantarray() ? @subvalues : shift @subvalues);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
74 }
75  
76 sub unique_subvalues
77 0 ▶{
Subroutine unique_subvalues: not called CC=3 SCAR=24.8
Pod undocumented
78 0 my( $self ) = @_;
79 0 ▶ return () if ref $self->{'value'} ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"value"} ne "ARRAY" 0 0 0
80 0 my %subvalues;
81 0 foreach my $pair ( @{ $self->{'value'} } ) {
82 0 my( $name, $value ) = @{$pair};
83 0 $subvalues{ $name } = $value;
84 }
85 0 return %subvalues;
86 }
87  
88 sub dump
89 0 ▶{
Subroutine dump: not called CC=4 SCAR=30.0
Pod undocumented
90 0 my( $self ) = @_;
91 0 my $w = 16;
92 0 print sprintf('%-'.$w.'s', '#'.$self->{'name'}.' ');
93 0 ▶ print $self->{'value-type'}.' ' if length $self->{'value-type'};
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"value-type"} 0 0 0
94 0 ▶ if( $self->{'type'} eq 'map' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'type'} eq 'map') { } 0 0 0
elsif ($self->{'type'} eq 'string') { } 0 0 0
95 0 print "{\n";
96 map {
97 0 my( $name, $value ) = @{$_};
98 0 print ''.(' ' x $w)." $name: #".$value->{'name'}."\n";
99 0 } @{$self->{'value'}};
100 0 print ''.(' ' x $w)."}";
101 }
102 elsif( $self->{'type'} eq 'string' ) {
103 0 my $s = $self->{'value'};
104 0 $s =~ s/\n/\\n/g;
105 0 $s =~ s/\r/\\r/g;
106 0 $s =~ s/"/\\"/g;
107 0 print "\"$s\"";
108 }
109 else {
110 0 print $self->{'value'};
111 }
112 0 print "\n";
113 }
114  
115 1 1;
116  
« DEC.pm ↑ Summary