| 1 | package XML::NewsML_G2::Writer; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 26 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 26 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 26 | ▶ | use Moose::Util; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 26 | ▶ | use DateTime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 26 | ▶ | use DateTime::Format::XSD; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 26 | ▶ | use XML::NewsML_G2::Scheme; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 26 | ▶ | use XML::NewsML_G2::Scheme_Manager; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 26 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 26 | has '_root_item', is => 'ro', lazy => 1, builder => '_build__root_item'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 26 | has 'encoding', isa => 'Str', is => 'ro', default => 'utf-8'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 26 | has 'scheme_manager', | |||||||||||||||||||||||||||
| 17 | isa => 'XML::NewsML_G2::Scheme_Manager', | ||||||||||||||||||||||||||||
| 18 | is => 'ro', | ||||||||||||||||||||||||||||
| 19 | lazy => 1, | ||||||||||||||||||||||||||||
| 20 | builder => '_build_scheme_manager'; | ||||||||||||||||||||||||||||
| 21 | 26 | has 'doc', | |||||||||||||||||||||||||||
| 22 | isa => 'XML::LibXML::Document', | ||||||||||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||||||||
| 24 | lazy => 1, | ||||||||||||||||||||||||||||
| 25 | builder => '_build_doc'; | ||||||||||||||||||||||||||||
| 26 | 81 | ▶ | has '_formatter', is => 'ro', default => sub { DateTime::Format::XSD->new() }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 26 | has 'g2_ns', | |||||||||||||||||||||||||||
| 29 | isa => 'Str', | ||||||||||||||||||||||||||||
| 30 | is => 'ro', | ||||||||||||||||||||||||||||
| 31 | default => 'http://iptc.org/std/nar/2006-10-01/'; | ||||||||||||||||||||||||||||
| 32 | 26 | has 'xhtml_ns', | |||||||||||||||||||||||||||
| 33 | isa => 'Str', | ||||||||||||||||||||||||||||
| 34 | is => 'ro', | ||||||||||||||||||||||||||||
| 35 | default => 'http://www.w3.org/1999/xhtml'; | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 26 | has 'g2_version', isa => 'Str', is => 'ro', default => '2.18'; | |||||||||||||||||||||||||||
| 38 | 26 | has '_root_node_name', isa => 'Str', is => 'ro', default => 'newsItem'; | |||||||||||||||||||||||||||
| 39 | 26 | has '_nature_qcode_prefix', isa => 'Str', is => 'ro', default => 'ninat'; | |||||||||||||||||||||||||||
| 40 | 26 | has 'generator_version', | |||||||||||||||||||||||||||
| 41 | is => 'Str', | ||||||||||||||||||||||||||||
| 42 | is => 'ro', | ||||||||||||||||||||||||||||
| 43 | lazy => 1, | ||||||||||||||||||||||||||||
| 44 | builder => '_build_generator_version'; | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # attributes set by version-specific role | ||||||||||||||||||||||||||||
| 47 | 26 | has 'schema_location', isa => 'Str', is => 'ro'; | |||||||||||||||||||||||||||
| 48 | 26 | has 'g2_catalog_url', isa => 'Str', is => 'ro'; | |||||||||||||||||||||||||||
| 49 | 26 | has 'g2_catalog_schemes', | |||||||||||||||||||||||||||
| 50 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 51 | is => 'ro', | ||||||||||||||||||||||||||||
| 52 | lazy => 1, | ||||||||||||||||||||||||||||
| 53 | builder => '_build_g2_catalog_schemes'; | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # builders | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub _build__root_item { | ||||||||||||||||||||||||||
|
Subroutine
_build__root_item: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 58 | 0 | croak 'Override in subclass'; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 81 | ▶ | sub _build_g2_catalog_schemes { | ||||||||||||||||||||||||||
|
Subroutine
_build_g2_catalog_schemes: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 62 | return { | ||||||||||||||||||||||||||||
| 63 | 81 | isrol => undef, | |||||||||||||||||||||||||||
| 64 | nprov => undef, | ||||||||||||||||||||||||||||
| 65 | cinat => undef, | ||||||||||||||||||||||||||||
| 66 | ninat => undef, | ||||||||||||||||||||||||||||
| 67 | stat => undef, | ||||||||||||||||||||||||||||
| 68 | sig => undef, | ||||||||||||||||||||||||||||
| 69 | genre => undef, | ||||||||||||||||||||||||||||
| 70 | isin => undef, | ||||||||||||||||||||||||||||
| 71 | medtop => undef, | ||||||||||||||||||||||||||||
| 72 | crol => undef, | ||||||||||||||||||||||||||||
| 73 | drol => undef, | ||||||||||||||||||||||||||||
| 74 | pgrmod => undef, | ||||||||||||||||||||||||||||
| 75 | iso3166_1a2 => 'iso3166-1a2' | ||||||||||||||||||||||||||||
| 76 | }; | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 81 | ▶ | sub _build_doc { | ||||||||||||||||||||||||||
|
Subroutine
_build_doc: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 80 | 81 | my $self = shift; | |||||||||||||||||||||||||||
| 81 | 81 | return XML::LibXML->createDocument( '1.0', $self->encoding ); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 2 | ▶ | sub _build_scheme_manager { | ||||||||||||||||||||||||||
|
Subroutine
_build_scheme_manager: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 85 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 86 | 2 | return XML::NewsML_G2::Scheme_Manager->new(); | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 72 | ▶ | sub _build_generator_version { | ||||||||||||||||||||||||||
|
Subroutine
_build_generator_version: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 90 | 72 | return XML::NewsML_G2->VERSION; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | # Apply roles needed for writing | ||||||||||||||||||||||||||||
| 94 | 81 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 95 | 81 | my $self = shift; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 81 | ( my $ni_cls ) = reverse split( '::', $self->_root_item->meta->name ); | |||||||||||||||||||||||||||
| 98 | 81 | my $type_role = sprintf( 'XML::NewsML_G2::Role::Writer::%s', $ni_cls ); | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 81 | my $g2_version = $self->g2_version; | |||||||||||||||||||||||||||
| 101 | 81 | $g2_version =~ s/\./_/; | |||||||||||||||||||||||||||
| 102 | 81 | my $version_role = 'XML::NewsML_G2::Role::Writer_' . $g2_version; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 81 | Moose::Util::apply_all_roles( $self, $type_role, $version_role ); | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 81 | return; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | # DOM creating methods | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 207 | ▶ | sub _create_creator { | ||||||||||||||||||||||||||
|
Subroutine
_create_creator: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 112 | 207 | my ( $self, $creator ) = @_; | |||||||||||||||||||||||||||
| 113 | 207 | my $result = | |||||||||||||||||||||||||||
| 114 | $self->create_element( 'creator', _name_text => $creator->name ); | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 207 | ▶ | if ( $creator->kind ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 46 | my $rel = | |||||||||||||||||||||||||||
| 118 | $result->appendChild( | ||||||||||||||||||||||||||||
| 119 | $self->create_element( 'related', rel => 'crel:isA' ) ); | ||||||||||||||||||||||||||||
| 120 | 46 | $self->scheme_manager->add_qcode( $rel, 'gyibt', $creator->kind ); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | 207 | return $result; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 72 | ▶ | sub _create_root_element { | ||||||||||||||||||||||||||
|
Subroutine
_create_root_element: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 126 | 72 | my ($self) = @_; | |||||||||||||||||||||||||||
| 127 | 72 | my $root = | |||||||||||||||||||||||||||
| 128 | $self->doc->createElementNS( $self->g2_ns, $self->_root_node_name ); | ||||||||||||||||||||||||||||
| 129 | 72 | $self->doc->setDocumentElement($root); | |||||||||||||||||||||||||||
| 130 | 72 | $root->setAttributeNS( 'http://www.w3.org/2001/XMLSchema-instance', | |||||||||||||||||||||||||||
| 131 | 'xsi:schemaLocation', $self->schema_location ); | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 72 | $root->setAttribute( 'standard', 'NewsML-G2' ); | |||||||||||||||||||||||||||
| 134 | 72 | $root->setAttribute( 'standardversion', $self->g2_version ); | |||||||||||||||||||||||||||
| 135 | 72 | $root->setAttribute( 'conformance', 'power' ); | |||||||||||||||||||||||||||
| 136 | 72 | $root->setAttribute( 'xml:lang', $self->_root_item->language ); | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 72 | $root->setAttribute( 'guid', $self->_root_item->guid ); | |||||||||||||||||||||||||||
| 139 | 72 | $root->setAttribute( 'version', $self->_root_item->doc_version ); | |||||||||||||||||||||||||||
| 140 | 72 | return $root; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 65 | ▶ | sub _create_catalogs { | ||||||||||||||||||||||||||
|
Subroutine
_create_catalogs: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 144 | 65 | my ( $self, $root ) = @_; | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 65 | my %catalogs = ( $self->g2_catalog_url => 1 ); | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 65 | my $cat; | |||||||||||||||||||||||||||
| 149 | 65 | foreach my $scheme ( $self->scheme_manager->get_all_schemes() ) { | |||||||||||||||||||||||||||
| 150 | 1384 | ▶ | if ( my $catalog = $scheme->catalog ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 151 | 968 | $catalogs{$catalog} = 1; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | elsif ($scheme) { | ||||||||||||||||||||||||||||
| 154 | 416 | ▶ | $root->appendChild( $cat = $self->create_element('catalog') ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | unless $cat; | ||||||||||||||||||||||||||||
| 156 | 416 | $cat->appendChild( | |||||||||||||||||||||||||||
| 157 | $self->create_element( | ||||||||||||||||||||||||||||
| 158 | 'scheme', | ||||||||||||||||||||||||||||
| 159 | alias => $scheme->alias, | ||||||||||||||||||||||||||||
| 160 | uri => $scheme->uri | ||||||||||||||||||||||||||||
| 161 | ) | ||||||||||||||||||||||||||||
| 162 | ); | ||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 65 | foreach my $url ( sort keys %catalogs ) { | |||||||||||||||||||||||||||
| 167 | 108 | $root->appendChild( | |||||||||||||||||||||||||||
| 168 | $self->create_element( 'catalogRef', href => $url ) ); | ||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 65 | return; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 26 | ▶ | sub _create_copyright_holder_remoteinfo { | ||||||||||||||||||||||||||
|
Subroutine
_create_copyright_holder_remoteinfo: called CC=5 SCAR=16.5
| |||||||||||||||||||||||||||||
| 175 | 26 | my ( $self, $crh ) = @_; | |||||||||||||||||||||||||||
| 176 | 26 | ▶ | if ( my $remote_info = $self->news_item->copyright_holder->remote_info ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 25 | my %args; | |||||||||||||||||||||||||||
| 178 | 25 | ▶ | $args{reluri} = $remote_info->reluri if $remote_info->reluri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | 25 | ▶ | $args{href} = $remote_info->href if $remote_info->href; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | 25 | ▶ | $crh->appendChild( $self->create_element( 'remoteInfo', %args ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | if keys %args; | ||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | 26 | return; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 66 | ▶ | sub _create_item_meta_title { | ||||||||||||||||||||||||||
|
Subroutine
_create_item_meta_title: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 32 | ▶ | sub _create_teaser { | ||||||||||||||||||||||||||
|
Subroutine
_create_teaser: called CC=2 SCAR=8.4
| |||||||||||||||||||||||||||||
| 190 | 32 | my ( $self, $cm ) = @_; | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 32 | ▶ | if ( $self->news_item->teaser ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 0 | $cm->appendChild( | |||||||||||||||||||||||||||
| 194 | my $teaser = $self->create_element( | ||||||||||||||||||||||||||||
| 195 | 'description', _text => $self->news_item->teaser | ||||||||||||||||||||||||||||
| 196 | ) | ||||||||||||||||||||||||||||
| 197 | ); | ||||||||||||||||||||||||||||
| 198 | 0 | $self->scheme_manager->add_role( $teaser, 'drol', 'teaser' ); | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | 32 | return; | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 72 | ▶ | sub _create_item_meta { | ||||||||||||||||||||||||||
|
Subroutine
_create_item_meta: called CC=13 SCAR=25.7
| |||||||||||||||||||||||||||||
| 204 | 72 | my ( $self, $root ) = @_; | |||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 72 | my $im = $self->create_element('itemMeta'); | |||||||||||||||||||||||||||
| 207 | 72 | $im->appendChild( my $ic = $self->create_element('itemClass') ); | |||||||||||||||||||||||||||
| 208 | 72 | $self->scheme_manager->add_qcode( | |||||||||||||||||||||||||||
| 209 | $ic, | ||||||||||||||||||||||||||||
| 210 | $self->_nature_qcode_prefix, | ||||||||||||||||||||||||||||
| 211 | $self->_root_item->nature | ||||||||||||||||||||||||||||
| 212 | ); | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 72 | $im->appendChild( | |||||||||||||||||||||||||||
| 215 | my $p = $self->create_element( | ||||||||||||||||||||||||||||
| 216 | 'provider', _name_text => $self->_root_item->provider | ||||||||||||||||||||||||||||
| 217 | ) | ||||||||||||||||||||||||||||
| 218 | ); | ||||||||||||||||||||||||||||
| 219 | 72 | $self->scheme_manager->add_qcode_or_literal( $p, 'nprov', | |||||||||||||||||||||||||||
| 220 | $self->_root_item->provider->qcode ); | ||||||||||||||||||||||||||||
| 221 | 72 | $im->appendChild( | |||||||||||||||||||||||||||
| 222 | $self->create_element( | ||||||||||||||||||||||||||||
| 223 | 'versionCreated', | ||||||||||||||||||||||||||||
| 224 | _text => $self->_formatter->format_datetime( | ||||||||||||||||||||||||||||
| 225 | DateTime->now( time_zone => $self->_root_item->timezone ) | ||||||||||||||||||||||||||||
| 226 | ) | ||||||||||||||||||||||||||||
| 227 | ) | ||||||||||||||||||||||||||||
| 228 | ); | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 72 | ▶ | if ( $self->_root_item->embargo ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | 53 | my $e = | |||||||||||||||||||||||||||
| 232 | $self->_formatter->format_datetime( $self->_root_item->embargo ); | ||||||||||||||||||||||||||||
| 233 | 53 | $im->appendChild( $self->create_element( 'embargoed', _text => $e ) ); | |||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 72 | $im->appendChild( my $ps = $self->create_element('pubStatus') ); | |||||||||||||||||||||||||||
| 237 | 72 | $self->scheme_manager->add_qcode( $ps, 'stat', | |||||||||||||||||||||||||||
| 238 | $self->_root_item->doc_status ); | ||||||||||||||||||||||||||||
| 239 | 72 | $im->appendChild( | |||||||||||||||||||||||||||
| 240 | $self->create_element( | ||||||||||||||||||||||||||||
| 241 | 'generator', | ||||||||||||||||||||||||||||
| 242 | versioninfo => $self->generator_version, | ||||||||||||||||||||||||||||
| 243 | _text => 'XML::NewsML_G2' | ||||||||||||||||||||||||||||
| 244 | ) | ||||||||||||||||||||||||||||
| 245 | ); | ||||||||||||||||||||||||||||
| 246 | 72 | ▶ | if ( $self->_root_item->has_service ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | 53 | $im->appendChild( | |||||||||||||||||||||||||||
| 248 | my $svc = $self->create_element( | ||||||||||||||||||||||||||||
| 249 | 'service', _name_text => $self->_root_item->service | ||||||||||||||||||||||||||||
| 250 | ) | ||||||||||||||||||||||||||||
| 251 | ); | ||||||||||||||||||||||||||||
| 252 | 53 | $self->scheme_manager->add_qcode( $svc, 'svc', | |||||||||||||||||||||||||||
| 253 | $self->_root_item->service->qcode ); | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | 72 | $self->_create_item_meta_title($im); | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 72 | ▶ | if ( $self->_root_item->embargo_text ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | 53 | $im->appendChild( | |||||||||||||||||||||||||||
| 260 | my $e = $self->create_element( | ||||||||||||||||||||||||||||
| 261 | 'edNote', _text => $self->_root_item->embargo_text | ||||||||||||||||||||||||||||
| 262 | ) | ||||||||||||||||||||||||||||
| 263 | ); | ||||||||||||||||||||||||||||
| 264 | 53 | $self->scheme_manager->add_role( $e, 'role', 'embargotext' ); | |||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | 72 | ▶ | if ( $self->_root_item->closing ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 267 | 53 | $im->appendChild( | |||||||||||||||||||||||||||
| 268 | my $e = $self->create_element( | ||||||||||||||||||||||||||||
| 269 | 'edNote', _text => $self->_root_item->closing | ||||||||||||||||||||||||||||
| 270 | ) | ||||||||||||||||||||||||||||
| 271 | ); | ||||||||||||||||||||||||||||
| 272 | 53 | $self->scheme_manager->add_role( $e, 'role', 'closing' ); | |||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | 72 | ▶ | if ( $self->_root_item->note ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | 53 | $im->appendChild( | |||||||||||||||||||||||||||
| 276 | my $e = $self->create_element( | ||||||||||||||||||||||||||||
| 277 | 'edNote', _text => $self->_root_item->note | ||||||||||||||||||||||||||||
| 278 | ) | ||||||||||||||||||||||||||||
| 279 | ); | ||||||||||||||||||||||||||||
| 280 | 53 | $self->scheme_manager->add_role( $e, 'role', 'note' ); | |||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 72 | ▶ | if ( $self->_root_item->doc_version > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 284 | 0 | $im->appendChild( my $s = $self->create_element('signal') ); | |||||||||||||||||||||||||||
| 285 | 0 | $self->scheme_manager->add_qcode( $s, 'sig', 'correction' ); | |||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 72 | foreach ( @{ $self->_root_item->indicators } ) { | |||||||||||||||||||||||||||
| 289 | 104 | $im->appendChild( my $s = $self->create_element('signal') ); | |||||||||||||||||||||||||||
| 290 | 104 | $self->scheme_manager->add_qcode( $s, 'ind', lc ); | |||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | 72 | foreach | |||||||||||||||||||||||||||
| 294 | my $attr (qw(see_alsos derived_froms processed_froms evolved_froms)) { | ||||||||||||||||||||||||||||
| 295 | 288 | ▶ | if ( $self->_root_item->$attr ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 296 | 288 | my $arrayref = $self->_root_item->$attr; | |||||||||||||||||||||||||||
| 297 | 288 | for my $v (@$arrayref) { | |||||||||||||||||||||||||||
| 298 | 159 | ( my $rel = $attr ) =~ s/_(\w)/uc $1/ge; | |||||||||||||||||||||||||||
| 299 | 159 | $rel =~ s/s$//; | |||||||||||||||||||||||||||
| 300 | 159 | my $linkelem = $self->create_element( | |||||||||||||||||||||||||||
| 301 | 'link', | ||||||||||||||||||||||||||||
| 302 | rel => "irel:$rel", | ||||||||||||||||||||||||||||
| 303 | version => $v->version | ||||||||||||||||||||||||||||
| 304 | ); | ||||||||||||||||||||||||||||
| 305 | 159 | for my $attribute (qw/residref href/) { | |||||||||||||||||||||||||||
| 306 | 318 | ▶ | next unless $v->$attribute; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 307 | 159 | $linkelem->setAttribute( $attribute => $v->$attribute ); | |||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | 159 | $im->appendChild($linkelem); | |||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | 72 | $root->appendChild($im); | |||||||||||||||||||||||||||
| 316 | 72 | return; | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | 81 | ▶ | sub _import_iptc_catalog { | ||||||||||||||||||||||||||
|
Subroutine
_import_iptc_catalog: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||
| 320 | 81 | my $self = shift; | |||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 81 | ▶ | while ( my ( $attr, $alias ) = each %{ $self->g2_catalog_schemes } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 323 | 1119 | ▶ | $alias ||= $attr; | ||||||||||||||||||||||||||
|
Condition66%2/3
$alias ||= $attr
MC/DC0%0/2
$alias ||= $attr
$alias
$attr
Truth table66%2/3
A ||= B
A= $aliasB= $attr
| |||||||||||||||||||||||||||||
| 324 | 1119 | ▶ | my $getter_setter = $self->scheme_manager->can($attr) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 325 | or die "Unknown scheme '$attr'\n"; | ||||||||||||||||||||||||||||
| 326 | next | ||||||||||||||||||||||||||||
| 327 | 1119 | ▶ | if ( $getter_setter->( $self->scheme_manager ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 328 | ; # attribute ist already set by user | ||||||||||||||||||||||||||||
| 329 | 244 | my $scheme = XML::NewsML_G2::Scheme->new( | |||||||||||||||||||||||||||
| 330 | alias => $alias, | ||||||||||||||||||||||||||||
| 331 | catalog => $self->g2_catalog_url | ||||||||||||||||||||||||||||
| 332 | ); | ||||||||||||||||||||||||||||
| 333 | 244 | $getter_setter->( $self->scheme_manager, $scheme ); | |||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | 81 | return; | |||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | # public methods | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 6537 | ▶ | sub create_element { | ||||||||||||||||||||||||||
|
Subroutine
create_element: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||
| 341 | 6537 | my ( $self, $name, %attrs ) = @_; | |||||||||||||||||||||||||||
| 342 | 6537 | my $text = delete $attrs{_text}; | |||||||||||||||||||||||||||
| 343 | 6537 | my $cdata = delete $attrs{_cdata}; | |||||||||||||||||||||||||||
| 344 | 6537 | my $name_text = delete $attrs{_name_text}; | |||||||||||||||||||||||||||
| 345 | 6537 | ▶ | 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
| |||||||||||||||||||||||||||||
| 346 | 6537 | my $elem = $self->doc->createElementNS( $ns, $name ); | |||||||||||||||||||||||||||
| 347 | 6537 | for my $attr_name ( sort keys %attrs ) { | |||||||||||||||||||||||||||
| 348 | 2876 | $elem->setAttribute( $attr_name, $attrs{$attr_name} ); | |||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | 6537 | ▶ | if ($text) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 351 | 2866 | $elem->appendChild( $self->doc->createTextNode($text) ); | |||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | elsif ($cdata) { | ||||||||||||||||||||||||||||
| 354 | 0 | $elem->appendChild( $self->doc->createCDATASection($cdata) ); | |||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | elsif ($name_text) { | ||||||||||||||||||||||||||||
| 357 | 1189 | ▶ | $name_text = $name_text->name | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $name_text and $name_text->can("name")
MC/DC50%1/2
ref $name_text and $name_text->can("name")
ref $name_text
$name_text->can("name")
Truth table66%2/3
A and B
A= ref $name_textB= $name_text->can("name")
| |||||||||||||||||||||||||||||
| 358 | if ( ref $name_text and $name_text->can('name') ); | ||||||||||||||||||||||||||||
| 359 | 1189 | $elem->appendChild( | |||||||||||||||||||||||||||
| 360 | $self->create_element( 'name', _text => $name_text ) ); | ||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | 6537 | return $elem; | |||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | 72 | ▶ | sub create_dom { | ||||||||||||||||||||||||||
|
Subroutine
create_dom: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 366 | 72 | my $self = shift; | |||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | 72 | $self->_import_iptc_catalog(); | |||||||||||||||||||||||||||
| 369 | 72 | my $root = $self->_create_root_element(); | |||||||||||||||||||||||||||
| 370 | 72 | $self->_create_catalogs($root); | |||||||||||||||||||||||||||
| 371 | 72 | $self->_create_rights_info($root); | |||||||||||||||||||||||||||
| 372 | 72 | $self->_create_item_meta($root); | |||||||||||||||||||||||||||
| 373 | 72 | $self->_create_content_meta($root); | |||||||||||||||||||||||||||
| 374 | 68 | $self->_create_content($root); | |||||||||||||||||||||||||||
| 375 | 68 | return $self->doc; | |||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | 26 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||
| 381 | 26 | 1; | |||||||||||||||||||||||||||
| 382 | __END__ | ||||||||||||||||||||||||||||