CycloneDX/Lite.pm

filter: Statementstmt 56.7% 38 / 67 Branchbran 0.0% 0 / 4 Conditioncond 25.0% 4 / 16 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 22.2% 6 / 27 Podpod 100% 21 / 21 totaltotal 47.9% 69 / 144 CC 6 SCAR 13.9
CC
6
Cov
48%
import
14.4
bom
6.0
component
2.0
CRAP 4.0
« CycloneDX/Declarations.pm ↑ Summary CycloneDX/Declarations/Confidence.pm »
1 package SBOM::CycloneDX::Lite;
2  
3 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 require SBOM::CycloneDX;
11 1 require SBOM::CycloneDX::Component;
12 1 require SBOM::CycloneDX::ExternalReference;
13 1 require SBOM::CycloneDX::Hash;
14 1 require SBOM::CycloneDX::License;
15 1 require SBOM::CycloneDX::OrganizationalContact;
16 1 require SBOM::CycloneDX::OrganizationalEntity;
17 1 require SBOM::CycloneDX::Property;
18  
19  
20 1 our @EXPORT_OK = qw(
21 bom
22 component
23 contact
24 external_reference
25 hash
26 license
27 organization
28 property
29  
30 application_component
31 container_component
32 cryptographic_asset_component
33 data_component
34 device_component
35 device_driver_component
36 file_component
37 firmware_component
38 framework_component
39 library_component
40 machine_learning_model_component
41 operating_system_component
42 platform_component
43 );
44  
45 1 our %EXPORT_TAGS = (all => \@EXPORT_OK);
46  
47 my $LATEST_SPEC_VERSION = (
48 sort {
49 1 my ($am, $an, $ap) = split /\./, $a, 3;
50 11 my ($bm, $bn, $bp) = split /\./, $b, 3;
51 11 ▶ $ap //= 0;
Condition50%1/2
$ap //= 0
l!l
011
MC/DC0%0/1
$ap //= 0
$ap
Truth table50%1/2
A
A= $ap
Aresult
11
00
52 11 ▶ $bp //= 0;
Condition50%1/2
$bp //= 0
l!l
011
MC/DC0%0/1
$bp //= 0
$bp
Truth table50%1/2
A
A= $bp
Aresult
11
00
53 11 ▶ $am <=> $bm || $an <=> $bn || $ap <=> $bp
Condition33%2/6
$am <=> $bm || $an <=> $bn || $ap <=> $bp
l!l&&r!l&&!r
1100
$am <=> $bm or $an <=> $bn
l!l&&r!l&&!r
0110
MC/DC0%0/3
$am <=> $bm || $an <=> $bn || $ap <=> $bp
$am <=> $bm $an <=> $bn $ap <=> $bp
Truth table0%0/4
A or B || C
A= $am <=> $bmB= $an <=> $bnC= $ap <=> $bp
ABCresult
1XX1
01X1
0011
0000
54 } keys %SBOM::CycloneDX::JSON_SCHEMA
55 )[-1];
56  
57 1 my $DEFAULT_SPEC_VERSION = $LATEST_SPEC_VERSION;
58  
59 1 my %_caller_version = ();
60  
61 1 ▶sub import {
Subroutine import: called CC=5 SCAR=26.7
62  
63 1 my $class = shift;
64 1 my $caller = caller;
65  
66 1 foreach (@_) {
67  
68 0 ▶ if ($_ =~ /^\:v(1_\d+(?:_\d+)?)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^\:v(1_\d+(?:_\d+)?)$/) 0 0 0
69 0 my $v = $1 =~ tr/_/./r;
70 0 $_caller_version{$caller} = $v;
71 }
72  
73 0 ▶ if ($_ eq ':latest') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq ":latest") 0 0 0
74 0 $DEFAULT_SPEC_VERSION = $LATEST_SPEC_VERSION;
75 }
76  
77 }
78  
79 1 local $Exporter::ExportLevel = 1;
80 0 ▶ Exporter::import($class, grep { $_ !~ /^:v1_/ && $_ ne ':latest' } @_);
Condition0%0/3
!($_ =~ /^:v1_/) && $_ ne ':latest'
!ll&&!rl&&r
000
MC/DC0%0/2
!($_ =~ /^:v1_/) && $_ ne ':latest'
!($_ =~ /^:v1_/) $_ ne ':latest'
Truth table0%0/3
not(A) && B
A= !($_ =~ /^:v1_/)B= $_ ne ':latest'
ABresult
0X0
100
111
81  
82 }
83  
84 0 ▶sub bom {
Subroutine bom: not called CC=2 SCAR=17.9
Pod documented
85 0 my $caller = caller;
86 0 ▶ my $version = $_caller_version{$caller} // $DEFAULT_SPEC_VERSION;
Condition0%0/3
$_caller_version{$caller} // $DEFAULT_SPEC_VERSION
l!l&&r!l&&!r
000
MC/DC0%0/2
$_caller_version{$caller} // $DEFAULT_SPEC_VERSION
$_caller_version{$caller} $DEFAULT_SPEC_VERSION
Truth table0%0/3
A // B
A= $_caller_version{$caller}B= $DEFAULT_SPEC_VERSION
ABresult
1X1
011
000
87 0 return SBOM::CycloneDX->new(spec_version => $version, @_);
88 }
89  
90 0 ▶sub component { SBOM::CycloneDX::Component->new(@_) }
Subroutine component: not called CC=1 SCAR=6.9
Pod documented
91 0 ▶sub contact { SBOM::CycloneDX::OrganizationalContact->new(@_) }
Subroutine contact: not called CC=1 SCAR=6.9
Pod documented
92 0 ▶sub external_reference { SBOM::CycloneDX::ExternalReference->new(@_) }
Subroutine external_reference: not called CC=1 SCAR=6.9
Pod documented
93 0 ▶sub hash { SBOM::CycloneDX::Hash->new(@_) }
Subroutine hash: not called CC=1 SCAR=6.9
Pod documented
94 0 ▶sub license { SBOM::CycloneDX::License->new(@_) }
Subroutine license: not called CC=1 SCAR=6.9
Pod documented
95 0 ▶sub organization { SBOM::CycloneDX::OrganizationalEntity->new(@_) }
Subroutine organization: not called CC=1 SCAR=6.9
Pod documented
96 0 ▶sub property { SBOM::CycloneDX::Property->new(@_) }
Subroutine property: not called CC=1 SCAR=6.9
Pod documented
97  
98 0 ▶sub application_component { component(type => 'application', @_) }
Subroutine application_component: not called CC=1 SCAR=6.9
Pod documented
99 0 ▶sub container_component { component(type => 'container', @_) }
Subroutine container_component: not called CC=1 SCAR=6.9
Pod documented
100 0 ▶sub cryptographic_asset_component { component(type => 'cryptographic-asset', @_) }
Subroutine cryptographic_asset_component: not called CC=1 SCAR=6.9
Pod documented
101 0 ▶sub data_component { component(type => 'data', @_) }
Subroutine data_component: not called CC=1 SCAR=6.9
Pod documented
102 0 ▶sub device_component { component(type => 'device', @_) }
Subroutine device_component: not called CC=1 SCAR=6.9
Pod documented
103 0 ▶sub device_driver_component { component(type => 'device-driver', @_) }
Subroutine device_driver_component: not called CC=1 SCAR=6.9
Pod documented
104 0 ▶sub file_component { component(type => 'file', @_) }
Subroutine file_component: not called CC=1 SCAR=6.9
Pod documented
105 0 ▶sub firmware_component { component(type => 'firmware', @_) }
Subroutine firmware_component: not called CC=1 SCAR=6.9
Pod documented
106 0 ▶sub framework_component { component(type => 'framework', @_) }
Subroutine framework_component: not called CC=1 SCAR=6.9
Pod documented
107 0 ▶sub library_component { component(type => 'library', @_) }
Subroutine library_component: not called CC=1 SCAR=6.9
Pod documented
108 0 ▶sub machine_learning_model_component { component(type => 'machine-learning-model', @_) }
Subroutine machine_learning_model_component: not called CC=1 SCAR=6.9
Pod documented
109 0 ▶sub operating_system_component { component(type => 'operating-system', @_) }
Subroutine operating_system_component: not called CC=1 SCAR=6.9
Pod documented
110 0 ▶sub platform_component { component(type => 'platform', @_) }
Subroutine platform_component: not called CC=1 SCAR=6.9
Pod documented
111  
112 1 1;
113  
114 =encoding utf-8
115  
116 =head1 NAME
117  
118 SBOM::CycloneDX::Lite - Simple accessors and helpers for SBOM::CycloneDX
119  
120 =head1 SYNOPSIS
121  
122 use SBOM::CycloneDX::Lite qw(:v1_7 :all);
123 use SBOM::CycloneDX::Util qw(cyclonedx_tool);
124  
125 my $bom = bom;
126  
127 my $root_component = application_component(
128 name => 'MyApp',
129 licenses => [license('Artistic-2.0')],
130 bom_ref => 'MyApp'
131 );
132  
133 my $metadata = $bom->metadata;
134  
135 $metadata->tools->add(cyclonedx_tool);
136  
137 $metadata->component($root_component);
138  
139 my $component1 = library_component(
140 name => 'some-component',
141 group => 'acme',
142 version => '1.33.7-beta.1',
143 licenses => [license(name => '(c) 2021 Acme inc.')],
144 bom_ref => 'myComponent@1.33.7-beta.1',
145 purl => URI::PackageURL->new(
146 type => 'generic',
147 namespace => 'acme',
148 name => 'some-component',
149 version => '1.33.7-beta.1'
150 ),
151 );
152  
153 $bom->components->add($component1);
154 $bom->add_dependency($root_component, [$component1]);
155  
156 my $component2 = library_component(
157 name => 'some-library',
158 licenses => [license('GPL-3.0-only WITH Classpath-exception-2.0')],
159 bom_ref => 'some-lib',
160 );
161  
162 $bom->components->add($component2);
163 $bom->add_dependency($root_component, [$component2]);
164  
165 my @errors = $bom->validate;
166  
167 if (@errors) {
168 say $_ for (@errors);
169 Carp::croak 'Validation error';
170 }
171  
172 say $bom->to_string;
173  
174  
175  
176 =head1 DESCRIPTION
177  
178 L<SBOM::CycloneDX::Lite> is an EXPERIMENTAL lightweight layer built on top of
179 L<SBOM::CycloneDX> to quickly create CycloneDX BOM files.
180  
181 It focuses on the most commonly used BOM fields and provides a simple,
182 low-boilerplate interface. It accepts friendly input and normalizes it into
183 canonical CycloneDX structures.
184  
185 =head2 EXPORTED TAGS
186  
187 =over
188  
189 =item C<:latest>
190  
191 Select the latest CycloneDX schema version supported by L<SBOM::CycloneDX>
192 distribution.
193  
194 =item C<:v1_7>
195  
196 Select the CycloneDX v1.7 schema version.
197  
198 =item C<:v1_6>
199  
200 Select the CycloneDX v1.6 schema version.
201  
202 =item C<:v1_5>
203  
204 Select the CycloneDX v1.5 schema version.
205  
206 =item C<:v1_4>
207  
208 Select the CycloneDX v1.4 schema version.
209  
210 =item C<:v1_3>
211  
212 Select the CycloneDX v1.3 schema version.
213  
214 =item C<:v1_2>
215  
216 Select the CycloneDX v1.2 schema version.
217  
218 =item C<:all>
219  
220 Export all functions.
221  
222 =back
223  
224 =head2 EXPORTED FUNCTIONS
225  
226 =head3 B<bom>
227  
228 Return a L<SBOM::CycloneDX> object.
229  
230 =head3 B<component>
231  
232 Return a L<SBOM::CycloneDX::Component> object.
233  
234 Component aliases:
235  
236 =over
237  
238 =item B<application_component>
239  
240 =item B<framework_component>
241  
242 =item B<library_component>
243  
244 =item B<container_component>
245  
246 =item B<platform_component>
247  
248 =item B<operating_system_component>
249  
250 =item B<device_component>
251  
252 =item B<device_driver_component>
253  
254 =item B<firmware_component>
255  
256 =item B<file_component>
257  
258 =item B<machine_learning_model_component>
259  
260 =item B<data_component>
261  
262 =item B<cryptographic_asset_component>
263  
264 =back
265  
266 =head3 B<license>
267  
268 Return a L<SBOM::CycloneDX::License> object.
269  
270 =head3 B<external_reference>
271  
272 Return a L<SBOM::CycloneDX::ExternalReference> object.
273  
274 =head3 B<property>
275  
276 Return a L<SBOM::CycloneDX::Property> object.
277  
278 =head3 B<organization>
279  
280 Return a L<SBOM::CycloneDX::OrganizationalEntity> object.
281  
282 =head3 B<contact>
283  
284 Return a L<SBOM::CycloneDX::OrganizationalContact> object.
285  
286 =head3 B<hash>
287  
288 Return a L<SBOM::CycloneDX::Hash> object.
289  
290  
291 =head1 SUPPORT
292  
293 =head2 Bugs / Feature Requests
294  
295 Please report any bugs or feature requests through the issue tracker
296 at L<https://github.com/giterlizzi/perl-SBOM-CycloneDX/issues>.
297 You will be notified automatically of any progress on your issue.
298  
299 =head2 Source Code
300  
301 This is open source software. The code repository is available for
302 public review and contribution under the terms of the license.
303  
304 L<https://github.com/giterlizzi/perl-SBOM-CycloneDX>
305  
306 git clone https://github.com/giterlizzi/perl-SBOM-CycloneDX.git
307  
308  
309 =head1 AUTHOR
310  
311 =over 4
312  
313 =item * Giuseppe Di Terlizzi <gdt@cpan.org>
314  
315 =back
316  
317  
318 =head1 LICENSE AND COPYRIGHT
319  
320 This software is copyright (c) 2025-2026 by Giuseppe Di Terlizzi.
321  
322 This is free software; you can redistribute it and/or modify it under
323 the same terms as the Perl 5 programming language system itself.
324  
325 =cut
« CycloneDX/Declarations.pm ↑ Summary CycloneDX/Declarations/Confidence.pm »