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   73012 use warnings;
  9         10  
  9         217  
29 9     9   24 use strict;
  9         9  
  9         113  
30              
31 9     9   24 use Carp;
  9         17  
  9         416  
32 9     9   400 use parent qw( Exporter );
  9         265  
  9         49  
33             our @EXPORT_OK = qw{ positive_int m_to_n };
34              
35              
36             sub m_to_n {
37 3806     3806 1 7830 my ($i, $m, $n) = @_;
38             defined && /^[0-9]+$/
39             or croak +($_ // 'undef') . ' should be non negative integer'
40 3806   100     32014 for $i, $m, $n;
      100        
      66        
41 3802 100 100     14078 $m <= $i && $i <= $n or croak "$i not between $m and $n";
42             }
43              
44              
45             sub positive_int {
46 236     236 1 50600 my $i = shift;
47 236         344 m_to_n($i, 1, $i)
48             }
49              
50              
51             __PACKAGE__