| 1 | package CSAF::Type::Document; | ||
| 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 Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 1 | ▶ | use CSAF::Type::AggregateSeverity; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 1 | ▶ | use CSAF::Type::Distribution; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 1 | ▶ | use CSAF::Type::Publisher; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | 0 | ▶ | use CSAF::Type::Tracking; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 15 | use CSAF::Type::Acknowledgments; | ||
| 16 | use CSAF::Type::Notes; | ||
| 17 | use CSAF::Type::References; | ||
| 18 | |||
| 19 | extends 'CSAF::Type::Base'; | ||
| 20 | |||
| 21 | has category => (is => 'rw', default => 'csaf_base', required => 1); | ||
| 22 | has csaf_version => (is => 'rw', default => '2.0'); | ||
| 23 | has lang => (is => 'rw', default => 'en', coerce => sub { (my $lang = $_[0]) =~ tr /_/-/; $lang }); | ||
| 24 | has title => (is => 'rw'); | ||
| 25 | has source_lang => (is => 'rw', coerce => sub { (my $lang = $_[0]) =~ tr /_/-/; $lang }); | ||
| 26 | |||
| 27 | sub aggregate_severity { | ||
| 28 | my ($self, %params) = @_; | ||
| 29 | $self->{aggregate_severity} ||= CSAF::Type::AggregateSeverity->new(%params); | ||
| 30 | } | ||
| 31 | |||
| 32 | sub distribution { | ||
| 33 | my ($self, %params) = @_; | ||
| 34 | $self->{distribution} ||= CSAF::Type::Distribution->new(%params); | ||
| 35 | } | ||
| 36 | |||
| 37 | sub tracking { | ||
| 38 | my ($self, %params) = @_; | ||
| 39 | $self->{tracking} ||= CSAF::Type::Tracking->new(%params); | ||
| 40 | } | ||
| 41 | |||
| 42 | sub publisher { | ||
| 43 | my ($self, %params) = @_; | ||
| 44 | $self->{publisher} ||= CSAF::Type::Publisher->new(%params); | ||
| 45 | } | ||
| 46 | |||
| 47 | sub acknowledgments { | ||
| 48 | my $self = shift; | ||
| 49 | $self->{acknowledgments} ||= CSAF::Type::Acknowledgments->new(@_); | ||
| 50 | } | ||
| 51 | |||
| 52 | sub notes { | ||
| 53 | my $self = shift; | ||
| 54 | $self->{notes} ||= CSAF::Type::Notes->new(@_); | ||
| 55 | } | ||
| 56 | |||
| 57 | sub references { | ||
| 58 | my $self = shift; | ||
| 59 | $self->{references} ||= CSAF::Type::References->new(@_); | ||
| 60 | } | ||
| 61 | |||
| 62 | sub TO_CSAF { | ||
| 63 | |||
| 64 | my $self = shift; | ||
| 65 | |||
| 66 | # TODO | ||
| 67 | Carp::croak 'Missing document title' unless $self->title; | ||
| 68 | |||
| 69 | my $output = { | ||
| 70 | category => $self->category, | ||
| 71 | csaf_version => $self->csaf_version, | ||
| 72 | distribution => $self->distribution, | ||
| 73 | publisher => $self->publisher, | ||
| 74 | title => $self->title, | ||
| 75 | tracking => $self->tracking, | ||
| 76 | lang => $self->lang, | ||
| 77 | }; | ||
| 78 | |||
| 79 | if (@{$self->acknowledgments->items}) { | ||
| 80 | $output->{acknowledgments} = $self->acknowledgments; | ||
| 81 | } | ||
| 82 | |||
| 83 | if (@{$self->notes->items}) { | ||
| 84 | $output->{notes} = $self->notes; | ||
| 85 | } | ||
| 86 | |||
| 87 | if ($self->aggregate_severity->text || $self->aggregate_severity->namespace) { | ||
| 88 | $output->{aggregate_severity} = $self->aggregate_severity; | ||
| 89 | } | ||
| 90 | |||
| 91 | if (@{$self->references->items}) { | ||
| 92 | $output->{references} = $self->references; | ||
| 93 | } | ||
| 94 | |||
| 95 | $output->{source_lang} = $self->source_lang if ($self->source_lang); | ||
| 96 | |||
| 97 | return $output; | ||
| 98 | |||
| 99 | } | ||
| 100 | |||
| 101 | 1; | ||
| 102 | |||
| 103 | __END__ | ||