| 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<m_to_n($i, 1, $i)>. | ||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||
| 24 | =back | ||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||
| 26 | =cut | ||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||
| 28 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 29 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||
| 31 | 10 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 32 | 10 | ▶ | use parent qw( Exporter ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 33 | 10 | our @EXPORT_OK = qw{ positive_int m_to_n }; | |||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||
| 36 | 3870 | ▶ | sub m_to_n { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
m_to_n: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 37 | 3870 | my ($i, $m, $n) = @_; | |||||||||||||||||||||||||||||||||||||
| 38 | defined && /^[0-9]+$/ | ||||||||||||||||||||||||||||||||||||||
| 39 | or croak +($_ // 'undef') . ' should be non negative integer' | ||||||||||||||||||||||||||||||||||||||
| 40 | 3870 | ▶ | for $i, $m, $n; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
defined $_ and /^[0-9]+$/
$_ // "undef"
MC/DC100%2/2
defined $_ and /^[0-9]+$/
defined $_
/^[0-9]+$/
MC/DC100%1/1
$_ // "undef"
$_
Truth table100%3/3
A and B
A= defined $_B= /^[0-9]+$/
Truth table100%2/2
A
A= $_
| |||||||||||||||||||||||||||||||||||||||
| 41 | 3866 | ▶ | $m <= $i && $i <= $n or croak "$i not between $m and $n"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$m <= $i and $i <= $n
MC/DC100%2/2
$m <= $i and $i <= $n
$m <= $i
$i <= $n
Truth table100%3/3
A and B
A= $m <= $iB= $i <= $n
| |||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||
| 45 | 240 | ▶ | sub positive_int { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
positive_int: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 46 | 240 | my $i = shift; | |||||||||||||||||||||||||||||||||||||
| 47 | 240 | m_to_n($i, 1, $i) | |||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||
| 51 | 10 | __PACKAGE__ | |||||||||||||||||||||||||||||||||||||