| 1 | package List::Haystack; | ||||||||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||
| 7 | 4 | our $VERSION = "0.01"; | |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | 16 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 10 | 16 | my ($class, $list, $options) = @_; | |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | 16 | ▶ | if (not defined $list) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 13 | 3 | $list = []; | |||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | 16 | ▶ | if (ref $list ne 'ARRAY') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 17 | 1 | croak 'Type of given argument `$list` is not suitable. It must be array reference.'; | |||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | 15 | my $self = bless { | |||||||||||||||||||||||||||||||||
| 21 | list => $list, | ||||||||||||||||||||||||||||||||||
| 22 | }, $class; | ||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | 15 | ▶ | my $lazy = defined $options && ref($options) eq 'HASH' && $options->{lazy}; | ||||||||||||||||||||||||||||||||
|
Condition66%4/6
defined $options && ref $options eq 'HASH' && $options->{'lazy'}
defined $options and ref $options eq "HASH"
MC/DC33%1/3
defined $options && ref $options eq 'HASH' && $options->{'lazy'}
defined $options
ref $options eq "HASH"
$options->{'lazy'}
Truth table50%2/4
A and B && C
A= defined $optionsB= ref $options eq "HASH"C= $options->{'lazy'}
| |||||||||||||||||||||||||||||||||||
| 25 | 15 | ▶ | if (not $lazy) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 26 | 8 | $self->_construct_haystack; | |||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | 15 | return $self; | |||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | 16 | ▶ | sub haystack { | ||||||||||||||||||||||||||||||||
|
Subroutine
haystack: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 33 | 16 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||
| 35 | 16 | my $haystack = $self->{haystack}; | |||||||||||||||||||||||||||||||||
| 36 | 16 | ▶ | if (defined $haystack) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 37 | 12 | return $haystack; | |||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | # For lazy building | ||||||||||||||||||||||||||||||||||
| 41 | 4 | return $self->_construct_haystack; | |||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||
| 44 | 8 | ▶ | sub find { | ||||||||||||||||||||||||||||||||
|
Subroutine
find: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 45 | 8 | my ($self, $needle) = @_; | |||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | 8 | ▶ | return exists($self->haystack->{$needle}) ? 1 : 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | 8 | ▶ | sub cnt { | ||||||||||||||||||||||||||||||||
|
Subroutine
cnt: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 51 | 8 | my ($self, $needle) = @_; | |||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | 8 | ▶ | return $self->haystack->{$needle} || 0; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->haystack->{$needle} || 0
MC/DC100%1/1
$self->haystack->{$needle} || 0
$self->haystack->{$needle}
Truth table100%2/2
A
A= $self->haystack->{$needle}
| |||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||
| 56 | 12 | ▶ | sub _construct_haystack { | ||||||||||||||||||||||||||||||||
|
Subroutine
_construct_haystack: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 57 | 12 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | 12 | my %haystack; | |||||||||||||||||||||||||||||||||
| 60 | 12 | for my $item (@{($self->{list})}) { | |||||||||||||||||||||||||||||||||
| 61 | 15 | $haystack{$item}++; | |||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | 12 | $self->{haystack} = \%haystack; | |||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | 4 | 1; | |||||||||||||||||||||||||||||||||
| 68 | __END__ | ||||||||||||||||||||||||||||||||||