CycloneDX/Base.pm

filter: Statementstmt 96.1% 25 / 26 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 8 / 9 Podpod 100% 3 / 3 totaltotal 94.7% 36 / 38 CC 1 SCAR 1.1
CC
1
Cov
96%
TO_JSON
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« CycloneDX/Vulnerability/Reference.pm ↑ Summary CycloneDX/Enum/CommonExtensionName.pm »
1 package SBOM::CycloneDX::Base;
2  
3 16 ▶use 5.010001;
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 Cpanel::JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 16 ▶use overload '""' => \&to_string, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 0 ▶sub TO_JSON { Carp::croak 'TO_JSON is not extended by subclass' }
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod documented
13  
14 162 ▶sub to_string {
Subroutine to_string: called CC=1 SCAR=0.0
Pod documented
15  
16 162 my $self = shift;
17  
18 162 my $json = Cpanel::JSON::XS->new->utf8->canonical->allow_nonref->allow_unknown->allow_blessed->convert_blessed
19 ->stringify_infnan->escape_slash(0)->allow_dupkeys->pretty->space_before(0);
20  
21 162 return $json->encode($self->TO_JSON);
22  
23 }
24  
25 34 ▶sub to_hash {
Subroutine to_hash: called CC=1 SCAR=0.0
Pod documented
26  
27 34 my $self = shift;
28  
29 34 my $json = $self->to_string;
30 34 my $hash = Cpanel::JSON::XS->new->decode($json);
31  
32 34 return $hash;
33  
34 }
35  
36 16 1;
37  
38 =encoding utf-8
39  
40 =head1 NAME
41  
42 SBOM::CycloneDX::Base - Base class for SBOM::CycloneDX
43  
44 =head1 SYNOPSIS
45  
46 $component->to_string; # Convert object in JSON
47  
48 $license->to_hash; # Convert object in HASH
49  
50 $bom->TO_JSON; Helper for JSON packages
51  
52  
53 =head1 DESCRIPTION
54  
55 L<SBOM::CycloneDX::BomRef> represents the BOM reference in L<SBOM::CycloneDX>.
56  
57 =head2 METHODS
58  
59 =over
60  
61 =item SBOM::CycloneDX::Base->new( %PARAMS )
62  
63 =item $base->to_string
64  
65 Stringify BOM object in JSON.
66  
67 =item $base->to_hash
68  
69 Convert BOM object in HASH.
70  
71 =item $base->TO_JSON
72  
73 Helper method for JSON modules (L<JSON>, L<JSON::PP>, L<JSON::XS>, L<Mojo::JSON>, etc).
74  
75 use Mojo::JSON qw(encode_json);
76  
77 say encode_json($bom);
78  
79 =back
80  
81 =head1 SUPPORT
82  
83 =head2 Bugs / Feature Requests
84  
85 Please report any bugs or feature requests through the issue tracker
86 at L<https://github.com/giterlizzi/perl-SBOM-CycloneDX/issues>.
87 You will be notified automatically of any progress on your issue.
88  
89 =head2 Source Code
90  
91 This is open source software. The code repository is available for
92 public review and contribution under the terms of the license.
93  
94 L<https://github.com/giterlizzi/perl-SBOM-CycloneDX>
95  
96 git clone https://github.com/giterlizzi/perl-SBOM-CycloneDX.git
97  
98  
99 =head1 AUTHOR
100  
101 =over 4
102  
103 =item * Giuseppe Di Terlizzi <gdt@cpan.org>
104  
105 =back
106  
107  
108 =head1 LICENSE AND COPYRIGHT
109  
110 This software is copyright (c) 2025-2026 by Giuseppe Di Terlizzi.
111  
112 This is free software; you can redistribute it and/or modify it under
113 the same terms as the Perl 5 programming language system itself.
114  
115 =cut
« CycloneDX/Vulnerability/Reference.pm ↑ Summary CycloneDX/Enum/CommonExtensionName.pm »