| 1 | package CSAF::Type::ProductIdentificationHelper; | ||||||||||||||||||||
| 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 CSAF::Type::Hashes; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use CSAF::Type::GenericURIs; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 1 | ▶ | use URI::PackageURL; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 1 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 1 | extends 'CSAF::Type::Base'; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 1 | my $PURL_REGEX = qr{^pkg:[A-Za-z\\.\\-\\+][A-Za-z0-9\\.\\-\\+]*/.+}; | |||||||||||||||||||
| 17 | 1 | my $CPE_REGEX | |||||||||||||||||||
| 18 | = qr{^(cpe:2\.3:[aho\*\-](:(((\?*|\*?)([a-zA-Z0-9\-\._]|(\\[\\\*\?!"#\$%&'\(\)\+,/:;<=>@\[\]\^`\{\|\}~]))+(\?*|\*?))|[\*\-])){5}(:(([a-zA-Z]{2,3}(-([a-zA-Z]{2}|[0-9]{3}))?)|[\*\-]))(:(((\?*|\*?)([a-zA-Z0-9\-\._]|(\\[\\\*\?!"#\$%&'\(\)\+,/:;<=>@\[\]\^`\{\|\}~]))+(\?*|\*?))|[\*\-])){4})|([c][pP][eE]:/[AHOaho]?(:[A-Za-z0-9\._\-~%]*){0,6})$}; | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 0 | ▶ | has cpe => (is => 'rw', predicate => 1, isa => sub { Carp::croak 'Invalid CPE' if $_[0] !~ /$CPE_REGEX/ },); | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | has purl => ( | ||||||||||||||||||||
| 23 | is => 'rw', | ||||||||||||||||||||
| 24 | predicate => 1, | ||||||||||||||||||||
| 25 | 0 | ▶ | coerce => sub { ref($_[0]) eq 'URI::PackageURL' ? $_[0]->to_string : $_[0] }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||
| 26 | 0 | ▶ | isa => sub { Carp::croak 'Invalid purl' if $_[0] !~ /$PURL_REGEX/ } | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||
| 27 | 1 | ); | |||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 2 | ▶ | has hashes => (is => 'rw', trigger => 1, default => sub { CSAF::Type::Hashes->new }); | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 8 | ▶ | has [qw(sbom_urls serial_numbers skus model_numbers)] => (is => 'rw', predicate => 1, default => sub { [] }); | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 0 | ▶ | sub _trigger_hashes { | ||||||||||||||||||
|
Subroutine
_trigger_hashes: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 0 | my ($self) = @_; | |||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 0 | my $hashes = CSAF::Type::Hashes->new; | |||||||||||||||||||
| 38 | 0 | $hashes->item(%{$_}) for (@{$self->hashes}); | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 0 | $self->{hashes} = $hashes; | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | ▶ | sub x_generic_uris { | ||||||||||||||||||
|
Subroutine
x_generic_uris: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 45 | 0 | my $self = shift; | |||||||||||||||||||
| 46 | 0 | ▶ | $self->{x_generic_uris} ||= CSAF::Type::GenericURIs->new(@_); | ||||||||||||||||||
|
Condition0%0/3
$self->{"x_generic_uris"} ||= "CSAF::Type::GenericURIs"->new(@_)
MC/DC0%0/2
$self->{"x_generic_uris"} ||= "CSAF::Type::GenericURIs"->new(@_)
$self->{"x_generic_uris"}
"CSAF::Type::GenericURIs"->new(@_)
Truth table0%0/3
A ||= B
A= $self->{"x_generic_uris"}B= "CSAF::Type::GenericURIs"->new(@_)
| |||||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 0 | ▶ | sub TO_CSAF { | ||||||||||||||||||
|
Subroutine
TO_CSAF: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 0 | my $self = shift; | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | my $output = {}; | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 0 | ▶ | $output->{cpe} = $self->cpe if $self->has_cpe; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 0 | ▶ | $output->{purl} = $self->purl if $self->has_purl; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 0 | ▶ | $output->{skus} = $self->skus if @{$self->skus}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | 0 | ▶ | $output->{sbom_urls} = $self->sbom_urls if @{$self->sbom_urls}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 0 | ▶ | $output->{serial_numbers} = $self->serial_numbers if @{$self->serial_numbers}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 0 | ▶ | $output->{model_numbers} = $self->model_numbers if @{$self->model_numbers}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 0 | ▶ | if (@{$self->x_generic_uris->items}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | 0 | $output->{x_generic_uris} = $self->x_generic_uris; | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 0 | ▶ | if (my $hashes = $self->{hashes}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | 0 | ▶ | $output->{hashes} = $hashes->TO_CSAF if ($hashes->size); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 0 | return $output; | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 1 | 1; | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||