CycloneDX/List.pm

filter: Statementstmt 49.0% 27 / 55 Branchbran 50.0% 1 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 47.8% 11 / 23 Podpod 100% 18 / 18 totaltotal 56.4% 57 / 101 CC 4 SCAR 8.0
CC
4
Cov
47%
join
6.0
each
4.5
grep
2.0
CRAP 2.2
« CycloneDX/Schema.pm ↑ Summary CycloneDX/Advisory.pm »
1 package SBOM::CycloneDX::List;
2  
3 16 ▶use 5.016000;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 16 ▶use overload '@{}' => \&to_array, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1857 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
11 1857 my $collection = CORE::shift;
12 1857 bless({collections => [@_]}, $collection);
13 }
14  
15 12 ▶sub each {
Subroutine each: called CC=3 SCAR=15.1
Pod documented
16  
17 12 my ($self, $callback) = @_;
18  
19 12 ▶ return @{$self} unless $callback;
Branch: 1 branch
BranchTrueFalseTotal
unless $callback 12 0 12
20  
21 0 my $idx = 0;
22 0 $_->$callback($idx++) for @{$self};
23  
24 0 return $self;
25  
26 }
27  
28 0 ▶sub grep {
Subroutine grep: not called CC=1 SCAR=6.9
Pod documented
29 0 my ($self, $callback) = @_;
30 0 return $self->new(CORE::grep { $_->$callback(@_) } @{$self});
31 }
32  
33 0 ▶sub map {
Subroutine map: not called CC=1 SCAR=6.9
Pod documented
34 0 my ($self, $callback) = @_;
35 0 return $self->new(CORE::map { $_->$callback(@_) } @{$self});
36 }
37  
38 0 ▶sub size { CORE::scalar @{$_[0]->{collections}} }
Subroutine size: not called CC=1 SCAR=6.9
Pod documented
39  
40 0 ▶sub get { $_[0]->{collections}->[$_[1]] }
Subroutine get: not called CC=1 SCAR=6.9
Pod documented
41  
42 0 ▶sub set { $_[0]->{collections}->[$_[1]] = $_[2] }
Subroutine set: not called CC=1 SCAR=6.9
Pod documented
43  
44 0 ▶sub clear { @{$_[0]->{collections}} = () }
Subroutine clear: not called CC=1 SCAR=6.9
Pod documented
45  
46 0 ▶sub pop { CORE::pop @{$_[0]->{collections}} }
Subroutine pop: not called CC=1 SCAR=6.9
Pod documented
47  
48 73 ▶sub push { CORE::push @{$_[0]->{collections}}, @_[1 .. $#_] }
Subroutine push: called CC=1 SCAR=0.0
Pod documented
49  
50 0 ▶sub shift { CORE::shift @{$_[0]->{collections}} }
Subroutine shift: not called CC=1 SCAR=6.9
Pod documented
51  
52 0 ▶sub unshift { CORE::unshift @{$_[0]->{collections}}, @_[1 .. $#_] }
Subroutine unshift: not called CC=1 SCAR=6.9
Pod documented
53  
54 0 ▶sub join { CORE::join($_[1] // '', @{$_[0]}) }
Subroutine join: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/2
$_[1] // ""
l!l
00
MC/DC0%0/1
$_[1] // ""
$_[1]
Truth table0%0/2
A
A= $_[1]
Aresult
11
00
55  
56 0 ▶sub first { $_[0]->{collections}[0] }
Subroutine first: not called CC=1 SCAR=6.9
Pod documented
57  
58 0 ▶sub last { $_[0]->{collections}[-1] }
Subroutine last: not called CC=1 SCAR=6.9
Pod documented
59  
60 6744 ▶sub to_array { [@{$_[0]->{collections}}] }
Subroutine to_array: called CC=1 SCAR=0.0
Pod documented
61  
62 146 ▶sub TO_JSON { [@{$_[0]->{collections}}] }
Subroutine TO_JSON: called CC=1 SCAR=0.0
Pod documented
63  
64 # Aliases
65  
66 48 ▶sub add { $_[0]->push(@_[1 .. $#_]) }
Subroutine add: called CC=1 SCAR=0.0
Pod documented
67  
68 16 1;
69  
70 =encoding utf-8
71  
72 =head1 NAME
73  
74 SBOM::CycloneDX::List - Collection utility
75  
76 =head1 SYNOPSIS
77  
78 use SBOM::CycloneDX::List;
79 my $collection = SBOM::CycloneDX::List->new( qw[foo bar baz] );
80  
81  
82 =head1 DESCRIPTION
83  
84 L<SBOM::CycloneDX::List> is a collection utility.
85  
86  
87 =head2 METHODS
88  
89 =over
90  
91 =item SBOM::CycloneDX::List->new( ARRAY )
92  
93 Create a new collection.
94  
95 my $c = SBOM::CycloneDX::List->new( [foo bar baz] );
96  
97 =item $c->add
98  
99 Alias for L</"push">.
100  
101 =item $c->each
102  
103 Evaluate callback for each element in collection.
104  
105 foreach my $item ($c->each) {
106 [...]
107 }
108  
109 my $collection = $c->each(sub {...});
110  
111 $c->each(sub {
112 my ($value, $idx) = @_;
113 [...]
114 });
115  
116 =item $c->clear
117  
118 Reset the collection.
119  
120 =item $c->first
121  
122 Get the first element of collection.
123  
124 =item $c->get
125  
126 Get item from N index position.
127  
128 my $item = $c->get(5);
129  
130 =item $c->grep
131  
132 Filter items.
133  
134 my $filtered = $c->grep(sub { $_ eq 'foo' });
135  
136 =item $c->push
137  
138 Add a new item in collection.
139  
140 $c->push('foo');
141 $c->push(sub {...});
142  
143 =item $c->join
144  
145 Join elements in collection.
146  
147 $c->join(', ');
148  
149 =item $c->last
150  
151 Get the last element of collection.
152  
153 =item $c->map
154  
155 Evaluate the callback and create a new collection.
156  
157 SBOM::CycloneDX::List->new(1,2,3)->map(sub { $_ * 2 });
158  
159 =item $c->pop
160  
161 Remove and return the last element of collection.
162  
163 my $item = $c->pop;
164  
165 =item $c->push
166  
167 Add one or more elements in collection.
168  
169 $c->push('foo', 'bar', 'baz');
170  
171 =item $c->set
172  
173 Set item value in N index position.
174  
175 $c->set(5, 'foo');
176  
177 =item $c->shift
178  
179 Take the first element from the collection-
180  
181 my $item = $c->shift;
182  
183 =item $c->size
184  
185 Number of item elements.
186  
187 =item $c->unshift
188  
189 Add one or more elements at the beginning of the collection.
190  
191 $c->unshift('baz');
192  
193 =item $c->to_array
194  
195 Return the collection ARRAY.
196  
197 =item $c->TO_JSON
198  
199 Convert the collenction in JSON.
200  
201 =back
202  
203  
204 =head1 SUPPORT
205  
206 =head2 Bugs / Feature Requests
207  
208 Please report any bugs or feature requests through the issue tracker
209 at L<https://github.com/giterlizzi/perl-SBOM-CycloneDX/issues>.
210 You will be notified automatically of any progress on your issue.
211  
212 =head2 Source Code
213  
214 This is open source software. The code repository is available for
215 public review and contribution under the terms of the license.
216  
217 L<https://github.com/giterlizzi/perl-SBOM-CycloneDX>
218  
219 git clone https://github.com/giterlizzi/perl-SBOM-CycloneDX.git
220  
221  
222 =head1 AUTHOR
223  
224 =over 4
225  
226 =item * Giuseppe Di Terlizzi <gdt@cpan.org>
227  
228 =back
229  
230  
231 =head1 LICENSE AND COPYRIGHT
232  
233 This software is copyright (c) 2025-2026 by Giuseppe Di Terlizzi.
234  
235 This is free software; you can redistribute it and/or modify it under
236 the same terms as the Perl 5 programming language system itself.
237  
238 =cut
« CycloneDX/Schema.pm ↑ Summary CycloneDX/Advisory.pm »