Homespring/Node.pm

filter: Statementstmt 72.7% 48 / 66 Branchbran 41.6% 5 / 12 Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 75.0% 9 / 12 Podpod 0.0% 0 / 8 totaltotal 63.4% 66 / 104 CC 12 SCAR 19.0
CC
12
Cov
68%
get_depth
20.0
get_salmon
12.0
new
4.0
CRAP 6.7
« Homespring.pm ↑ Summary Homespring/Snowmelt.pm »
1 package Language::Homespring::Node;
2  
3 4 $VERSION = 0.02;
4  
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 my $node_count = 0;
9  
10 121 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod undocumented
11 121 my $class = shift;
12 121 my $self = bless {}, $class;
13  
14 121 my $options = shift;
15 121 $self->{interp} = $options->{interp};
16 121 ▶ $self->{parent_node} = $options->{parent_node} || undef;
Condition100%2/2
$options->{'parent_node'} || undef
l!l
9526
MC/DC100%1/1
$options->{'parent_node'} || undef
$options->{'parent_node'}
Truth table100%2/2
A
A= $options->{'parent_node'}
Aresult
11
00
17 121 ▶ $self->{node_name} = $options->{node_name} || '';
Condition50%1/2
$options->{'node_name'} || ''
l!l
1210
MC/DC0%0/1
$options->{'node_name'} || ''
$options->{'node_name'}
Truth table50%1/2
A
A= $options->{'node_name'}
Aresult
11
00
18 121 $self->{child_nodes} = [];
19 121 $self->{rivers_up} = [];
20 121 $self->{river_down} = undef;
21 121 $self->{power} = 0;
22 121 $self->{water} = 0;
23 121 $self->{destroyed} = 0;
24 121 $self->{spring} = $self->_is_spring();
25 121 $self->{uid} = ++$node_count;
26 121 $self->{depth} = 0;
27 121 $self->{node_name_safe} = $self->_make_safe($options->{node_name});
28 121 $self->{toggle} = 0;
29  
30 # easier to deal with lowercase commands :)
31 121 ▶ $self->{node_name} = lc($self->{node_name}) if (!$self->{spring});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"spring"} 91 30 121
32  
33 121 return $self;
34 }
35  
36 95 ▶sub add_child {
Subroutine add_child: called CC=1 SCAR=0.0
Pod undocumented
37 95 my ($self, $child) = @_;
38 95 push @{$self->{child_nodes}}, $child;
39 }
40  
41 0 ▶sub get_salmon {
Subroutine get_salmon: not called CC=3 SCAR=24.8
Pod undocumented
42 0 my ($self) = @_;
43 0 my @out;
44 0 for (@{$self->{interp}->{salmon}}){
45 0 ▶ if ($_->{location} eq $self){
Branch: 1 branch
BranchTrueFalseTotal
if ($_->{"location"} eq $self) 0 0 0
46 0 push @out, $_;
47 }
48 }
49 0 return @out;
50 }
51  
52 0 ▶sub get_depth {
Subroutine get_depth: not called CC=4 SCAR=30.0
Pod undocumented
53 0 my ($self) = @_;
54  
55 0 ▶ if (!$self->{depth}){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"depth"}) 0 0 0
56 0 ▶ if (scalar(@{$self->{child_nodes}})){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$self->{'child_nodes'};}) { } 0 0 0
57 0 for (@{$self->{child_nodes}}){
58 0 $self->{depth} += $_->get_depth();
59 }
60 }else{
61 0 $self->{depth} = 2;
62 }
63 }
64  
65 0 return $self->{depth};
66 }
67  
68 121 ▶sub _is_spring {
Subroutine _is_spring: called CC=3 SCAR=11.0
69 121 my ($self) = @_;
70  
71 121 my @keywords = (
72 'powers',
73 'hydro power',
74 'power invert',
75 'marshy',
76 'shallows',
77 'rapids',
78 'bear',
79 'young bear',
80 'bird',
81 'upstream killing device',
82 'net',
83 'current',
84 'insulated',
85 'force field',
86 'bridge',
87 'waterfall',
88 'evaporates',
89 'pump',
90 'fear',
91 'lock',
92 'inverse lock',
93 'narrows',
94 'sense',
95 'switch',
96 'upstream sense',
97 'downstream sense',
98 'range sense',
99 'range switch',
100 'young sense',
101 'young switch',
102 'young range sense',
103 'young range switch',
104 'youth fountain',
105 'time',
106 'reverse up',
107 'reverse down',
108 'force up',
109 'force down',
110 'hatchery',
111 'snowmelt',
112 'append down',
113 'append up',
114 'clone',
115 'universe',
116 'oblivion',
117 'spawn',
118 'split',
119 );
120  
121 121 for (@keywords){
122 2991 ▶ return 0 if (lc $_ eq lc $self->{node_name});
Branch: 1 branch
BranchTrueFalseTotal
if lc $_ eq lc $self->{"node_name"} 91 2900 2991
123 }
124 30 return 1;
125 }
126  
127 121 ▶sub _make_safe {
Subroutine _make_safe: called CC=2 SCAR=7.0
128 121 my ($self, $name) = @_;
129  
130 121 ▶ if ($name){
Branch: 1 branch
BranchTrueFalseTotal
if ($name) 121 0 121
131 121 $name =~ s/\n/\\n/g;
132 }
133  
134 121 return $name;
135 }
136  
137 95 ▶sub add_river_up {
Subroutine add_river_up: called CC=1 SCAR=0.0
Pod undocumented
138 95 my ($self, $river) = @_;
139 95 push @{$self->{rivers_up}}, $river;
140 }
141  
142 95 ▶sub add_river_down {
Subroutine add_river_down: called CC=1 SCAR=0.0
Pod undocumented
143 95 my ($self, $river) = @_;
144 95 $self->{river_down} = $river;
145 }
146  
147 0 ▶sub debug {
Subroutine debug: not called CC=1 SCAR=6.9
Pod undocumented
148 0 my ($self) = @_;
149 0 return "node $self->{uid} ($self->{node_name_safe})";
150 }
151  
152 4 ▶sub every_other {
Subroutine every_other: called CC=1 SCAR=0.0
Pod undocumented
153 4 my ($self) = @_;
154 4 $self->{toggle} = !$self->{toggle};
155 4 return $self->{toggle};
156 }
157  
158 4 1;
159  
« Homespring.pm ↑ Summary Homespring/Snowmelt.pm »