File Coverage

blib/lib/SBOM/CycloneDX/Version.pm
Criterion Covered Total %
statement 20 31 64.5
branch 0 10 0.0
condition 0 3 0.0
subroutine 7 10 70.0
pod 1 2 50.0
total 28 56 50.0


line stmt bran cond sub pod time code
1             package SBOM::CycloneDX::Version;
2              
3 1     1   1965 use 5.010001;
  1         4  
4 1     1   4 use strict;
  1         2  
  1         19  
5 1     1   3 use warnings;
  1         2  
  1         44  
6 1     1   6 use utf8;
  1         2  
  1         7  
7              
8 1     1   43 use Types::Standard qw(Str Enum InstanceOf);
  1         2  
  1         7  
9              
10 1     1   3146 use Moo;
  1         2  
  1         7  
11 1     1   393 use namespace::autoclean;
  1         3  
  1         10  
12              
13             extends 'SBOM::CycloneDX::Base';
14              
15             sub BUILD {
16 0     0 0   my ($self, $args) = @_;
17             Carp::croak('"version" and "range" cannot be used at the same time')
18 0 0 0       if exists $args->{version} && exists $args->{range};
19             }
20              
21             has version => (is => 'rw', isa => Str);
22             has range => (is => 'rw', isa => InstanceOf ['URI::VersionRange'], coerce => sub { _vers_parse($_[0]) });
23             has status => (is => 'rw', isa => Enum [qw(affected unaffected unknown)]);
24              
25             sub _vers_parse {
26              
27 0     0     my $vers = shift;
28              
29 0 0         return $vers if (ref $vers eq 'URI::VersionRange');
30 0           return URI::VersionRange->from_string($vers);
31              
32             }
33              
34             sub TO_JSON {
35              
36 0     0 1   my $self = shift;
37              
38 0           my $json = {};
39              
40 0 0         $json->{versions} = $self->versions if $self->versions;
41 0 0         $json->{range} = $self->range->to_string if $self->range;
42 0 0         $json->{status} = $self->status if $self->status;
43              
44 0           return $json;
45              
46             }
47              
48             1;
49              
50             =encoding utf-8
51              
52             =head1 NAME
53              
54             SBOM::CycloneDX::Version - Version
55              
56             =head1 SYNOPSIS
57              
58             SBOM::CycloneDX::Version->new();
59              
60              
61             =head1 DESCRIPTION
62              
63             L provide the version object.
64              
65             =head2 METHODS
66              
67             L inherits all methods from L
68             and implements the following new ones.
69              
70             =over
71              
72             =item SBOM::CycloneDX::Version->new( %PARAMS )
73              
74             Properties:
75              
76             =over
77              
78             =item * C, A version range specified in Package URL Version Range
79             syntax (vers) which is defined at
80             L
81              
82             =item * C, The vulnerability status for the version or range of
83             versions.
84              
85             =item * C, A single version of a component or service.
86              
87             =back
88              
89             =item $version->range
90              
91             =item $version->status
92              
93             =item $version->version
94              
95             =back
96              
97              
98             =head1 SUPPORT
99              
100             =head2 Bugs / Feature Requests
101              
102             Please report any bugs or feature requests through the issue tracker
103             at L.
104             You will be notified automatically of any progress on your issue.
105              
106             =head2 Source Code
107              
108             This is open source software. The code repository is available for
109             public review and contribution under the terms of the license.
110              
111             L
112              
113             git clone https://github.com/giterlizzi/perl-SBOM-CycloneDX.git
114              
115              
116             =head1 AUTHOR
117              
118             =over 4
119              
120             =item * Giuseppe Di Terlizzi
121              
122             =back
123              
124              
125             =head1 LICENSE AND COPYRIGHT
126              
127             This software is copyright (c) 2025-2026 by Giuseppe Di Terlizzi.
128              
129             This is free software; you can redistribute it and/or modify it under
130             the same terms as the Perl 5 programming language system itself.
131              
132             =cut