ArrayData/Test/Spec/Basic.pm

filter: Statementstmt 89.4% 34 / 38 Branchbran 57.1% 8 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 7 totaltotal 74.2% 52 / 70 CC 8 SCAR 10.6
CC
8
Cov
81%
has_item_at_pos
5.0
get_item_at_pos
4.8
_elems
2.0
CRAP 2.9
« ArrayDataRole/Spec/Basic.pm ↑ Summary ArrayData.pm »
1 package ArrayData::Test::Spec::Basic;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 with 'ArrayDataRole::Spec::Basic';
9  
10 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
11 2 our $DATE = '2024-01-16'; # DATE
12 2 our $DIST = 'ArrayData'; # DIST
13 2 our $VERSION = '0.2.6'; # VERSION
14  
15 2 my $elems = [
16 1,
17 2,
18 undef,
19 4,
20 ];
21  
22 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
23 1 my $class = shift;
24 1 bless {pos=>0}, $class;
25 }
26  
27 0 ▶sub _elems {
Subroutine _elems: not called CC=1 SCAR=6.9
28 0 my $self = shift;
29 0 $elems;
30 }
31  
32 19 ▶sub get_next_item {
Subroutine get_next_item: called CC=2 SCAR=6.9
Pod undocumented
33 19 my $self = shift;
34 19 ▶ die "StopIteration" unless $self->{pos} < @$elems;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"pos"} < @$elems 1 18 19
35 18 $elems->[ $self->{pos}++ ];
36 }
37  
38 17 ▶sub has_next_item {
Subroutine has_next_item: called CC=1 SCAR=0.0
Pod undocumented
39 17 my $self = shift;
40 17 $self->{pos} < @$elems;
41 }
42  
43 1 ▶sub get_iterator_pos {
Subroutine get_iterator_pos: called CC=1 SCAR=0.0
Pod undocumented
44 1 my $self = shift;
45 1 $self->{pos};
46 }
47  
48 5 ▶sub reset_iterator {
Subroutine reset_iterator: called CC=1 SCAR=0.0
Pod undocumented
49 5 my $self = shift;
50 5 $self->{pos} = 0;
51 }
52  
53 2 ▶sub get_item_at_pos {
Subroutine get_item_at_pos: called CC=4 SCAR=15.6
Pod undocumented
54 2 my ($self, $pos) = @_;
55 2 ▶ if ($pos < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < 0) { } 0 2 2
56 0 ▶ die "Out of range" unless -$pos <= @$elems;
Branch: 1 branch
BranchTrueFalseTotal
unless -$pos <= @$elems 0 0 0
57 } else {
58 2 ▶ die "Out of range" unless $pos < @$elems;
Branch: 1 branch
BranchTrueFalseTotal
unless $pos < @$elems 1 1 2
59 }
60 1 $elems->[ $pos ];
61 }
62  
63 2 ▶sub has_item_at_pos {
Subroutine has_item_at_pos: called CC=4 SCAR=16.1
Pod undocumented
64 2 my ($self, $pos) = @_;
65 2 ▶ if ($pos < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < 0) { } 0 2 2
66 0 ▶ return -$pos <= @$elems ? 1:0;
Branch: 1 branch
BranchTrueFalseTotal
-$pos <= @$elems ? : 0 0 0
67 } else {
68 2 ▶ return $pos < @$elems ? 1:0;
Branch: 1 branch
BranchTrueFalseTotal
$pos < @$elems ? : 1 1 2
69 }
70 }
71  
72 2 1;
73  
74 # ABSTRACT: A test array data
75  
76 __END__
« ArrayDataRole/Spec/Basic.pm ↑ Summary ArrayData.pm »