File Coverage

blib/lib/XML/NewsML_G2/Substancial_Item.pm
Criterion Covered Total %
statement 15 15 100.0
branch 5 6 83.3
condition n/a
subroutine 4 4 100.0
pod 2 2 100.0
total 26 27 96.3


line stmt bran cond sub pod time code
1             package XML::NewsML_G2::Substancial_Item;
2              
3 18     18   9283 use Moose;
  18         40  
  18         103  
4 18     18   107506 use namespace::autoclean;
  18         39  
  18         151  
5              
6             # document properties
7             extends 'XML::NewsML_G2::AnyItem';
8              
9             has 'title', isa => 'Str', is => 'ro', required => 1;
10             has 'subtitle', isa => 'Str', is => 'rw';
11             has 'summary', isa => 'Str', is => 'rw';
12              
13             has 'media_topics',
14             isa => 'HashRef[XML::NewsML_G2::Media_Topic]',
15             is => 'rw',
16             default => sub { {} },
17             traits => ['Hash'],
18             handles => { has_media_topics => 'count' };
19             has 'concepts',
20             isa => 'HashRef[XML::NewsML_G2::Concept]',
21             is => 'rw',
22             default => sub { {} },
23             traits => ['Hash'],
24             handles => { has_concepts => 'count' };
25              
26             sub add_media_topic {
27 101     101 1 317 my ( $self, $mt ) = @_;
28 101 100       2951 return if exists $self->media_topics->{ $mt->qcode };
29 76         1990 $self->media_topics->{ $mt->qcode } = $mt;
30 76 100       1933 $self->add_media_topic( $mt->parent ) if ( $mt->parent );
31 76         168 return 1;
32             }
33              
34             sub add_concept {
35 2     2 1 6 my ( $self, $concept ) = @_;
36 2 50       67 return if exists $self->concepts->{ $concept->uid };
37 2         61 $self->concepts->{ $concept->uid } = $concept;
38 2         6 return 1;
39             }
40              
41             __PACKAGE__->meta->make_immutable;
42              
43             1;
44             __END__
45              
46             =head1 NAME
47              
48             XML::NewsML_G2::Substancial_Item - base class for substancial item types
49              
50             =head1 DESCRIPTION
51              
52             This module acts as an abstract base class for substancial NewsML-G2 item types
53             as there are News_Items and Concept_Items. Instead of using this class, use the most appropriate subclass.
54              
55             =head1 ATTRIBUTES
56              
57             =over 4
58              
59             =item media_topics
60              
61             Hash mapping qcodes to L<XML::NewsML_G2::Media_Topic> instances
62              
63             =item concepts
64              
65             Hash mapping generated uids to L<XML::NewsML_G2::Concept> instances
66              
67             =back
68              
69             =head1 METHODS
70              
71             =over 4
72              
73             =item add_media_topic
74              
75             Add a new L<XML::NewsML_G2::MediaTopic> instance
76              
77             =item add_concept
78              
79             Add a new L<XML::NewsML_G2::Concept> instance
80              
81             =back
82              
83             =head1 AUTHOR
84              
85             Christian Eder C<< <christian.eder@apa.at> >>
86              
87             =head1 LICENCE AND COPYRIGHT
88              
89             Copyright (c) 2019, APA-IT. All rights reserved.
90              
91             See L<XML::NewsML_G2> for the license.