| 1 | package XML::NewsML_G2::Writer; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # $Id: Writer.pm 47068 2013-07-03 12:17:55Z apatecgortan $ | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 12 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use DateTime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 12 | ▶ | use DateTime::Format::XSD; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 12 | ▶ | use XML::NewsML_G2::Scheme_Manager; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 12 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 12 | has 'news_item', isa => 'XML::NewsML_G2::News_Item', is => 'ro', required => 1; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 12 | has 'encoding', isa => 'Str', is => 'ro', default => 'utf-8'; | |||||||||||||||||||||||||||
| 14 | 12 | has 'generator', isa => 'Str', is => 'ro', default => __PACKAGE__; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 12 | has 'scheme_manager', isa => 'XML::NewsML_G2::Scheme_Manager', is => 'ro', lazy => 1, builder => '_build_scheme_manager'; | |||||||||||||||||||||||||||
| 17 | 12 | has 'doc', isa => 'XML::LibXML::Document', is => 'ro', lazy=> 1, builder => '_build_doc'; | |||||||||||||||||||||||||||
| 18 | 5 | ▶ | has '_formatter', is => 'ro', default => sub {DateTime::Format::XSD->new()}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 12 | has 'g2_ns', isa => 'Str', is => 'ro', default => 'http://iptc.org/std/nar/2006-10-01/'; | |||||||||||||||||||||||||||
| 21 | 12 | has 'xhtml_ns', isa => 'Str', is => 'ro', default => 'http://www.w3.org/1999/xhtml'; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 12 | has 'g2_version', isa => 'Str', is => 'ro'; | |||||||||||||||||||||||||||
| 24 | 12 | has 'schema_location', isa => 'Str', is => 'ro'; | |||||||||||||||||||||||||||
| 25 | 12 | has 'g2_catalog_url', isa => 'Str', is => 'ro'; | |||||||||||||||||||||||||||
| 26 | has 'g2_catalog_schemes', isa => 'HashRef', is => 'ro', default => sub { | ||||||||||||||||||||||||||||
| 27 | 5 | ▶ | {isrol => undef, nprov => undef, ninat => undef, stat => undef, sig => undef, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 12 | genre => undef, isin => undef, medtop => undef, iso3166_1a2 => 'iso3166-1a2'} }; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # builders | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub _build_doc { | ||||||||||||||||||||||||||||
| 33 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_doc: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 5 | return XML::LibXML->createDocument('1.0', $self->encoding); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | sub _build_scheme_manager { | ||||||||||||||||||||||||||||
| 38 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_build_scheme_manager: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 2 | return XML::NewsML_G2::Scheme_Manager->new(); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # DOM creating methods | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | sub _create_root_element { | ||||||||||||||||||||||||||||
| 45 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_create_root_element: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 5 | my $root = $self->doc->createElementNS($self->g2_ns, 'newsItem'); | |||||||||||||||||||||||||||
| 47 | 5 | $self->doc->setDocumentElement($root); | |||||||||||||||||||||||||||
| 48 | 5 | $root->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation', $self->schema_location); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 5 | $root->setAttribute('standard', 'NewsML-G2'); | |||||||||||||||||||||||||||
| 51 | 5 | $root->setAttribute('standardversion', $self->g2_version); | |||||||||||||||||||||||||||
| 52 | 5 | $root->setAttribute('conformance', 'power'); | |||||||||||||||||||||||||||
| 53 | 5 | $root->setAttribute('xml:lang', $self->news_item->language); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 5 | $root->setAttribute('guid', $self->news_item->guid); | |||||||||||||||||||||||||||
| 56 | 5 | $root->setAttribute('version', $self->news_item->doc_version); | |||||||||||||||||||||||||||
| 57 | 5 | return $root; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | sub _create_catalogs { | ||||||||||||||||||||||||||||
| 61 | 4 | ▶ | my ($self, $root) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_create_catalogs: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 4 | my %catalogs = ($self->g2_catalog_url => 1); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 4 | my $cat; | |||||||||||||||||||||||||||
| 66 | 4 | foreach my $scheme ($self->scheme_manager->get_all_schemes()) { | |||||||||||||||||||||||||||
| 67 | 45 | ▶ | if (my $catalog = $scheme->catalog) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 68 | 36 | $catalogs{$catalog} = 1; | |||||||||||||||||||||||||||
| 69 | } elsif ($scheme) { | ||||||||||||||||||||||||||||
| 70 | 9 | ▶ | $root->appendChild($cat = $self->create_element('catalog')) unless $cat; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 9 | $cat->appendChild($self->create_element('scheme', alias => $scheme->alias, uri => $scheme->uri)); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 4 | foreach my $url (sort keys %catalogs) { | |||||||||||||||||||||||||||
| 76 | 4 | $root->appendChild($self->create_element('catalogRef', href => $url)); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 4 | return; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | sub _create_rights_info { | ||||||||||||||||||||||||||||
| 83 | 5 | ▶ | my ($self, $root) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_create_rights_info: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 84 | 5 | my $ri = $self->create_element('rightsInfo'); | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 5 | $ri->appendChild (my $crh = $self->create_element('copyrightHolder')); | |||||||||||||||||||||||||||
| 87 | 5 | $self->scheme_manager->add_qcode_or_literal($crh, 'nprov', $self->news_item->provider->qcode); | |||||||||||||||||||||||||||
| 88 | 5 | $crh->appendChild($self->create_element('name', _text => $self->news_item->provider->name)); | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 5 | my $notice = $self->news_item->provider->notice; | |||||||||||||||||||||||||||
| 91 | 5 | ▶ | $ri->appendChild($self->create_element('copyrightNotice', _text => $notice)) if $notice; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 5 | $root->appendChild($ri); | |||||||||||||||||||||||||||
| 94 | 5 | return; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | sub _create_item_meta { | ||||||||||||||||||||||||||||
| 98 | 5 | ▶ | my ($self, $root) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_create_item_meta: called CC=9 SCAR=40.5
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 5 | my $im = $self->create_element('itemMeta'); | |||||||||||||||||||||||||||
| 101 | 5 | $im->appendChild(my $ic = $self->create_element('itemClass')); | |||||||||||||||||||||||||||
| 102 | 5 | $self->scheme_manager->add_qcode($ic, 'ninat', 'text'); | |||||||||||||||||||||||||||
| 103 | 5 | $im->appendChild(my $p = $self->create_element('provider')); | |||||||||||||||||||||||||||
| 104 | 5 | $self->scheme_manager->add_qcode_or_literal($p, 'nprov', $self->news_item->provider->qcode); | |||||||||||||||||||||||||||
| 105 | 5 | $p->appendChild($self->create_element('name', _text => $self->news_item->provider->name)); | |||||||||||||||||||||||||||
| 106 | 5 | $im->appendChild($self->create_element('versionCreated', _text => $self->_formatter->format_datetime(DateTime->now(time_zone => 'local')))); | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ($self->news_item->embargo) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 0 | my $e = $self->_formatter->format_datetime($self->news_item->embargo); | |||||||||||||||||||||||||||
| 110 | 0 | $im->appendChild($self->create_element('embargoed', _text => $e)); | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | $im->appendChild(my $ps = $self->create_element('pubStatus')); | |||||||||||||||||||||||||||
| 114 | 0 | $self->scheme_manager->add_qcode($ps, 'stat', $self->news_item->doc_status); | |||||||||||||||||||||||||||
| 115 | 0 | $im->appendChild($self->create_element('generator', versioninfo => XML::NewsML_G2->VERSION, _text => $self->generator)); | |||||||||||||||||||||||||||
| 116 | 0 | ▶ | if ($self->news_item->has_service) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 0 | $im->appendChild(my $svc = $self->create_element('service')); | |||||||||||||||||||||||||||
| 118 | 0 | $self->scheme_manager->add_qcode($svc, 'svc', $self->news_item->service->qcode); | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | $svc->appendChild($self->create_element('name', _text => $self->news_item->service->name)); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if ($self->news_item->embargo_text) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | $im->appendChild(my $e = $self->create_element('edNote', _text => $self->news_item->embargo_text)); | |||||||||||||||||||||||||||
| 125 | 0 | $self->scheme_manager->add_role($e, 'role', 'embargotext'); | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if ($self->news_item->closing) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | $im->appendChild(my $e = $self->create_element('edNote', _text => $self->news_item->closing)); | |||||||||||||||||||||||||||
| 129 | 0 | $self->scheme_manager->add_role($e, 'role', 'closing'); | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | 0 | ▶ | if ($self->news_item->note) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 0 | $im->appendChild(my $e = $self->create_element('edNote', _text => $self->news_item->note)); | |||||||||||||||||||||||||||
| 133 | 0 | $self->scheme_manager->add_role($e, 'role', 'note'); | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if ($self->news_item->doc_version > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 0 | $im->appendChild(my $s = $self->create_element('signal')); | |||||||||||||||||||||||||||
| 138 | 0 | $self->scheme_manager->add_qcode($s, 'sig', 'correction'); | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | foreach (@{$self->news_item->indicators}) { | |||||||||||||||||||||||||||
| 142 | 0 | $im->appendChild(my $s = $self->create_element('signal')); | |||||||||||||||||||||||||||
| 143 | 0 | $self->scheme_manager->add_qcode($s, 'ind', lc); | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | ▶ | $im->appendChild($self->create_element('link', rel => 'irel:seeAlso', residref => $self->news_item->see_also)) if ($self->news_item->see_also); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | $root->appendChild($im); | |||||||||||||||||||||||||||
| 149 | 0 | return; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | sub _create_hierarchy { | ||||||||||||||||||||||||||||
| 153 | # my ($self, $node, $schema) = @_; | ||||||||||||||||||||||||||||
| 154 | # code moved to Writer_2_9 | ||||||||||||||||||||||||||||
| 155 | 0 | ▶ | return; | ||||||||||||||||||||||||||
|
Subroutine
_create_hierarchy: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | sub _create_subjects_desk { | ||||||||||||||||||||||||||||
| 159 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_create_subjects_desk: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 160 | 0 | my @res; | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 0 | ▶ | push @res, $self->doc->createComment('desks') if $self->news_item->has_desks; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | 0 | foreach (@{$self->news_item->desks}) { | |||||||||||||||||||||||||||
| 164 | 0 | push @res, my $s = $self->create_element('subject', type => 'cpnat:abstract'); | |||||||||||||||||||||||||||
| 165 | 0 | $self->scheme_manager->add_qcode_or_literal($s, 'desk', $_->qcode); | |||||||||||||||||||||||||||
| 166 | 0 | $s->appendChild($self->create_element('name', _text => $_->name)); | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | 0 | return @res; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | sub _create_subjects_media_topic { | ||||||||||||||||||||||||||||
| 172 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_create_subjects_media_topic: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 173 | 0 | my @res; | |||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 0 | ▶ | push @res, $self->doc->createComment('media topics') if $self->news_item->has_media_topics; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 0 | foreach my $mt_qcode (sort keys %{$self->news_item->media_topics}) { | |||||||||||||||||||||||||||
| 177 | 0 | my $mt = $self->news_item->media_topics->{$mt_qcode}; | |||||||||||||||||||||||||||
| 178 | 0 | ▶ | my $why = $mt->direct ? 'why:direct' : 'why:ancestor'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | 0 | push @res, my $s = $self->create_element('subject', type => 'cpnat:abstract', why => $why); | |||||||||||||||||||||||||||
| 180 | 0 | $self->scheme_manager->add_qcode_or_literal($s, 'medtop', $mt->qcode); | |||||||||||||||||||||||||||
| 181 | 0 | $s->appendChild($self->create_element('name', _text => $mt->name)); | |||||||||||||||||||||||||||
| 182 | 0 | foreach my $lang (sort keys %{$mt->translations}) { | |||||||||||||||||||||||||||
| 183 | 0 | $s->appendChild($self->create_element('name', 'xml:lang' => $lang, _text => $mt->translations->{$lang})); | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | 0 | ▶ | if ($mt->parent) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 0 | $s->appendChild(my $b = $self->create_element('broader')); | |||||||||||||||||||||||||||
| 187 | 0 | $self->scheme_manager->add_qcode_or_literal($b, 'medtop', $mt->parent->qcode); | |||||||||||||||||||||||||||
| 188 | 0 | my $hierarchy = $self->_create_hierarchy($mt, 'medtop'); | |||||||||||||||||||||||||||
| 189 | 0 | ▶ | $b->appendChild($hierarchy) if $hierarchy; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | 0 | return @res; | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | sub _create_subjects_location { | ||||||||||||||||||||||||||||
| 196 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_create_subjects_location: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 197 | 0 | my @res; | |||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 0 | ▶ | push @res, $self->doc->createComment('locations') if $self->news_item->has_locations; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | foreach my $l (sort {$b->relevance <=> $a->relevance} values %{$self->news_item->locations}) { | |||||||||||||||||||||||||||
| 202 | 0 | ▶ | my $why = $l->direct ? 'why:direct' : 'why:ancestor'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 0 | push @res, my $s = $self->create_element('subject', type => 'cpnat:geoArea', relevance => $l->relevance, why => $why); | |||||||||||||||||||||||||||
| 204 | 0 | $self->scheme_manager->add_qcode_or_literal($s, 'geo', $l->qcode); | |||||||||||||||||||||||||||
| 205 | 0 | $s->appendChild($self->create_element('name', _text => $l->name)); | |||||||||||||||||||||||||||
| 206 | 0 | ▶ | if ($l->iso_code) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 0 | $s->appendChild(my $sa = $self->create_element('sameAs')); | |||||||||||||||||||||||||||
| 208 | 0 | $self->scheme_manager->add_qcode_or_literal($sa, 'iso3166_1a2', $l->iso_code); | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if ($l->parent) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | 0 | $s->appendChild(my $b = $self->create_element('broader')); | |||||||||||||||||||||||||||
| 212 | 0 | $self->scheme_manager->add_qcode_or_literal($b, 'geo', $l->parent->qcode); | |||||||||||||||||||||||||||
| 213 | 0 | my $hierarchy = $self->_create_hierarchy($l, 'apageo'); | |||||||||||||||||||||||||||
| 214 | 0 | ▶ | $b->appendChild($hierarchy) if $hierarchy; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | 0 | return @res; | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | sub _create_subjects_organisation { | ||||||||||||||||||||||||||||
| 221 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_create_subjects_organisation: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 222 | 0 | my @res; | |||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 0 | ▶ | push @res, $self->doc->createComment('organisations') if $self->news_item->has_organisations; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 0 | foreach my $org (@{$self->news_item->organisations}) { | |||||||||||||||||||||||||||
| 226 | 0 | push @res, my $o = $self->create_element('subject', type => 'cpnat:organisation'); | |||||||||||||||||||||||||||
| 227 | 0 | $self->scheme_manager->add_qcode_or_literal($o, 'org', $org->qcode); | |||||||||||||||||||||||||||
| 228 | 0 | $o->appendChild($self->create_element('name', _text => $org->name)); | |||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | 0 | return @res; | |||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | sub _create_subjects_topic { | ||||||||||||||||||||||||||||
| 234 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_create_subjects_topic: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 235 | 0 | my @res; | |||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 0 | ▶ | push @res, $self->doc->createComment('topics') if $self->news_item->has_topics; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 0 | foreach my $topic (@{$self->news_item->topics}) { | |||||||||||||||||||||||||||
| 240 | 0 | push @res, my $t = $self->create_element('subject', type => 'cpnat:abstract'); | |||||||||||||||||||||||||||
| 241 | 0 | $self->scheme_manager->add_qcode_or_literal($t, 'topic', $topic->qcode); | |||||||||||||||||||||||||||
| 242 | 0 | $t->appendChild($self->create_element('name', _text => $topic->name)); | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 0 | return @res; | |||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | sub _create_subjects_product { | ||||||||||||||||||||||||||||
| 249 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_create_subjects_product: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 250 | 0 | my @res; | |||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 0 | ▶ | push @res, $self->doc->createComment('products') if $self->news_item->has_products; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 0 | foreach my $product (@{$self->news_item->products}) { | |||||||||||||||||||||||||||
| 255 | 0 | push @res, my $p = $self->create_element('subject', type => 'cpnat:object'); | |||||||||||||||||||||||||||
| 256 | 0 | ▶ | if ($product->isbn) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 257 | 0 | $self->scheme_manager->add_qcode_or_literal($p, 'isbn', $product->isbn); | |||||||||||||||||||||||||||
| 258 | } elsif ($product->ean) { | ||||||||||||||||||||||||||||
| 259 | 0 | $self->scheme_manager->add_qcode_or_literal($p, 'ean', $product->ean); | |||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 0 | $p->appendChild($self->create_element('name', _text => $product->name)); | |||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 0 | return @res; | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | sub _create_subjects { | ||||||||||||||||||||||||||||
| 270 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_create_subjects: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 271 | 0 | my @res; | |||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 0 | push @res, $self->_create_subjects_desk(); | |||||||||||||||||||||||||||
| 274 | 0 | push @res, $self->_create_subjects_media_topic(); | |||||||||||||||||||||||||||
| 275 | 0 | push @res, $self->_create_subjects_location(); | |||||||||||||||||||||||||||
| 276 | 0 | push @res, $self->_create_subjects_organisation(); | |||||||||||||||||||||||||||
| 277 | 0 | push @res, $self->_create_subjects_topic(); | |||||||||||||||||||||||||||
| 278 | 0 | push @res, $self->_create_subjects_product(); | |||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 0 | return @res; | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | sub _create_asserts_organisation { | ||||||||||||||||||||||||||||
| 284 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_create_asserts_organisation: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 0 | my @res; | |||||||||||||||||||||||||||
| 287 | 0 | ▶ | push @res, $self->doc->createComment('organisations') if $self->news_item->has_organisations; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 0 | foreach my $org (@{$self->news_item->organisations}) { | |||||||||||||||||||||||||||
| 290 | 0 | push @res, my $a = $self->create_element('assert'); | |||||||||||||||||||||||||||
| 291 | 0 | $self->scheme_manager->add_qcode_or_literal($a, 'org', $org->qcode); | |||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | 0 | $a->appendChild($self->create_element('name', _text => $org->name)); | |||||||||||||||||||||||||||
| 294 | 0 | foreach (@{$org->isins}) { | |||||||||||||||||||||||||||
| 295 | 0 | $a->appendChild(my $sa = $self->create_element('sameAs')); | |||||||||||||||||||||||||||
| 296 | 0 | $self->scheme_manager->add_qcode_or_literal($sa, 'isin', $_); | |||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | 0 | ▶ | if ($org->has_websites) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 299 | 0 | $a->appendChild(my $od = $self->create_element('organisationDetails')); | |||||||||||||||||||||||||||
| 300 | 0 | $od->appendChild(my $ci = $self->create_element('contactInfo')); | |||||||||||||||||||||||||||
| 301 | 0 | $ci->appendChild($self->create_element('web', _text => $_)) foreach @{$org->websites}; | |||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | 0 | ▶ | if ($self->scheme_manager->crel) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | 0 | my $crel_alias = $self->scheme_manager->crel->alias; | |||||||||||||||||||||||||||
| 305 | 0 | $a->appendChild($self->create_element('related', rel => "$crel_alias:index", literal => $_)) foreach (@{$org->indices}); | |||||||||||||||||||||||||||
| 306 | 0 | $a->appendChild($self->create_element('related', rel => "$crel_alias:exchange", literal => $_)) foreach (@{$org->stock_exchanges}); | |||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | 0 | return @res; | |||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | sub _create_asserts { | ||||||||||||||||||||||||||||
| 313 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_create_asserts: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 314 | 0 | my @res; | |||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 0 | push @res, $self->_create_asserts_organisation(); | |||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 0 | return @res; | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | sub _create_content_meta { | ||||||||||||||||||||||||||||
| 322 | 0 | ▶ | my ($self, $root) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_create_content_meta: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 0 | my $cm = $self->create_element('contentMeta'); | |||||||||||||||||||||||||||
| 325 | 0 | $cm->appendChild($self->create_element('urgency', _text => $self->news_item->priority)); | |||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 0 | ▶ | if ($self->news_item->content_created) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 328 | 0 | my $t = $self->_formatter->format_datetime($self->news_item->content_created); | |||||||||||||||||||||||||||
| 329 | 0 | $cm->appendChild($self->create_element('contentCreated', _text => $t)); | |||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | 0 | ▶ | if ($self->news_item->content_modified and $self->news_item->content_created != $self->news_item->content_modified) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->news_item->content_modified and $self->news_item->content_created != $self->news_item->content_modified
MC/DC0%0/2
$self->news_item->content_modified and $self->news_item->content_created != $self->news_item->content_modified
$self->news_item->content_modified
$self->news_item->content_created != $self->news_item->content_modified
Truth table0%0/3
A and B
A= $self->news_item->content_modifiedB= $self->news_item->content_created != $self->news_item->content_modified
| |||||||||||||||||||||||||||||
| 332 | 0 | my $t = $self->_formatter->format_datetime($self->news_item->content_modified); | |||||||||||||||||||||||||||
| 333 | 0 | $cm->appendChild($self->create_element('contentModified', _text => $t)); | |||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | 0 | foreach (@{$self->news_item->cities}) { | |||||||||||||||||||||||||||
| 337 | 0 | $cm->appendChild(my $loc = $self->create_element('located')); | |||||||||||||||||||||||||||
| 338 | 0 | $loc->appendChild($self->create_element('name', _text => $_)); | |||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||
| 341 | 0 | foreach (@{$self->news_item->sources}) { | |||||||||||||||||||||||||||
| 342 | 0 | ▶ | next if $_ eq uc $self->news_item->provider->qcode; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 343 | 0 | $cm->appendChild(my $i = $self->create_element('infoSource', literal => $_)); | |||||||||||||||||||||||||||
| 344 | 0 | $self->scheme_manager->add_role($i, 'isrol', 'originfo'); | |||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 0 | foreach (@{$self->news_item->authors}) { | |||||||||||||||||||||||||||
| 348 | 0 | $cm->appendChild($self->create_element('creator', literal => $_)); | |||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | 0 | ▶ | if ($self->news_item->message_id) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 352 | 0 | $cm->appendChild($self->create_element('altId', _text => $self->news_item->message_id)); | |||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | 0 | $cm->appendChild($self->create_element('language', tag => $self->news_item->language)); | |||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | 0 | foreach (@{$self->news_item->genres}) { | |||||||||||||||||||||||||||
| 358 | 0 | $cm->appendChild(my $gn = $self->create_element('genre')); | |||||||||||||||||||||||||||
| 359 | 0 | $self->scheme_manager->add_qcode_or_literal($gn, 'genre', $_->qcode); | |||||||||||||||||||||||||||
| 360 | 0 | $gn->appendChild($self->create_element('name', _text => $_->name)); | |||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 0 | my @subjects = $self->_create_subjects(); | |||||||||||||||||||||||||||
| 364 | 0 | $cm->appendChild($_) foreach (@subjects); | |||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | 0 | ▶ | if ($self->news_item->slugline) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 367 | 0 | $cm->appendChild($self->create_element('slugline', separator => $self->news_item->slugline_sep, _text => $self->news_item->slugline)); | |||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | 0 | $cm->appendChild(my $hl1 = $self->create_element('headline', _text => $self->news_item->title)); | |||||||||||||||||||||||||||
| 371 | 0 | $self->scheme_manager->add_role($hl1, 'hltype', 'title'); | |||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 0 | ▶ | if ($self->news_item->subtitle) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 374 | 0 | $cm->appendChild(my $hl2 = $self->create_element('headline', _text => $self->news_item->subtitle)); | |||||||||||||||||||||||||||
| 375 | 0 | $self->scheme_manager->add_role($hl2, 'hltype', 'subtitle'); | |||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | 0 | $root->appendChild($cm); | |||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | 0 | my @asserts = $self->_create_asserts(); | |||||||||||||||||||||||||||
| 381 | 0 | $root->appendChild($_) foreach @asserts; | |||||||||||||||||||||||||||
| 382 | 0 | return; | |||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | sub _create_content { | ||||||||||||||||||||||||||||
| 386 | 0 | ▶ | my ($self, $root) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_create_content: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | 0 | $root->appendChild(my $cs = $self->create_element('contentSet')); | |||||||||||||||||||||||||||
| 389 | 0 | my $inlinexml = $self->create_element('inlineXML', contenttype => 'application/xhtml+xml'); | |||||||||||||||||||||||||||
| 390 | 0 | my $html = $self->create_element('html', _ns => $self->xhtml_ns); | |||||||||||||||||||||||||||
| 391 | 0 | $html->appendChild(my $head = $self->create_element('head', _ns => $self->xhtml_ns)); | |||||||||||||||||||||||||||
| 392 | 0 | $head->appendChild($self->create_element('title', _ns => $self->xhtml_ns, _text => $self->news_item->title)); | |||||||||||||||||||||||||||
| 393 | 0 | $inlinexml->appendChild($html); | |||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | 0 | $html->appendChild(my $body = $self->create_element('body', _ns => $self->xhtml_ns)); | |||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | 0 | $body->appendChild($self->create_element('h1', _ns => $self->xhtml_ns, _text => $self->news_item->title)); | |||||||||||||||||||||||||||
| 398 | 0 | ▶ | $body->appendChild($self->create_element('h2', _ns => $self->xhtml_ns, _text => $self->news_item->subtitle)) if $self->news_item->subtitle; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | 0 | ▶ | my @paras = $self->news_item->paragraphs ? $self->news_item->paragraphs->getChildNodes() : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 401 | 0 | $body->appendChild($_) foreach (@paras); | |||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | 0 | $cs->appendChild($inlinexml); | |||||||||||||||||||||||||||
| 404 | 0 | return; | |||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | sub _import_iptc_catalog { | ||||||||||||||||||||||||||||
| 408 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_import_iptc_catalog: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | 5 | ▶ | while (my ($attr, $alias) = each %{$self->g2_catalog_schemes}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 411 | 45 | ▶ | $alias ||= $attr; | ||||||||||||||||||||||||||
|
Condition66%2/3
$alias ||= $attr
MC/DC0%0/2
$alias ||= $attr
$alias
$attr
Truth table66%2/3
A ||= B
A= $aliasB= $attr
| |||||||||||||||||||||||||||||
| 412 | 45 | ▶ | my $getter_setter = $self->scheme_manager->can($attr) or die "Unknown scheme '$attr'\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 413 | 45 | ▶ | next if ($getter_setter->($self->scheme_manager)); # attribute ist already set by user | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 414 | 45 | my $scheme = XML::NewsML_G2::Scheme->new(alias => $alias, catalog => $self->g2_catalog_url); | |||||||||||||||||||||||||||
| 415 | 45 | $getter_setter->($self->scheme_manager, $scheme); | |||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||
| 417 | 5 | return; | |||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | # public methods | ||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | sub create_element { | ||||||||||||||||||||||||||||
| 423 | 63 | ▶ | my ($self, $name, %attrs) = @_; | ||||||||||||||||||||||||||
|
Subroutine
create_element: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 424 | 63 | my $text = delete $attrs{_text}; | |||||||||||||||||||||||||||
| 425 | 63 | ▶ | my $ns = delete $attrs{_ns} || $self->g2_ns; | ||||||||||||||||||||||||||
|
Condition66%2/3
delete $attrs{'_ns'} || $self->g2_ns
MC/DC0%0/2
delete $attrs{'_ns'} || $self->g2_ns
delete $attrs{'_ns'}
$self->g2_ns
Truth table66%2/3
A || B
A= delete $attrs{'_ns'}B= $self->g2_ns
| |||||||||||||||||||||||||||||
| 426 | 63 | my $elem = $self->doc->createElementNS($ns, $name); | |||||||||||||||||||||||||||
| 427 | 63 | ▶ | while (my ($k, $v) = each %attrs) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 428 | 41 | $elem->setAttribute($k, $v); | |||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||
| 430 | 63 | ▶ | $elem->appendChild($self->doc->createTextNode($text)) if $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 431 | 63 | return $elem; | |||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | sub create_dom { | ||||||||||||||||||||||||||||
| 435 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
create_dom: called CC=1 SCAR=0.4
Pod
documented
| |||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | 5 | $self->_import_iptc_catalog(); | |||||||||||||||||||||||||||
| 438 | 5 | my $root = $self->_create_root_element(); | |||||||||||||||||||||||||||
| 439 | 5 | $self->_create_catalogs($root); | |||||||||||||||||||||||||||
| 440 | 5 | $self->_create_rights_info($root); | |||||||||||||||||||||||||||
| 441 | 5 | $self->_create_item_meta($root); | |||||||||||||||||||||||||||
| 442 | 0 | $self->_create_content_meta($root); | |||||||||||||||||||||||||||
| 443 | 0 | $self->_create_content($root); | |||||||||||||||||||||||||||
| 444 | 0 | return $self->doc; | |||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | 12 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | 12 | 1; | |||||||||||||||||||||||||||
| 452 | __END__ | ||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | =head1 NAME | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | XML::NewsML_G2::Writer - base class for XML DOM tree creation | ||||||||||||||||||||||||||||
| 457 | conforming to NewsML-G2 | ||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | =for test_synopsis | ||||||||||||||||||||||||||||
| 460 | my ($ni, $sm); | ||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||
| 464 | my $w = XML::NewsML_G2::Writer_2_12->new | ||||||||||||||||||||||||||||
| 465 | (news_item => $ni, scheme_manager => $sm); | ||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||
| 467 | my $p = $w->create_element('p', class => 'main', _text => 'blah'); | ||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | my $dom = $w->create_dom(); | ||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||
| 471 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | This module acts as a NewsML-G2 version-independent base | ||||||||||||||||||||||||||||
| 474 | class. Instead of using this class, use the most current subclass, | ||||||||||||||||||||||||||||
| 475 | e.g. L<XML::NewsML_G2::Writer_2_12>. | ||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||
| 477 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | =over 4 | ||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | =item news_item | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | L<XML::NewsML_G2::News_Item> instance used to create the output document | ||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | =item encoding | ||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||
| 487 | Encoding used to create the output document, defaults to utf-8 | ||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | =item generator | ||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | String used in output as the generator program name | ||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | =item scheme_manager | ||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | L<XML::NewsML_G2::Scheme_Manager> instance used to create qcodes | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | =item doc | ||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||
| 499 | L<XML::LibXML::Document> instance used to create the output document | ||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | =item g2_ns | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | XML Namespace of NewsML-G2 | ||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | =item xhtml_n2 | ||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||
| 507 | XML Namespace of XHTML | ||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | =item g2_version | ||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | Specified by subclass. | ||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | =item schema_location | ||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | Specified by subclass. | ||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||
| 517 | =item g2_catalog_url | ||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||
| 519 | URL of the G2 catalog, specified by subclass. | ||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||
| 521 | =item g2_catalog_schemes | ||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||
| 523 | Reference to a hash of schemes that are covered by the G2 catalog. If | ||||||||||||||||||||||||||||
| 524 | the value is undefined, it defaults to the name of the scheme. | ||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | =back | ||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||
| 528 | =head1 METHODS | ||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||
| 530 | =over 4 | ||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||
| 532 | =item create_element | ||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | Helper method that creates XML elements, e.g. to be used in the | ||||||||||||||||||||||||||||
| 535 | C<paragraphs> element of the L<XML::NewsML_G2::News_Item>. | ||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | =item create_dom | ||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||
| 539 | Returns the L<XML::LibXML::Document> element containing the requested | ||||||||||||||||||||||||||||
| 540 | output. Be careful I<not> to use C<< $dom->serialize(2) >> for formatting, | ||||||||||||||||||||||||||||
| 541 | as this creates invalid NewsML-G2 files because it adds whitespace | ||||||||||||||||||||||||||||
| 542 | where none is allowed (e.g. in xs:dateTime elements). | ||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | =back | ||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||
| 548 | Philipp Gortan C<< <philipp.gortan@apa.at> >> | ||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||
| 550 | =head1 LICENCE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||
| 552 | Copyright (c) 2013, APA-IT. All rights reserved. | ||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||
| 554 | See L<XML::NewsML_G2> for the license. | ||||||||||||||||||||||||||||