| 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'
MC/DC100%1/1
$options->{'value'} || 'homeless'
$options->{'value'}
Truth table100%2/2
A
A= $options->{'value'}
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 187 | ▶ | $self->{upstream} = $options->{upstream} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options->{'upstream'} || 0
MC/DC100%1/1
$options->{'upstream'} || 0
$options->{'upstream'}
Truth table100%2/2
A
A= $options->{'upstream'}
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 187 | ▶ | $self->{mature} = $options->{mature} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$options->{'mature'} || 0
MC/DC100%1/1
$options->{'mature'} || 0
$options->{'mature'}
Truth table100%2/2
A
A= $options->{'mature'}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 90 | $node_to_pass = $self->{location}->{up_node}; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 90 | $river_target = undef; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 90 | ▶ | if ($node_to_pass){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 90 | my $count = scalar(@{$node_to_pass->{rivers_up}}); | |||||||||||||||||||||||||||||||||||||||||
| 37 | 90 | ▶ | if ($count){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
$node_to_pass->{"node_name"} eq "shallows" and $self->{"mature"} and $self->{"time_in_river"} == 1
$node_to_pass->{"node_name"} eq "shallows" and $self->{"mature"}
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
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 335 | ▶ | return if (($node_to_pass->{node_name} eq 'rapids') && (!$self->{mature}) && ($self->{time_in_river} == 1)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$node_to_pass->{"node_name"} eq "rapids" and not $self->{"mature"} and $self->{"time_in_river"} == 1
$node_to_pass->{"node_name"} eq "rapids" and not $self->{"mature"}
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
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 332 | ▶ | return if (($node_to_pass->{node_name} eq 'net') && ($self->{mature})); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$node_to_pass->{"node_name"} eq "net" and $self->{"mature"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 326 | ▶ | return if (($node_to_pass->{node_name} eq 'current') && (!$self->{mature})); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$node_to_pass->{"node_name"} eq "current" and not $self->{"mature"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 323 | ▶ | if (($node_to_pass->{node_name} eq 'bear') && ($self->{mature})){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$node_to_pass->{"node_name"} eq "bear" and $self->{"mature"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$node_to_pass->{"node_name"} eq "young bear" and $self->{"mature"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 4 | ▶ | if ($node_to_pass->every_other()){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$node_to_pass->{"node_name"} eq "bird" and not $self->{"mature"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$node_to_pass->{"node_name"} eq "force field" and $node_to_pass->{"power"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 15 | ▶ | if ($self->{upstream}){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | ."\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||