| 1 | package SSVC::Base; | ||||||||||||
| 2 | |||||||||||||
| 3 | 8 | ▶ | use feature ':5.10'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 8 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 8 | ▶ | use utf8; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 8 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 8 | ▶ | use Time::Piece; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 8 | ▶ | use Carp (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 8 | ▶ | use overload '""' => 'to_vector_string', fallback => 1; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | 8 | ▶ | use constant METADATA => +{}; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 8 | ▶ | use constant DECISION_POINTS => +{}; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 8 | ▶ | use constant DECISION_TREE => +{}; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 8 | ▶ | use constant DECISION_PATH => +[]; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 8 | ▶ | use constant VECTOR => +[]; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | |||||||||||||
| 19 | 487 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 20 | |||||||||||||
| 21 | 487 | my ($class, %params) = @_; | |||||||||||
| 22 | |||||||||||||
| 23 | 487 | my %decision_points = $class->normalize_decision_points(%params); | |||||||||||
| 24 | 487 | my %vector = $class->decision_points_to_vector(%decision_points); | |||||||||||
| 25 | 487 | my $decision = undef; | |||||||||||
| 26 | |||||||||||||
| 27 | 487 | my $self = {decision_points => \%decision_points, vector => \%vector, decision => $decision}; | |||||||||||
| 28 | |||||||||||||
| 29 | 487 | return bless $self, $class; | |||||||||||
| 30 | |||||||||||||
| 31 | } | ||||||||||||
| 32 | |||||||||||||
| 33 | 145 | ▶ | sub vector { shift->{vector} } | ||||||||||
|
Subroutine
vector: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 34 | 0 | ▶ | sub decision_points { shift->{decision_points} } | ||||||||||
|
Subroutine
decision_points: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 35 | |||||||||||||
| 36 | 43 | ▶ | sub compute { | ||||||||||
|
Subroutine
compute: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 37 | |||||||||||||
| 38 | 43 | my ($self) = @_; | |||||||||||
| 39 | |||||||||||||
| 40 | 43 | my $key = join ':', map { $self->vector->{$_} } @{$self->DECISION_PATH}; | |||||||||||
| 41 | 43 | return $self->DECISION_TREE->{$key}; | |||||||||||
| 42 | |||||||||||||
| 43 | } | ||||||||||||
| 44 | |||||||||||||
| 45 | 7999 | ▶ | sub vector_value { | ||||||||||
|
Subroutine
vector_value: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 46 | 7999 | my ($self, $name) = @_; | |||||||||||
| 47 | 7999 | return $self->{vector}->{$name}; | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | 0 | ▶ | sub decision_point_value { | ||||||||||
|
Subroutine
decision_point_value: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 51 | 0 | my ($self, $name) = @_; | |||||||||||
| 52 | 0 | return $self->{decision_points}->{$name}; | |||||||||||
| 53 | } | ||||||||||||
| 54 | |||||||||||||
| 55 | 3157 | ▶ | sub decision_point_enum { | ||||||||||
|
Subroutine
decision_point_enum: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 56 | 3157 | my ($self, $name) = @_; | |||||||||||
| 57 | 3157 | my @values = @{$self->DECISION_POINTS->{$name}->{values}}; | |||||||||||
| 58 | 3157 | return [@values[grep { $_ % 2 } 0 .. @values]]; | |||||||||||
| 59 | } | ||||||||||||
| 60 | |||||||||||||
| 61 | 1915 | ▶ | sub decision_point_labels { | ||||||||||
|
Subroutine
decision_point_labels: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 62 | 1915 | my ($self, $name) = @_; | |||||||||||
| 63 | 1915 | my %labels = @{$self->DECISION_POINTS->{$name}->{values}}; | |||||||||||
| 64 | 1915 | return \%labels; | |||||||||||
| 65 | } | ||||||||||||
| 66 | |||||||||||||
| 67 | 3157 | ▶ | sub decision_point_codes { | ||||||||||
|
Subroutine
decision_point_codes: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 68 | 3157 | my ($self, $name) = @_; | |||||||||||
| 69 | 3157 | my %codes = reverse @{$self->DECISION_POINTS->{$name}->{values}}; | |||||||||||
| 70 | 3157 | return \%codes; | |||||||||||
| 71 | } | ||||||||||||
| 72 | |||||||||||||
| 73 | 0 | ▶ | sub decision_point_info { | ||||||||||
|
Subroutine
decision_point_info: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 74 | 0 | my ($self, $name) = @_; | |||||||||||
| 75 | 0 | my $dp = $self->DECISION_POINTS->{$name}; | |||||||||||
| 76 | |||||||||||||
| 77 | return { | ||||||||||||
| 78 | vector_name => $dp->{vector_name}, | ||||||||||||
| 79 | label => $dp->{label}, | ||||||||||||
| 80 | definition => $dp->{definition}, | ||||||||||||
| 81 | 0 | enum => $self->decision_point_enum($name), | |||||||||||
| 82 | labels => $self->decision_point_labels($name), | ||||||||||||
| 83 | codes => $self->decision_point_codes($name), | ||||||||||||
| 84 | }; | ||||||||||||
| 85 | } | ||||||||||||
| 86 | |||||||||||||
| 87 | 487 | ▶ | sub decision_points_to_vector { | ||||||||||
|
Subroutine
decision_points_to_vector: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 88 | |||||||||||||
| 89 | 487 | my ($self, %decision_points) = @_; | |||||||||||
| 90 | |||||||||||||
| 91 | 487 | my %output = (); | |||||||||||
| 92 | |||||||||||||
| 93 | 487 | foreach (keys %{$self->DECISION_POINTS}) { | |||||||||||
| 94 | 4100 | ▶ | next unless $decision_points{$_}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 95 | 3157 | my $vector_name = $self->DECISION_POINTS->{$_}->{vector_name}; | |||||||||||
| 96 | 3157 | $output{$vector_name} = $self->decision_point_codes($_)->{$decision_points{$_}}; | |||||||||||
| 97 | } | ||||||||||||
| 98 | |||||||||||||
| 99 | 487 | return %output; | |||||||||||
| 100 | |||||||||||||
| 101 | } | ||||||||||||
| 102 | |||||||||||||
| 103 | 487 | ▶ | sub normalize_decision_points { | ||||||||||
|
Subroutine
normalize_decision_points: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||
| 104 | |||||||||||||
| 105 | 487 | my ($self, %params) = @_; | |||||||||||
| 106 | |||||||||||||
| 107 | 487 | my %normalized = (); | |||||||||||
| 108 | |||||||||||||
| 109 | 487 | foreach my $dp (keys %params) { | |||||||||||
| 110 | |||||||||||||
| 111 | 3157 | my @allowed = @{$self->decision_point_enum($dp)}; | |||||||||||
| 112 | |||||||||||||
| 113 | 3157 | ▶ | unless (grep { lc $params{$dp} eq $_ } @allowed) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 114 | 0 | Carp::croak "Unknown value for '$dp' (allowed: " . join(', ', @allowed) . ")"; | |||||||||||
| 115 | } | ||||||||||||
| 116 | |||||||||||||
| 117 | 3157 | $normalized{$dp} = lc $params{$dp}; | |||||||||||
| 118 | } | ||||||||||||
| 119 | |||||||||||||
| 120 | 487 | return %normalized; | |||||||||||
| 121 | |||||||||||||
| 122 | } | ||||||||||||
| 123 | |||||||||||||
| 124 | |||||||||||||
| 125 | 0 | ▶ | sub to_vector_string { | ||||||||||
|
Subroutine
to_vector_string: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||
| 126 | |||||||||||||
| 127 | 0 | my $self = shift; | |||||||||||
| 128 | 0 | my $prefix = 'SSVC'; | |||||||||||
| 129 | |||||||||||||
| 130 | 0 | ▶ | if (defined $self->METADATA->{key}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 131 | 0 | $prefix = uc $self->METADATA->{key}; | |||||||||||
| 132 | } | ||||||||||||
| 133 | |||||||||||||
| 134 | 0 | my $now = Time::Piece->gmtime->datetime; | |||||||||||
| 135 | 0 | ▶ | my @vectors = (map { join ':', $_, $self->{vector}->{$_} || Carp::croak 'Missing metric' } @{$self->VECTOR}); | ||||||||||
|
Condition0%0/2
$self->{'vector'}{$_} || Carp::croak('Missing metric')
MC/DC0%0/1
$self->{'vector'}{$_} || Carp::croak('Missing metric')
$self->{'vector'}{$_}
Truth table0%0/2
A
A= $self->{'vector'}{$_}
| |||||||||||||
| 136 | |||||||||||||
| 137 | 0 | return join '/', "${prefix}v1", @vectors, "${now}.000Z"; | |||||||||||
| 138 | |||||||||||||
| 139 | } | ||||||||||||
| 140 | |||||||||||||
| 141 | 0 | ▶ | sub TO_JSON { {} } | ||||||||||
|
Subroutine
TO_JSON: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 142 | |||||||||||||
| 143 | 8 | 1; | |||||||||||
| 144 | |||||||||||||
| 145 | __END__ | ||||||||||||