| 1 | package Acme::Hospital::Bed; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use 5.006; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | our $VERSION = '0.06'; | |||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | sub new { | ||||||||||||||||||||
| 9 | 1 | ▶ | my ($package, %args) = @_; | ||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=21.1
Pod
documented
| |||||||||||||||||||||
| 10 | 1 | ▶ | $args{total_num_of_rooms} ||= 20; | ||||||||||||||||||
|
Condition50%1/2
$args{"total_num_of_rooms"} ||= 20
MC/DC0%0/1
$args{"total_num_of_rooms"} ||= 20
$args{"total_num_of_rooms"}
Truth table50%1/2
A
A= $args{"total_num_of_rooms"}
| |||||||||||||||||||||
| 11 | 1 | ▶ | $args{lifes} ||= 3; | ||||||||||||||||||
|
Condition50%1/2
$args{"lifes"} ||= 3
MC/DC0%0/1
$args{"lifes"} ||= 3
$args{"lifes"}
Truth table50%1/2
A
A= $args{"lifes"}
| |||||||||||||||||||||
| 12 | 1 | ▶ | $args{rooms} ||= []; | ||||||||||||||||||
|
Condition50%1/2
$args{"rooms"} ||= []
MC/DC0%0/1
$args{"rooms"} ||= []
$args{"rooms"}
Truth table50%1/2
A
A= $args{"rooms"}
| |||||||||||||||||||||
| 13 | 1 | ▶ | $args{max_length_of_stay} ||= $args{total_num_of_rooms}*2; | ||||||||||||||||||
|
Condition33%1/3
$args{"max_length_of_stay"} ||= $args{"total_num_of_rooms"} * 2
MC/DC0%0/2
$args{"max_length_of_stay"} ||= $args{"total_num_of_rooms"} * 2
$args{"max_length_of_stay"}
$args{"total_num_of_rooms"} * 2
Truth table33%1/3
A ||= B
A= $args{"max_length_of_stay"}B= $args{"total_num_of_rooms"} * 2
| |||||||||||||||||||||
| 14 | 1 | my $self = bless \%args, $package; | |||||||||||||||||||
| 15 | 1 | ▶ | unless ($self->{names}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 16 | $self->{names} = [ | ||||||||||||||||||||
| 17 | 1 | qw/rob robert ben tom dean dennis ruby roxy jane michelle larry liane leanne anne axel/ | |||||||||||||||||||
| 18 | ]; | ||||||||||||||||||||
| 19 | } | ||||||||||||||||||||
| 20 | 1 | ▶ | unless ($self->{phrases}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | $self->{phrases} = [ | ||||||||||||||||||||
| 22 | [ | ||||||||||||||||||||
| 23 | 1 | "Hello, I am fine.", | |||||||||||||||||||
| 24 | "I still have my mind.", | ||||||||||||||||||||
| 25 | ], | ||||||||||||||||||||
| 26 | [ | ||||||||||||||||||||
| 27 | "Hello, I am still fine.", | ||||||||||||||||||||
| 28 | "I still have my mind." | ||||||||||||||||||||
| 29 | ], | ||||||||||||||||||||
| 30 | [ | ||||||||||||||||||||
| 31 | "Hello, I am also fine.", | ||||||||||||||||||||
| 32 | "I still have my mind." | ||||||||||||||||||||
| 33 | ], | ||||||||||||||||||||
| 34 | [ | ||||||||||||||||||||
| 35 | "Hello, I think I'm still fine.", | ||||||||||||||||||||
| 36 | "I still have my mind." | ||||||||||||||||||||
| 37 | ], | ||||||||||||||||||||
| 38 | [ | ||||||||||||||||||||
| 39 | "Hello, I think you think I'm fine.", | ||||||||||||||||||||
| 40 | "I still have my mind." | ||||||||||||||||||||
| 41 | ], | ||||||||||||||||||||
| 42 | [ | ||||||||||||||||||||
| 43 | "Hello, am I still fine.", | ||||||||||||||||||||
| 44 | "Where is my mind?", | ||||||||||||||||||||
| 45 | ], | ||||||||||||||||||||
| 46 | [ | ||||||||||||||||||||
| 47 | "Hello, do you still think I'm fine.", | ||||||||||||||||||||
| 48 | "Where is my mind?", | ||||||||||||||||||||
| 49 | ], | ||||||||||||||||||||
| 50 | [ | ||||||||||||||||||||
| 51 | "Hello, I don't feel so fine.", | ||||||||||||||||||||
| 52 | "Where is my mind?", | ||||||||||||||||||||
| 53 | ], | ||||||||||||||||||||
| 54 | [ | ||||||||||||||||||||
| 55 | "Hello, This is not fine.", | ||||||||||||||||||||
| 56 | "Where is my mind?", | ||||||||||||||||||||
| 57 | ], | ||||||||||||||||||||
| 58 | [ | ||||||||||||||||||||
| 59 | "Hello, I'm not fine.", | ||||||||||||||||||||
| 60 | "Waiting every 5 minutes...?", | ||||||||||||||||||||
| 61 | ] | ||||||||||||||||||||
| 62 | ]; | ||||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | 1 | return $self; | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | sub start { | ||||||||||||||||||||
| 68 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
start: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 69 | 0 | ▶ | unless (ref $self) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | 0 | $self = __PACKAGE__->new; | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | 0 | $self->next_patient; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | sub available_rooms { | ||||||||||||||||||||
| 76 | 38 | ▶ | return $_[0]->{total_num_of_rooms} - scalar @{$_[0]->{rooms}}; | ||||||||||||||||||
|
Subroutine
available_rooms: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | sub next_patient { | ||||||||||||||||||||
| 80 | 19 | ▶ | $_[0]->check_patients_out; | ||||||||||||||||||
|
Subroutine
next_patient: called CC=6 SCAR=19.9
Pod
documented
| |||||||||||||||||||||
| 81 | 19 | my $available = $_[0]->available_rooms; | |||||||||||||||||||
| 82 | 19 | ▶ | if ($available == 0) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | 0 | say('You won this time.'); | |||||||||||||||||||
| 84 | 0 | exit; | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | 19 | my %patient = $_[0]->_generate_patient(); | |||||||||||||||||||
| 87 | 19 | my @phrases = @{ $_[0]->{phrases}->[$patient{level}] }; | |||||||||||||||||||
| 88 | 19 | my $phrase = $phrases[int(rand(@phrases))]; | |||||||||||||||||||
| 89 | 19 | say(sprintf 'You have %s available rooms', $_[0]->available_rooms); | |||||||||||||||||||
| 90 | 19 | say( sprintf('The next patients name is: %s. The patient will stay for: %s days.', $patient{name}, $patient{length})); | |||||||||||||||||||
| 91 | 19 | say($phrase); | |||||||||||||||||||
| 92 | 19 | my $ans = _wait_answer(); | |||||||||||||||||||
| 93 | 19 | ▶ | if ($ans eq 'y') { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 94 | $patient{level} < 6 ? do { | ||||||||||||||||||||
| 95 | 0 | $_[0]->_lose_a_life(); | |||||||||||||||||||
| 96 | 19 | ▶ | } : do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | 19 | push @{$_[0]->{rooms}}, \%patient; | |||||||||||||||||||
| 98 | }; | ||||||||||||||||||||
| 99 | } elsif ($patient{level} > 5) { | ||||||||||||||||||||
| 100 | 0 | $_[0]->_lose_a_life(); | |||||||||||||||||||
| 101 | } | ||||||||||||||||||||
| 102 | 19 | ▶ | $_[0]->next_patient() unless $_[1]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | sub check_patients_out { | ||||||||||||||||||||
| 106 | 19 | ▶ | my $i = 0; | ||||||||||||||||||
|
Subroutine
check_patients_out: called CC=3 SCAR=12.3
Pod
documented
| |||||||||||||||||||||
| 107 | 19 | for (@{$_[0]->{rooms}}) { | |||||||||||||||||||
| 108 | 171 | $_->{length}--; | |||||||||||||||||||
| 109 | 171 | ▶ | if ($_->{length} == 0) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 110 | 0 | splice @{$_[0]->{rooms}}, $i, 1; | |||||||||||||||||||
| 111 | 0 | say('Patient checked out: ' . $_->{name}); | |||||||||||||||||||
| 112 | } | ||||||||||||||||||||
| 113 | 171 | $i++; | |||||||||||||||||||
| 114 | } | ||||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | sub _lose_a_life { | ||||||||||||||||||||
| 118 | 0 | ▶ | if ($_[0]->{lifes}-- == 0) { | ||||||||||||||||||
|
Subroutine
_lose_a_life: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||
| 119 | 0 | say('GAME OVER!'); | |||||||||||||||||||
| 120 | 0 | exit; | |||||||||||||||||||
| 121 | } | ||||||||||||||||||||
| 122 | 0 | say(sprintf 'You lose a life, %s lifes remaining.', $_[0]->{lifes}); | |||||||||||||||||||
| 123 | } | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | sub _wait_answer { | ||||||||||||||||||||
| 126 | 0 | ▶ | say('Should they go to hospital? (y/n) '); | ||||||||||||||||||
|
Subroutine
_wait_answer: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 127 | 0 | my $answer = <STDIN>; | |||||||||||||||||||
| 128 | 0 | chomp $answer; | |||||||||||||||||||
| 129 | 0 | ▶ | if ($answer !~ m/y|n/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 130 | 0 | return _wait_answer(); | |||||||||||||||||||
| 131 | } | ||||||||||||||||||||
| 132 | 0 | return $answer; | |||||||||||||||||||
| 133 | } | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | sub _generate_patient { | ||||||||||||||||||||
| 136 | 0 | ▶ | my @names = @{$_[0]->{names}}; | ||||||||||||||||||
|
Subroutine
_generate_patient: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 137 | return ( | ||||||||||||||||||||
| 138 | 0 | ▶ | name => sprintf('%s %s', map { $names[int(rand(@names))] } 0 .. 1), | ||||||||||||||||||
|
Condition0%0/2
int rand $_[0]{'max_length_of_stay'} || 1
MC/DC0%0/1
int rand $_[0]{'max_length_of_stay'} || 1
int rand $_[0]{'max_length_of_stay'}
Truth table0%0/2
A
A= int rand $_[0]{'max_length_of_stay'}
| |||||||||||||||||||||
| 139 | level => int(rand(10)), | ||||||||||||||||||||
| 140 | 0 | length => int(rand($_[0]->{max_length_of_stay})) || 1 | |||||||||||||||||||
| 141 | ); | ||||||||||||||||||||
| 142 | } | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | sub say { | ||||||||||||||||||||
| 145 | 57 | ▶ | print $_[0] . "\n"; | ||||||||||||||||||
|
Subroutine
say: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 146 | } | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | 2 | 1; | |||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | __END__ | ||||||||||||||||||||