Range.pm

filter: Statementstmt 100% 47 / 47 Branchbran 100% 10 / 10 Conditioncond 83.3% 10 / 12 MC/DCmcdc 75.0% 6 / 8 Subroutinesub 100% 12 / 12 Podpod 80.0% 4 / 5 totaltotal 94.6% 89 / 94 CC 10 SCAR 9.3
CC
10
Cov
97%
includes
4.0
excludes
4.0
all
3.0
CRAP 2.5
« Range/Search/Binary.pm ↑ Summary Range/Search/Liner.pm »
1 package List::Range;
2 5 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 our $VERSION = "0.02";
7  
8 5 ▶use Class::Accessor::Lite ro => [qw/name lower upper/];
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use overload '@{}' => sub { [shift->all] },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
10 5 fallback => 1;
11  
12 5 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 28 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
15 28 my ($class, %args) = @_;
16 28 my $self = bless {
17 lower => '-Inf',
18 upper => '+Inf',
19 name => '',
20 %args,
21 } => $class;
22 $self->{lower} <= $self->{upper}
23 28 ▶ or croak "Cannot make a range by $self->{lower}..$self->{upper}";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"lower"} <= $self->{"upper"} or croak(qq[Cannot make a range by $self->{"lower"}..$self->{"upper"}]) 27 1 28
24 27 return $self;
25 }
26  
27 32 ▶sub includes {
Subroutine includes: called CC=4 SCAR=13.9
Pod documented
28 32 my $self = shift;
29 32 ▶ if (ref $_[0] eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq "CODE") 6 26 32
30 6 my $code = shift;
31  
32 6 my $tmp; # for preformance
33 return grep {
34 6 $tmp = $code->($_);
35 $self->{lower} <= $tmp && $tmp <= $self->{upper}
36 17 ▶ } @_;
Condition66%2/3
$self->{'lower'} <= $tmp && $tmp <= $self->{'upper'}
!ll&&!rl&&r
0413
MC/DC50%1/2
$self->{'lower'} <= $tmp && $tmp <= $self->{'upper'}
$self->{'lower'} <= $tmp $tmp <= $self->{'upper'}
Truth table66%2/3
A && B
A= $self->{'lower'} <= $tmpB= $tmp <= $self->{'upper'}
ABresult
0X0
100
111
37 }
38 26 ▶ return grep { $self->{lower} <= $_ && $_ <= $self->{upper} } @_;
Condition100%3/3
$self->{'lower'} <= $_ && $_ <= $self->{'upper'}
!ll&&!rl&&r
31519
MC/DC100%2/2
$self->{'lower'} <= $_ && $_ <= $self->{'upper'}
$self->{'lower'} <= $_ $_ <= $self->{'upper'}
Truth table100%3/3
A && B
A= $self->{'lower'} <= $_B= $_ <= $self->{'upper'}
ABresult
0X0
100
111
39 }
40  
41 12 ▶sub excludes {
Subroutine excludes: called CC=4 SCAR=13.9
Pod documented
42 12 my $self = shift;
43 12 ▶ if (ref $_[0] eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq "CODE") 6 6 12
44 6 my $code = shift;
45 6 my $tmp; # for preformance
46 return grep {
47 6 $tmp = $code->($_);
48 17 ▶ $tmp < $self->{lower} || $self->{upper} < $tmp
Condition66%2/3
$tmp < $self->{'lower'} || $self->{'upper'} < $tmp
l!l&&r!l&&!r
0413
MC/DC50%1/2
$tmp < $self->{'lower'} || $self->{'upper'} < $tmp
$tmp < $self->{'lower'} $self->{'upper'} < $tmp
Truth table66%2/3
A || B
A= $tmp < $self->{'lower'}B= $self->{'upper'} < $tmp
ABresult
1X1
011
000
49 } @_;
50 }
51 6 ▶ return grep { $_ < $self->{lower} || $self->{upper} < $_ } @_;
Condition100%3/3
$_ < $self->{'lower'} || $self->{'upper'} < $_
l!l&&r!l&&!r
2213
MC/DC100%2/2
$_ < $self->{'lower'} || $self->{'upper'} < $_
$_ < $self->{'lower'} $self->{'upper'} < $_
Truth table100%3/3
A || B
A= $_ < $self->{'lower'}B= $self->{'upper'} < $_
ABresult
1X1
011
000
52 }
53  
54 # for duck typing
55 1 ▶sub ranges { [shift] }
Subroutine ranges: called CC=1 SCAR=0.0
Pod undocumented
56  
57 4 ▶sub all {
Subroutine all: called CC=3 SCAR=11.0
Pod documented
58 4 my $self = shift;
59 4 ▶ croak 'lower is infinit' if $self->lower == '-Inf';
Branch: 1 branch
BranchTrueFalseTotal
if $self->lower == "-Inf" 1 3 4
60 3 ▶ croak 'upper is infinit' if $self->upper == '+Inf';
Branch: 1 branch
BranchTrueFalseTotal
if $self->upper == "+Inf" 1 2 3
61 2 return ($self->lower..$self->upper);
62 }
63  
64 5 1;
65 __END__
« Range/Search/Binary.pm ↑ Summary Range/Search/Liner.pm »