Gherkin/Node.pm

filter: Statementstmt 100% 53 / 53 Branchbran 93.7% 15 / 16 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 98.8% 83 / 84 CC 12 SCAR 15.3
CC
12
Cov
99%
new
9.0
_set_immutable
3.0
_add_property
2.0
CRAP 4.6
« Gherkin/Node/Table/Row.pm ↑ Summary Gherkin/Parser.pm »
1 package Test::Pcuke::Gherkin::Node;
2  
3 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 ▶use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Test::Pcuke::Gherkin::Node - Base class for Gherkin nodes
12  
13 =head1 SYNOPSIS
14  
15 package MyClass;
16 use base 'Test::Pcuke::Gherkin::Node';
17
18 sub new {
19 my ($class, %args) = @_;
20
21 my @properties = qw{property1 property2};
22 my @immutable_properties = qw{immutable1 immutable2};
23
24 return $class->SUPER::new(
25 immutable_properties => [ @immutable_properties ],
26 properties => [ @properties ],
27 args => {%args}
28 );
29 }
30
31 sub set_property1 {
32 my ($self, $value) = @_;
33 $self->_set_property('property1', $value);
34 }
35
36 sub property1 { $_[0]->_get_property('property1'); }
37
38 #... etc.
39  
40 =head1 METHODS
41  
42 =cut
43  
44 {
45
46 11 my %properties = ();
47 11 my %immutables = ();
48
49 =head2 new
50  
51 =cut
52  
53 72 ▶ sub new {
Subroutine new: called CC=9 SCAR=22.0
Pod documented
54 72 my ($class, %conf) = @_;
55
56 72 my $self = bless \do { my $anonymous_scalar }, $class;
57  
58 72 ▶ return $self
Branch: 1 branch
BranchTrueFalseTotal
unless %conf 5 67 72
59 unless %conf;
60
61 67 my $args = $conf{args};
62 67 ▶ return $self
Branch: 1 branch
BranchTrueFalseTotal
unless $args 8 59 67
63 unless $args;
64
65 59 ▶ if ( ref $conf{properties} eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $conf{"properties"} eq "ARRAY") 34 25 59
66 34 foreach my $name ( @{ $conf{properties} } ) {
67 $self->_set_property( $name, $args->{$name} )
68 89 ▶ if defined $args->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{$name} 63 26 89
69 }
70 }
71
72 59 ▶ if ( ref $conf{immutables} eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $conf{"immutables"} eq "ARRAY") 59 0 59
73 59 foreach my $name ( @{ $conf{immutables} } ) {
74 $self->_set_immutable($name, $args->{$name})
75 189 ▶ if defined $args->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{$name} 66 123 189
76 }
77 }
78
79 59 return $self;
80 }
81  
82 87 ▶ sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
83 87 my $key = refaddr shift;
84 87 delete $properties{$key};
85 87 delete $immutables{$key};
86 }
87
88 177 ▶ sub _set_property {
Subroutine _set_property: called CC=1 SCAR=0.0
89 177 my ($self, $name, $value) = @_;
90 177 my $key = refaddr $self;
91 177 $properties{$key}->{$name} = $value;
92 }
93
94 101 ▶ sub _set_immutable {
Subroutine _set_immutable: called CC=3 SCAR=11.0
95 101 my ($self, $name, $value) = @_;
96
97 101 my $key = refaddr $self;
98
99 101 ▶ if ( defined $immutables{$key}->{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $immutables{$key}{$name}) { } 13 88 101
100 13 confess ref($self) . "::$name is an immutable property and can not be changed";
101 }
102 else {
103 88 ▶ $immutables{$key}->{$name} = $value || q{};
Condition100%2/2
$value || ''
l!l
826
MC/DC100%1/1
$value || ''
$value
Truth table100%2/2
A
A= $value
Aresult
11
00
104 }
105 }
106
107 169 ▶ sub _get_property {
Subroutine _get_property: called CC=1 SCAR=0.0
108 169 my ($self, $name) = @_;
109 169 my $key = refaddr $self;
110 169 $properties{$key}->{$name};
111 }
112
113 95 ▶ sub _get_immutable {
Subroutine _get_immutable: called CC=1 SCAR=0.0
114 95 my ($self, $name) = @_;
115 95 my $key = refaddr $self;
116 95 $immutables{$key}->{$name};
117 }
118
119 }
120  
121 11 ▶sub _add_property {
Subroutine _add_property: called CC=2 SCAR=6.9
122 38 my ($self, $name, $value) = @_;
123
124 38 ▶ confess "scenario must be defined"
Branch: 1 branch
BranchTrueFalseTotal
unless $value 2 36 38
125 unless $value;
126
127 36 my $values = $self->_get_property($name);
128 36 push @$values, $value;
129 36 $self->_set_property($name, $values);
130
131 }
132  
133 11 1; # End of Test::Pcuke::Gherkin::Node
134 __END__
« Gherkin/Node/Table/Row.pm ↑ Summary Gherkin/Parser.pm »