lib/Data/TagDB/Iterator.pm

filter: Statementstmt 25.9% 21 / 81 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 26.0% 6 / 23 Podpod 100% 10 / 10 totaltotal 25.0% 37 / 148 CC 17 SCAR 34.3
CC
17
Cov
19%
collect
110.0
new
6.0
foreach
6.0
CRAP 30.9
« lib/Data/TagDB.pm ↑ Summary lib/Data/TagDB/LinkIterator.pm »
1 # Copyright (c) 2024-2026 Philipp Schafft
2  
3 # licensed under Artistic License 2.0 (see LICENSE file)
4  
5 # ABSTRACT: Work with Tag databases
6  
7 package Data::TagDB::Iterator;
8  
9 4 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 our $VERSION = v0.16;
16  
17  
18  
19 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
20 0 my ($pkg, %opts) = @_;
21  
22 0 ▶ croak 'Missing required member: db' unless defined $opts{db};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts{"db"} 0 0 0
23  
24 0 return bless \%opts, $pkg;
25 }
26  
27  
28 0 ▶sub from_array {
Subroutine from_array: not called CC=1 SCAR=6.9
Pod documented
29 0 my ($pkg, $array, %opts) = @_;
30 0 return Data::TagDB::Iterator::_Array->new(%opts, array => $array);
31 }
32  
33  
34 0 ▶sub db {
Subroutine db: not called CC=1 SCAR=6.9
Pod documented
35 0 my ($self) = @_;
36 0 return $self->{db};
37 }
38  
39  
40 0 ▶sub next {
Subroutine next: not called CC=1 SCAR=6.9
Pod documented
41 0 my ($self) = @_;
42 0 confess 'Not implemented';
43 }
44  
45  
46 0 ▶sub finish {
Subroutine finish: not called CC=1 SCAR=6.9
Pod documented
47 0 my ($self) = @_;
48 0 confess 'Not implemented';
49 }
50  
51  
52  
53 0 ▶sub foreach {
Subroutine foreach: not called CC=2 SCAR=17.9
Pod documented
54 0 my ($self, $code) = @_;
55  
56 0 ▶ while (defined(my $ent = $self->next)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ent = $self->next)) 0 0 0
57 0 $code->($ent);
58 }
59  
60 0 $self->finish;
61 }
62  
63  
64 0 ▶sub one {
Subroutine one: not called CC=2 SCAR=17.9
Pod documented
65 0 my ($self) = @_;
66 0 my $ent = $self->next;
67 0 $self->finish;
68  
69 0 ▶ return $ent // croak 'No entry';
Condition0%0/2
$ent // croak("No entry")
l!l
00
MC/DC0%0/1
$ent // croak("No entry")
$ent
Truth table0%0/2
A
A= $ent
Aresult
11
00
70 }
71  
72  
73 0 ▶sub none {
Subroutine none: not called CC=2 SCAR=17.9
Pod documented
74 0 my ($self) = @_;
75 0 my $ent = $self->next;
76  
77 0 $self->finish;
78  
79 0 ▶ croak 'Iterator non-empty' if defined $ent;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ent 0 0 0
80 }
81  
82  
83 0 ▶sub map {
Subroutine map: not called CC=1 SCAR=6.9
Pod documented
84 0 my ($self, $apply, %opts) = @_;
85  
86 0 return Data::TagDB::Iterator::_Mapped->new($self, $apply);
87 }
88  
89  
90 0 ▶sub collect {
Subroutine collect: not called CC=10 SCAR=47.0
Pod documented
91 0 my ($self, $apply, %opts) = @_;
92 0 my @ret;
93  
94 0 ▶ if (defined $apply) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $apply) 0 0 0
95 0 ▶ unless (ref $apply) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $apply) 0 0 0
96 0 my $funcname = $apply;
97 0 ▶ $apply = sub { $_[0]->can($funcname)->(@_) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
98 }
99 }
100  
101 0 ▶ if (defined($apply)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $apply) { } 0 0 0
102 0 ▶ if ($opts{skip_died}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{'skip_died'}) { } 0 0 0
103 0 ▶ while (defined(my $ent = $self->next)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ent = $self->next)) 0 0 0
104 0 $ent = eval { $ent->$apply() };
105 0 ▶ push(@ret, $ent) unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 0 0 0
106 }
107 } else {
108 0 ▶ while (defined(my $ent = $self->next)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ent = $self->next)) 0 0 0
109 0 push(@ret, $ent->$apply());
110 }
111 }
112 } else {
113 0 ▶ while (defined(my $ent = $self->next)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ent = $self->next)) 0 0 0
114 0 push(@ret, $ent);
115 }
116 }
117  
118 0 ▶ return \@ret if $opts{return_ref};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"return_ref"} 0 0 0
119  
120 0 return @ret;
121 }
122  
123 4 package Data::TagDB::Iterator::_Mapped {
124 4 ▶ use parent -norequire, 'Data::TagDB::Iterator';
Subroutine BEGIN: called CC=1 SCAR=0.0
125  
126 0 ▶ sub new {
Subroutine new: not called CC=2 SCAR=17.9
127 0 my ($pkg, $parent, $apply) = @_;
128  
129 0 ▶ unless (ref $apply) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $apply) 0 0 0
130 0 my $funcname = $apply;
131 0 ▶ $apply = sub { $_[0]->can($funcname)->(@_) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
132 }
133  
134 0 return $pkg->SUPER::new(db => $parent->db, parent => $parent, apply => $apply);
135 }
136  
137 0 ▶ sub next {
Subroutine next: not called CC=2 SCAR=17.9
138 0 my ($self, @args) = @_;
139 0 my $ent = $self->{parent}->next(@args);
140 0 my $apply = $self->{apply};
141  
142 0 ▶ return undef unless defined $ent;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ent 0 0 0
143  
144 0 return $ent->$apply();
145 }
146  
147 0 ▶ sub finish {
Subroutine finish: not called CC=1 SCAR=6.9
148 0 my ($self, @args) = @_;
149 0 return $self->{parent}->finish(@args);
150 }
151 };
152  
153 4 package Data::TagDB::Iterator::_Array {
154 4 ▶ use parent -norequire, 'Data::TagDB::Iterator';
Subroutine BEGIN: called CC=1 SCAR=0.0
155  
156 0 ▶ sub next {
Subroutine next: not called CC=2 SCAR=17.9
157 0 my ($self) = @_;
158 0 ▶ $self->{index} //= 0;
Condition0%0/2
$self->{"index"} //= 0
l!l
00
MC/DC0%0/1
$self->{"index"} //= 0
$self->{"index"}
Truth table0%0/2
A
A= $self->{"index"}
Aresult
11
00
159  
160 0 return $self->{array}[$self->{index}++];
161 }
162  
163 0 ▶ sub finish {}
Subroutine finish: not called CC=1 SCAR=0.0
164 };
165  
166 4 1;
167  
168 __END__
« lib/Data/TagDB.pm ↑ Summary lib/Data/TagDB/LinkIterator.pm »