File Coverage

blib/lib/Karel/Util.pm
Criterion Covered Total %
statement 17 17 100.0
branch 2 2 100.0
condition 10 11 90.9
subroutine 6 6 100.0
pod 2 2 100.0
total 37 38 97.3


line stmt bran cond sub pod time code
1             package Karel::Util;
2              
3             =head1 NAME
4              
5             Karel::Util
6              
7             =head1 DESCRITPTION
8              
9             Helper functions for other packages.
10              
11             =head1 FUNCTIONS
12              
13             =over 4
14              
15             =item m_to_n($i, $m, $n)
16              
17             Checks whether the integer C<$i> lies between C<$m> and C<$n>
18             inclusive.
19              
20             =item positive_int($i)
21              
22             Checks whether C<$i> is a positive integer, i.e. C.
23              
24             =back
25              
26             =cut
27              
28 9     9   82231 use warnings;
  9         11  
  9         215  
29 9     9   24 use strict;
  9         12  
  9         121  
30              
31 9     9   26 use Carp;
  9         14  
  9         433  
32 9     9   431 use parent qw( Exporter );
  9         278  
  9         51  
33             our @EXPORT_OK = qw{ positive_int m_to_n };
34              
35              
36             sub m_to_n {
37 3806     3806 1 8601 my ($i, $m, $n) = @_;
38             defined && /^[0-9]+$/
39             or croak +($_ // 'undef') . ' should be non negative integer'
40 3806   100     31871 for $i, $m, $n;
      100        
      66        
41 3802 100 100     14022 $m <= $i && $i <= $n or croak "$i not between $m and $n";
42             }
43              
44              
45             sub positive_int {
46 236     236 1 51984 my $i = shift;
47 236         348 m_to_n($i, 1, $i)
48             }
49              
50              
51             __PACKAGE__