blib/lib/Bootylicious/Iterator.pm

filter: Statementstmt 100% 59 / 59 Branchbran 100% 30 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 16 / 16 Podpod 7.6% 1 / 13 totaltotal 89.8% 106 / 118 CC 16 SCAR 11.0
CC
16
Cov
100%
prev
6.0
next
5.0
size
2.0
CRAP 3.0
« blib/lib/Bootylicious/Plugin/MarkdownParser.pm ↑ Summary blib/lib/Bootylicious/Plugin/HttpCache.pm »
1 package Bootylicious::Iterator;
2  
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 15 ▶use base 'Mojo::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 15 __PACKAGE__->attr('elements');
9  
10 sub new {
11 79 ▶ my $self = shift->SUPER::new(@_);
Subroutine new: called CC=1 SCAR=0.0
Pod documented
12  
13 79 $self->rewind;
14  
15 79 return $self;
16 }
17  
18 158 ▶sub rewind { shift->{index} = 0 }
Subroutine rewind: called CC=1 SCAR=0.0
Pod undocumented
19  
20 sub reverse {
21 1 ▶ my $self = shift;
Subroutine reverse: called CC=1 SCAR=0.0
Pod undocumented
22  
23 1 $self->{elements} = [reverse @{$self->{elements}}];
24  
25 1 return $self;
26 }
27  
28 183 ▶sub size { scalar @{shift->{elements} || []} }
Subroutine size: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{"elements"} or [] 4 179 183
29  
30 10 ▶sub first { shift->{elements}->[0] }
Subroutine first: called CC=1 SCAR=0.0
Pod undocumented
31 13 ▶sub last { shift->{elements}->[-1] }
Subroutine last: called CC=1 SCAR=0.0
Pod undocumented
32  
33 sub current {
34 3 ▶ my $self = shift;
Subroutine current: called CC=2 SCAR=6.9
Pod undocumented
35  
36 3 my $index = $self->{index};
37 3 ▶ $index-- if $index;
Branch: 1 branch
BranchTrueFalseTotal
if $index 1 2 3
38  
39 3 return $self->{elements}->[$index];
40 }
41  
42 sub take_next {
43 3 ▶ my $self = shift;
Subroutine take_next: called CC=2 SCAR=6.9
Pod undocumented
44  
45 3 ▶ return unless $self->has_next;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_next 1 2 3
46  
47 2 return $self->{elements}->[$self->{index}];
48 }
49  
50 sub take_prev {
51 3 ▶ my $self = shift;
Subroutine take_prev: called CC=2 SCAR=6.9
Pod undocumented
52  
53 3 ▶ return if $self->{index} < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"index"} < 2 1 2 3
54  
55 2 return $self->{elements}->[$self->{index} - 2];
56 }
57  
58 sub has_next {
59 141 ▶ my $self = shift;
Subroutine has_next: called CC=2 SCAR=6.9
Pod undocumented
60  
61 141 ▶ return $self->{index} < $self->size ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'index'} < $self->size ? : 101 40 141
62 }
63  
64 sub has_prev {
65 19 ▶ my $self = shift;
Subroutine has_prev: called CC=2 SCAR=6.9
Pod undocumented
66  
67 19 ▶ return $self->{index} > 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'index'} > 0 ? : 8 11 19
68 }
69  
70 sub next {
71 148 ▶ my $self = shift;
Subroutine next: called CC=5 SCAR=16.1
Pod undocumented
72 148 my $length = shift;
73  
74 148 ▶ if (!$length) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($length) 138 10 148
75 138 ▶ return unless $self->has_next;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_next 39 99 138
76  
77 99 return $self->{elements}->[$self->{index}++];
78 }
79  
80 10 my @elements;
81 10 ▶ while (my $element = $self->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $element = $self->next) 20 7 27
82 20 push @elements, $element;
83  
84 20 ▶ last if --$length <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$length <= 0 3 17 20
85 }
86  
87 10 return $self->new(elements => [@elements]);
88 }
89  
90 sub prev {
91 26 ▶ my $self = shift;
Subroutine prev: called CC=6 SCAR=17.9
Pod undocumented
92 26 my $length = shift;
93  
94 26 ▶ if (!$length) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($length) 19 7 26
95 19 ▶ return unless $self->has_prev;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_prev 11 8 19
96  
97 8 return $self->{elements}->[--$self->{index}];
98 }
99  
100 7 ▶ return $self->new(elements => []) if $self->{index} == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"index"} == 0 3 4 7
101  
102 4 $self->{index}--;
103  
104 4 my @elements;
105 4 ▶ while (my $element = $self->prev) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $element = $self->prev) 7 3 10
106 7 push @elements, $element;
107  
108 7 ▶ last if --$length <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$length <= 0 1 6 7
109 }
110  
111 4 return $self->new(elements => [@elements]);
112 }
113  
114 15 1;
« blib/lib/Bootylicious/Plugin/MarkdownParser.pm ↑ Summary blib/lib/Bootylicious/Plugin/HttpCache.pm »