blib/lib/List/Haystack.pm

filter: Statementstmt 100% 38 / 38 Branchbran 100% 10 / 10 Conditioncond 75.0% 6 / 8 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 9 / 9 Podpod 100% 4 / 4 totaltotal 94.5% 69 / 73 CC 10 SCAR 11.4
CC
10
Cov
96%
new
6.0
haystack
2.0
find
2.0
CRAP 3.1
↑ Summary
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
BranchTrueFalseTotal
unless (defined $list) 3 13 16
13 3 $list = [];
14 }
15  
16 16 ▶ if (ref $list ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $list ne "ARRAY") 1 15 16
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'}
!ll&&!rl&&r
807
defined $options and ref $options eq "HASH"
!ll&&!rl&&r
807
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'}
ABCresult
0XX0
10X0
1100
1111
25 15 ▶ if (not $lazy) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lazy) 8 7 15
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
BranchTrueFalseTotal
if (defined $haystack) 12 4 16
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
BranchTrueFalseTotal
exists $self->haystack->{$needle} ? : 4 4 8
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
l!l
44
MC/DC100%1/1
$self->haystack->{$needle} || 0
$self->haystack->{$needle}
Truth table100%2/2
A
A= $self->haystack->{$needle}
Aresult
11
00
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__
↑ Summary