FishFarm/WaterLevelMaintainer.pm

filter: Statementstmt 100% 41 / 41 Branchbran 58.3% 14 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 100% 8 / 8 totaltotal 88.2% 75 / 85 CC 13 SCAR 9.0
CC
13
Cov
85%
install
4.1
current_water_level
3.0
is_low_water_level
3.0
CRAP 2.5
« FishFarm.pm ↑ Summary FishFarm/OxygenMaintainer.pm »
1 package Acme::FishFarm::WaterLevelMaintainer;
2  
3 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Carp "croak";
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Acme::FishFarm::WaterLevelMaintainer - Water Level Maintainer for Acme::FishFarm
11  
12 =head1 VERSION
13  
14 Version 1.01
15  
16 =cut
17  
18 3 our $VERSION = '1.01';
19  
20  
21 =head1 SYNOPSIS
22  
23 use 5.010;
24  
25 use Acme::FishFarm qw( reduce_precision );
26 use Acme::FishFarm::WaterFiltration;
27  
28 my $water_level = Acme::FishFarm::WaterLevelMaintainer->install;
29  
30 say "Water level maintainer installed and switched on!\n";
31  
32 my $height_increase;
33 my $water_level_threshold;
34 my $current_reading;
35  
36 while ( "Fish are living under the water..." ) {
37  
38 $current_reading = reduce_precision( rand(10) );
39 $height_increase = $water_level->water_level_increase_height;
40 $water_level_threshold = $water_level->low_water_level_threshold;
41
42 $water_level->current_water_level( $current_reading ); # input by user
43 print "Current Water Level: ", $current_reading, " m (low: < ", $water_level_threshold, " m)\n";
44  
45 if ( $water_level->is_low_water_level ) {
46 print " !! Water level is low!\n";
47 $water_level->pump_water_in;
48 print " Pumping in ", $height_increase, " m of water...\n";
49 print "Current Water Level: ", $water_level->current_water_level, "\n";
50 } else {
51 print " Water level is still normal.\n";
52 }
53
54 sleep(1);
55 say "";
56 }
57  
58 =head1 EXPORT
59  
60 None
61  
62 =head1 CREATION RELATED MEHODS
63  
64 =head2 install ( %options )
65  
66 Installs a water level maintainer system. This system only pumps water in if the water level is lower than the threshold value.
67  
68 The supported C<%options> are:
69  
70 =over 4
71  
72 =item current_water_level
73  
74 The default water level is to C<5 unit>.
75  
76 =item low_water_level_threshold
77  
78 The default threshold is C<2 unit>.
79  
80 If the current water level is lower than this threshold, then you need to pump water into the tank.
81  
82 =item increase_water_level_by
83  
84 This is the height of the water level to increase when the water is pumped in.
85  
86 The default value is C<0.5 unit>.
87  
88 =back
89  
90 =cut
91  
92 2 ▶sub install {
Subroutine install: called CC=4 SCAR=14.1
Pod documented
93 2 my $class = shift;
94 2 my %options = @_;
95
96 2 ▶ if ( not $options{current_water_level} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($options{"current_water_level"}) 2 0 2
97 2 $options{current_water_level} = 5;
98 }
99
100 2 ▶ if ( not $options{low_water_level_threshold} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($options{"low_water_level_threshold"}) 2 0 2
101 2 $options{low_water_level_threshold} = 2;
102 }
103
104 2 ▶ if ( not $options{increase_water_level_by} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($options{"increase_water_level_by"}) 2 0 2
105 2 $options{increase_water_level_by} = 0.5;
106 }
107
108 2 $options{is_low_water_level} = 0; # might be useless :)
109
110 2 bless \%options, "Acme::FishFarm::WaterLevelMaintainer";
111 }
112  
113 =head1 WATER LEVEL DETECTION RELATED METHODS
114  
115 =head2 current_water_level ( $new_water_level )
116  
117 Sets / returns the current water level of the water.
118  
119 C<$new_water_level> is optional. If present, the current water level will be set to C<$new_water_level>. Otherwise, returns the current water level (depth).
120  
121 =cut
122  
123 7 ▶sub current_water_level {
Subroutine current_water_level: called CC=3 SCAR=11.0
Pod documented
124 7 ▶ ref( my $self = shift ) or croak "Please use this the OO way";
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or croak("Please use this the OO way") 7 0 7
125 7 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 3 4 7
126 3 $self->{current_water_level} = shift;
127 } else {
128 4 $self->{current_water_level};
129 }
130 }
131  
132 =head2 low_water_level_threshold
133  
134 Returns the low water level threshold.
135  
136 =cut
137  
138 3 ▶sub low_water_level_threshold {
Subroutine low_water_level_threshold: called CC=2 SCAR=7.2
Pod documented
139 3 ▶ ref( my $self = shift ) or croak "Please use this the OO way";
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or croak("Please use this the OO way") 3 0 3
140 3 $self->{low_water_level_threshold};
141 }
142  
143 =head2 set_low_water_level_threshold ( $new_threshold )
144  
145 Sets the low water level threshold.
146  
147 =cut
148  
149 1 ▶sub set_low_water_level_threshold {
Subroutine set_low_water_level_threshold: called CC=2 SCAR=7.2
Pod documented
150 1 ▶ ref( my $self = shift ) or croak "Please use this the OO way";
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or croak("Please use this the OO way") 1 0 1
151 1 $self->{low_water_level_threshold} = shift;
152 }
153  
154 =head2 is_low_water_level
155  
156 Returns C<1> if the DO level is less than the threshold value. Otherwise, returns C<0>.
157  
158 =cut
159  
160 3 ▶sub is_low_water_level {
Subroutine is_low_water_level: called CC=3 SCAR=11.0
Pod documented
161 3 ▶ ref( my $self = shift ) or croak "Please use this the OO way";
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or croak("Please use this the OO way") 3 0 3
162 3 ▶ if ( $self->{current_water_level} < $self->{low_water_level_threshold} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'current_water_level'} < $self->{'low_water_level_threshold'}) { } 2 1 3
163 2 return 1;
164 } else {
165 1 return 0;
166 }
167 }
168  
169 =head1 PUMPS RELATED METHODS
170  
171 For the pumping mechanism, just assume that the pumps can actually pump in certain metres of water each time :)
172  
173 =head2 water_level_increase_height
174  
175 Returns the height of water level to increase each water pumping action. See C<pump_water_in> below.
176  
177 =cut
178  
179 3 ▶sub water_level_increase_height {
Subroutine water_level_increase_height: called CC=2 SCAR=7.2
Pod documented
180 3 ▶ ref( my $self = shift ) or croak "Please use this the OO way";
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or croak("Please use this the OO way") 3 0 3
181 3 $self->{increase_water_level_by};
182 }
183  
184 =head2 set_water_level_increase_height ( $new_height )
185  
186 Sets the height of water level to increase to C<$new_height>.
187  
188 =cut
189  
190 1 ▶sub set_water_level_increase_height {
Subroutine set_water_level_increase_height: called CC=2 SCAR=7.2
Pod documented
191 1 ▶ ref( my $self = shift ) or croak "Please use this the OO way";
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or croak("Please use this the OO way") 1 0 1
192 1 $self->{increase_water_level_by} = shift;
193 }
194  
195 =head2 pump_water_in
196  
197 Pumps water into the tank to increase the height of the water level.
198  
199 =cut
200  
201 2 ▶sub pump_water_in {
Subroutine pump_water_in: called CC=2 SCAR=7.2
Pod documented
202 2 ▶ ref( my $self = shift ) or croak "Please use this the OO way";
Branch: 1 branch
BranchTrueFalseTotal
ref(my $self = shift()) or croak("Please use this the OO way") 2 0 2
203 2 $self->{current_water_level} += $self->{increase_water_level_by};
204 }
205  
206 =head1 AUTHOR
207  
208 Raphael Jong Jun Jie, C<< <ellednera at cpan.org> >>
209  
210 =head1 BUGS
211  
212 Please report any bugs or feature requests to C<bug-. at rt.cpan.org>, or through
213 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=.>. I will be notified, and then you'll
214 automatically be notified of progress on your bug as I make changes.
215  
216  
217  
218  
219 =head1 SUPPORT
220  
221 You can find documentation for this module with the perldoc command.
222  
223 perldoc Acme::FishFarm::WaterLevelMaintainer
224  
225  
226 You can also look for information at:
227  
228 =over 4
229  
230 =item * RT: CPAN's request tracker (report bugs here)
231  
232 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=.>
233  
234 =item * CPAN Ratings
235  
236 L<https://cpanratings.perl.org/d/.>
237  
238 =item * Search CPAN
239  
240 L<https://metacpan.org/release/.>
241  
242 =back
243  
244  
245 =head1 ACKNOWLEDGEMENTS
246  
247 Besiyata d'shmaya
248  
249 =head1 LICENSE AND COPYRIGHT
250  
251 This software is Copyright (c) 2021 by Raphael Jong Jun Jie.
252  
253 This is free software, licensed under:
254  
255 The Artistic License 2.0 (GPL Compatible)
256  
257  
258 =cut
259  
260 3 1; # End of Acme::FishFarm::WaterLevelMaintainer
« FishFarm.pm ↑ Summary FishFarm/OxygenMaintainer.pm »