Homespring/Salmon.pm

filter: Statementstmt 97.3% 73 / 75 Branchbran 86.1% 31 / 36 Conditioncond 100% 36 / 36 MC/DCmcdc 100% 21 / 21 Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 6 totaltotal 92.3% 168 / 182 CC 32 SCAR 29.4
CC
32
Cov
95%
move
26.0
debug
12.0
new
4.0
CRAP 18.9
« Homespring/Visualise.pm ↑ Summary Homespring.pm »
1 package Language::Homespring::Salmon;
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 $salmon_count = 0;
9  
10 187 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod undocumented
11 187 my $class = shift;
12 187 my $self = bless {}, $class;
13  
14 187 my $options = shift;
15 187 $self->{interp} = $options->{interp};
16 187 ▶ $self->{value} = $options->{value} || 'homeless';
Condition100%2/2
$options->{'value'} || 'homeless'
l!l
84103
MC/DC100%1/1
$options->{'value'} || 'homeless'
$options->{'value'}
Truth table100%2/2
A
A= $options->{'value'}
Aresult
11
00
17 187 ▶ $self->{upstream} = $options->{upstream} || 0;
Condition100%2/2
$options->{'upstream'} || 0
l!l
10384
MC/DC100%1/1
$options->{'upstream'} || 0
$options->{'upstream'}
Truth table100%2/2
A
A= $options->{'upstream'}
Aresult
11
00
18 187 ▶ $self->{mature} = $options->{mature} || 0;
Condition100%2/2
$options->{'mature'} || 0
l!l
10384
MC/DC100%1/1
$options->{'mature'} || 0
$options->{'mature'}
Truth table100%2/2
A
A= $options->{'mature'}
Aresult
11
00
19 187 $self->{location} = $options->{location};
20 187 $self->{time_in_river} = 0;
21 187 $self->{uid} = ++$salmon_count;
22  
23 #print "Creating salmon : ".$self->debug()."\n";
24  
25 187 return $self;
26 }
27  
28 338 ▶sub move {
Subroutine move: called CC=26 SCAR=32.6
Pod undocumented
29 338 my ($self) = @_;
30 338 my ($node_to_pass, $river_target);
31  
32 338 ▶ if ($self->{upstream}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'upstream'}) { } 90 248 338
33 90 $node_to_pass = $self->{location}->{up_node};
34 90 $river_target = undef;
35 90 ▶ if ($node_to_pass){
Branch: 1 branch
BranchTrueFalseTotal
if ($node_to_pass) 90 0 90
36 90 my $count = scalar(@{$node_to_pass->{rivers_up}});
37 90 ▶ if ($count){
Branch: 1 branch
BranchTrueFalseTotal
if ($count) 11 79 90
38 11 $river_target = @{$node_to_pass->{rivers_up}}[0];
39 }
40 }
41 }else{
42 248 $node_to_pass = $self->{location}->{down_node};
43 248 $river_target = $node_to_pass->{river_down};
44 }
45  
46 338 $self->{time_in_river}++;
47  
48 ##
49 ## see if we can pass the next node
50 ##
51  
52 338 my $node_name = $node_to_pass->{node_name};
53  
54 338 ▶ return if (($node_to_pass->{node_name} eq 'shallows') && ($self->{mature}) && ($self->{time_in_river} == 1));
Branch: 1 branch
BranchTrueFalseTotal
if $node_to_pass->{"node_name"} eq "shallows" and $self->{"mature"} and $self->{"time_in_river"} == 1 3 335 338
Condition100%6/6
$node_to_pass->{"node_name"} eq "shallows" and $self->{"mature"} and $self->{"time_in_river"} == 1
!ll&&!rl&&r
33323
$node_to_pass->{"node_name"} eq "shallows" and $self->{"mature"}
!ll&&!rl&&r
33035
MC/DC100%3/3
$node_to_pass->{"node_name"} eq "shallows" and $self->{"mature"} and $self->{"time_in_river"} == 1
$node_to_pass->{"node_name"} eq "shallows" $self->{"mature"} $self->{"time_in_river"} == 1
Truth table100%4/4
A and B and C
A= $node_to_pass->{"node_name"} eq "shallows"B= $self->{"mature"}C= $self->{"time_in_river"} == 1
ABCresult
0XX0
10X0
1100
1111
55 335 ▶ return if (($node_to_pass->{node_name} eq 'rapids') && (!$self->{mature}) && ($self->{time_in_river} == 1));
Branch: 1 branch
BranchTrueFalseTotal
if $node_to_pass->{"node_name"} eq "rapids" and not $self->{"mature"} and $self->{"time_in_river"} == 1 3 332 335
Condition100%6/6
$node_to_pass->{"node_name"} eq "rapids" and not $self->{"mature"} and $self->{"time_in_river"} == 1
!ll&&!rl&&r
33023
$node_to_pass->{"node_name"} eq "rapids" and not $self->{"mature"}
!ll&&!rl&&r
32735
MC/DC100%3/3
$node_to_pass->{"node_name"} eq "rapids" and not $self->{"mature"} and $self->{"time_in_river"} == 1
$node_to_pass->{"node_name"} eq "rapids" not $self->{"mature"} $self->{"time_in_river"} == 1
Truth table100%4/4
A and not(B) and C
A= $node_to_pass->{"node_name"} eq "rapids"B= not $self->{"mature"}C= $self->{"time_in_river"} == 1
ABCresult
0XX0
10X0
1100
1111
56  
57 332 ▶ return if (($node_to_pass->{node_name} eq 'net') && ($self->{mature}));
Branch: 1 branch
BranchTrueFalseTotal
if $node_to_pass->{"node_name"} eq "net" and $self->{"mature"} 6 326 332
Condition100%3/3
$node_to_pass->{"node_name"} eq "net" and $self->{"mature"}
!ll&&!rl&&r
32246
MC/DC100%2/2
$node_to_pass->{"node_name"} eq "net" and $self->{"mature"}
$node_to_pass->{"node_name"} eq "net" $self->{"mature"}
Truth table100%3/3
A and B
A= $node_to_pass->{"node_name"} eq "net"B= $self->{"mature"}
ABresult
0X0
100
111
58 326 ▶ return if (($node_to_pass->{node_name} eq 'current') && (!$self->{mature}));
Branch: 1 branch
BranchTrueFalseTotal
if $node_to_pass->{"node_name"} eq "current" and not $self->{"mature"} 3 323 326
Condition100%3/3
$node_to_pass->{"node_name"} eq "current" and not $self->{"mature"}
!ll&&!rl&&r
32123
MC/DC100%2/2
$node_to_pass->{"node_name"} eq "current" and not $self->{"mature"}
$node_to_pass->{"node_name"} eq "current" not $self->{"mature"}
Truth table100%3/3
A and not(B)
A= $node_to_pass->{"node_name"} eq "current"B= not $self->{"mature"}
ABresult
0X0
100
111
59  
60 323 ▶ if (($node_to_pass->{node_name} eq 'bear') && ($self->{mature})){
Branch: 1 branch
BranchTrueFalseTotal
if ($node_to_pass->{"node_name"} eq "bear" and $self->{"mature"}) 19 304 323
Condition100%3/3
$node_to_pass->{"node_name"} eq "bear" and $self->{"mature"}
!ll&&!rl&&r
2822219
MC/DC100%2/2
$node_to_pass->{"node_name"} eq "bear" and $self->{"mature"}
$node_to_pass->{"node_name"} eq "bear" $self->{"mature"}
Truth table100%3/3
A and B
A= $node_to_pass->{"node_name"} eq "bear"B= $self->{"mature"}
ABresult
0X0
100
111
61 19 $self->kill();
62 19 return;
63 }
64  
65 304 ▶ if (($node_to_pass->{node_name} eq 'young bear') && ($self->{mature})){
Branch: 1 branch
BranchTrueFalseTotal
if ($node_to_pass->{"node_name"} eq "young bear" and $self->{"mature"}) 4 300 304
Condition100%3/3
$node_to_pass->{"node_name"} eq "young bear" and $self->{"mature"}
!ll&&!rl&&r
29644
MC/DC100%2/2
$node_to_pass->{"node_name"} eq "young bear" and $self->{"mature"}
$node_to_pass->{"node_name"} eq "young bear" $self->{"mature"}
Truth table100%3/3
A and B
A= $node_to_pass->{"node_name"} eq "young bear"B= $self->{"mature"}
ABresult
0X0
100
111
66 4 ▶ if ($node_to_pass->every_other()){
Branch: 1 branch
BranchTrueFalseTotal
if ($node_to_pass->every_other) 2 2 4
67 2 $self->kill();
68 2 return;
69 }
70 }
71  
72 302 ▶ if (($node_to_pass->{node_name} eq 'bird') && (!$self->{mature})){
Branch: 1 branch
BranchTrueFalseTotal
if ($node_to_pass->{"node_name"} eq "bird" and not $self->{"mature"}) 2 300 302
Condition100%3/3
$node_to_pass->{"node_name"} eq "bird" and not $self->{"mature"}
!ll&&!rl&&r
29822
MC/DC100%2/2
$node_to_pass->{"node_name"} eq "bird" and not $self->{"mature"}
$node_to_pass->{"node_name"} eq "bird" not $self->{"mature"}
Truth table100%3/3
A and not(B)
A= $node_to_pass->{"node_name"} eq "bird"B= not $self->{"mature"}
ABresult
0X0
100
111
73 2 $self->kill();
74 2 return;
75 }
76  
77 300 ▶ if (($node_to_pass->{node_name} eq 'force field') && ($node_to_pass->{power})){
Branch: 1 branch
BranchTrueFalseTotal
if ($node_to_pass->{"node_name"} eq "force field" and $node_to_pass->{"power"}) 15 285 300
Condition100%3/3
$node_to_pass->{"node_name"} eq "force field" and $node_to_pass->{"power"}
!ll&&!rl&&r
2711415
MC/DC100%2/2
$node_to_pass->{"node_name"} eq "force field" and $node_to_pass->{"power"}
$node_to_pass->{"node_name"} eq "force field" $node_to_pass->{"power"}
Truth table100%3/3
A and B
A= $node_to_pass->{"node_name"} eq "force field"B= $node_to_pass->{"power"}
ABresult
0X0
100
111
78 15 ▶ if ($self->{upstream}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'upstream'}) { } 5 10 15
79 5 $self->spawn($node_to_pass);
80 }else{
81 10 return;
82 }
83 }
84  
85 ##
86 ## do we have a new river to swim into?
87 ##
88  
89 290 ▶ if (defined($river_target)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $river_target) { } 147 143 290
90  
91 147 $self->{location} = $river_target;
92 147 $self->{time_in_river} = 0;
93  
94 }else{
95  
96 # if there's nowhere to go,
97 # either spawn or print
98  
99 143 ▶ if ($self->{upstream}){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'upstream'}) { } 79 64 143
100 79 $self->spawn($node_to_pass);
101 }else{
102 64 $self->output();
103 }
104 }
105  
106 }
107  
108 84 ▶sub spawn {
Subroutine spawn: called CC=2 SCAR=6.9
Pod undocumented
109 84 my ($self, $spring) = @_;
110  
111 #print "spawning in river ".$self->{location}->{uid}." from node ".$spring->debug()."\n";
112  
113 84 ▶ my $value = ($spring->{spring})?$spring->{node_name}:'nameless';
Branch: 1 branch
BranchTrueFalseTotal
$spring->{'spring'} ? : 79 5 84
114 my $new_salmon = new Language::Homespring::Salmon({
115 'interp' => $self->{interp},
116 'value' => $value,
117 'upstream' => 0,
118 'mature' => 0,
119 'location' => $self->{location},
120 84 });
121 84 push @{$self->{interp}->{new_salmon}}, $new_salmon;
122 84 $self->{upstream} = 0;
123 84 $self->{mature} = 1;
124 }
125  
126 64 ▶sub output {
Subroutine output: called CC=1 SCAR=0.0
Pod undocumented
127 64 my ($self) = @_;
128 64 $self->{interp}->{output} .= $self->{value};
129 64 $self->kill();
130 }
131  
132 87 ▶sub kill {
Subroutine kill: called CC=1 SCAR=0.0
Pod undocumented
133 87 my ($self) = @_;
134 87 $self->{value} = 'DEAD';
135 87 push @{$self->{interp}->{dead_salmon}}, $_;
136 }
137  
138 0 ▶sub debug {
Subroutine debug: not called CC=3 SCAR=24.8
Pod undocumented
139 0 my ($self) = @_;
140  
141 return "salmon $self->{uid} in river ".$self->{location}->{uid}." ("
142 .(($self->{mature})?'mature':'young')
143 .") swimming "
144 0 ▶ .(($self->{upstream})?'upsteam':'downstream')
Branch: 2 branches
BranchTrueFalseTotal
$self->{'mature'} ? : 0 0 0
$self->{'upstream'} ? : 0 0 0
145 ."\n";
146  
147 }
148  
149 4 1;
150  
« Homespring/Visualise.pm ↑ Summary Homespring.pm »