| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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'}
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'}
| |||||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | 26 | ▶ | return grep { $self->{lower} <= $_ && $_ <= $self->{upper} } @_; | ||||||||||||||||||
|
Condition100%3/3
$self->{'lower'} <= $_ && $_ <= $self->{'upper'}
MC/DC100%2/2
$self->{'lower'} <= $_ && $_ <= $self->{'upper'}
$self->{'lower'} <= $_
$_ <= $self->{'upper'}
Truth table100%3/3
A && B
A= $self->{'lower'} <= $_B= $_ <= $self->{'upper'}
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
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
| |||||||||||||||||||||
| 49 | } @_; | ||||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | 6 | ▶ | return grep { $_ < $self->{lower} || $self->{upper} < $_ } @_; | ||||||||||||||||||
|
Condition100%3/3
$_ < $self->{'lower'} || $self->{'upper'} < $_
MC/DC100%2/2
$_ < $self->{'lower'} || $self->{'upper'} < $_
$_ < $self->{'lower'}
$self->{'upper'} < $_
Truth table100%3/3
A || B
A= $_ < $self->{'lower'}B= $self->{'upper'} < $_
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 60 | 3 | ▶ | croak 'upper is infinit' if $self->upper == '+Inf'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 2 | return ($self->lower..$self->upper); | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 5 | 1; | |||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||