line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Acme::FishFarm::OxygenMaintainer; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
71303
|
use 5.006; |
|
4
|
|
|
|
|
28
|
|
4
|
4
|
|
|
4
|
|
22
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
95
|
|
5
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
146
|
|
6
|
4
|
|
|
4
|
|
26
|
use Carp "croak"; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
2111
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Acme::FishFarm::OxygenMaintainer - Oxygen Maintainer for Acme::FishFarm |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 1.01 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '1.01'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use 5.010; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use Acme::FishFarm qw(consume_oxygen reduce_precision); |
26
|
|
|
|
|
|
|
use Acme::FishFarm::OxygenMaintainer; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $oxygen = Acme::FishFarm::OxygenMaintainer->install( DO_generation_volume => 3 ); |
29
|
|
|
|
|
|
|
say "Oxygen maintainer installed!\n"; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
while ( "fish are using up oxygen" ) { |
33
|
|
|
|
|
|
|
say "Current Oxygen Level: ", $oxygen->current_DO, " mg/L", |
34
|
|
|
|
|
|
|
" (low: < ", $oxygen->DO_threshold, ")"; |
35
|
|
|
|
|
|
|
#say "Low Oxygen Level: ", $oxygen->DO_threshold, " mg/L"; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
if ( $oxygen->is_low_DO ) { |
38
|
|
|
|
|
|
|
say "Fish status: Suffocating"; |
39
|
|
|
|
|
|
|
say " !! Low oxygen level!"; |
40
|
|
|
|
|
|
|
say "Pumping ", $oxygen->oxygen_generation_volume, " mg/L of oxygen into the water..." ; |
41
|
|
|
|
|
|
|
$oxygen->generate_oxygen; |
42
|
|
|
|
|
|
|
} else { |
43
|
|
|
|
|
|
|
say "Fish status: Happy"; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
consume_oxygen( $oxygen, rand(2.5) ); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sleep(3); |
49
|
|
|
|
|
|
|
say ""; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 EXPORT |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
None |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 CREATION RELATED SUBROUTINES/METHODS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 install ( %options ) |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Installs an oxygen maintainer system. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
The supported C<%options> are: |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=over 4 |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item current_DO |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
The default DO is to C<8 mg/L>. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item DO_threshold |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
The default threshold is C<5 mg/L>. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
If the current DO level is lower than this threshold, then your fish is lacking oxygen. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item DO_generation_volume |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
This is the rate of oxygen generation. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
The default value is C<0.2 mg/L per unit time> |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=back |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
The unit C is just a unit, it doesn't show up if you call any of it's related getters. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub install { |
89
|
5
|
|
|
5
|
1
|
100
|
my $class = shift; |
90
|
5
|
|
|
|
|
18
|
my %options = @_; |
91
|
|
|
|
|
|
|
|
92
|
5
|
100
|
|
|
|
16
|
if ( not $options{current_DO} ) { |
93
|
2
|
|
|
|
|
6
|
$options{current_DO} = 8; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
5
|
100
|
|
|
|
16
|
if ( not $options{DO_threshold} ) { |
97
|
4
|
|
|
|
|
10
|
$options{DO_threshold} = 5; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
5
|
50
|
|
|
|
15
|
if ( not $options{DO_generation_volume} ) { |
101
|
5
|
|
|
|
|
11
|
$options{DO_generation_volume} = 0.2; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
5
|
|
|
|
|
11
|
$options{is_DO_low} = 0; # might be useless :) |
105
|
|
|
|
|
|
|
|
106
|
5
|
|
|
|
|
17
|
bless \%options, "Acme::FishFarm::OxygenMaintainer"; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 DISSOLVED OXYGEN SENSOR RELATED METHODS |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 current_DO ( $new_DO ) |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Sets / returns the current DO level of the water. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
C<$new_DO> is optional. If present, the current DO will be set to C<$new_DO>. Otherwise, returns the current DO reading. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub current_DO { |
121
|
13
|
50
|
|
13
|
1
|
735
|
ref( my $self = shift ) or croak "Please use this the OO way"; |
122
|
13
|
100
|
|
|
|
36
|
if ( @_ ) { |
123
|
6
|
|
|
|
|
16
|
$self->{current_DO} = shift; |
124
|
|
|
|
|
|
|
} else { |
125
|
7
|
|
|
|
|
39
|
$self->{current_DO}; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 DO_threshold |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Returns the DO threshold. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub DO_threshold { |
137
|
5
|
50
|
|
5
|
1
|
18
|
ref( my $self = shift ) or croak "Please use this the OO way"; |
138
|
5
|
|
|
|
|
19
|
$self->{DO_threshold}; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 set_DO_threshold ( $new_DO_threshold ) |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Sets the DO threshold. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub set_DO_threshold { |
148
|
2
|
50
|
|
2
|
1
|
10
|
ref( my $self = shift ) or croak "Please use this the OO way"; |
149
|
2
|
|
|
|
|
11
|
my $new_do_threshold = shift; |
150
|
2
|
|
|
|
|
8
|
$self->{DO_threshold} = $new_do_threshold; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 is_low_DO |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Returns C<1> if the DO level is less than the threshold value. Otherwise, returns C<0>. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub is_low_DO { |
160
|
10
|
50
|
|
10
|
1
|
37
|
ref( my $self = shift ) or croak "Please use this the OO way"; |
161
|
10
|
100
|
|
|
|
36
|
if ( $self->{current_DO} < $self->{DO_threshold} ) { |
162
|
5
|
|
|
|
|
18
|
return 1; |
163
|
|
|
|
|
|
|
} else { |
164
|
5
|
|
|
|
|
21
|
return 0; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 OXYGEN GENERATING RELATED METHODS |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 oxygen_generation_volume |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Returns the oxygen generation rate. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub oxygen_generation_volume { |
178
|
3
|
50
|
|
3
|
1
|
10
|
ref( my $self = shift ) or croak "Please use this the OO way"; |
179
|
3
|
|
|
|
|
12
|
$self->{DO_generation_volume}; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head2 set_oxygen_generation_volume ( $new_rate ) |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Sets the new oxygen generation rate to C<$new_rate>. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=cut |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub set_oxygen_generation_volume { |
189
|
1
|
50
|
|
1
|
1
|
5
|
ref( my $self = shift ) or croak "Please use this the OO way"; |
190
|
1
|
|
|
|
|
2
|
$self->{DO_generation_volume} = shift; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head2 generate_oxygen |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Pumps oxygen into the water based on the diffusion rate. The current DO value will increase every time this action is invoked. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Take note that this will generate oxygen no matter what. Make sure you check the DO content before pumping oxygen into your tank. See C method above for more info. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub generate_oxygen { |
202
|
2
|
50
|
|
2
|
1
|
10
|
ref( my $self = shift ) or croak "Please use this the OO way"; |
203
|
2
|
|
|
|
|
7
|
$self->{current_DO} += $self->{DO_generation_volume}; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 AUTHOR |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Raphael Jong Jun Jie, C<< >> |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head1 BUGS |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
213
|
|
|
|
|
|
|
the web interface at L. 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::OxygenMaintainer |
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 |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=item * CPAN Ratings |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
L |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=item * Search CPAN |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
L |
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
|
|
|
|
|
|
|
1; # End of Acme::FishFarm::OxygenMaintainer |