« blib/lib/XML/NewsML_G2/Role/Writer/News_Item_Audio.pm
↑ Summary
blib/lib/XML/NewsML_G2/Writer/News_Message.pm »
| 1 | package XML::NewsML_G2::Writer::Package_Item; | ||||||||||
| 2 | |||||||||||
| 3 | 20 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 20 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 20 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 20 | extends 'XML::NewsML_G2::Writer'; | |||||||||
| 8 | |||||||||||
| 9 | 20 | has 'package_item', | |||||||||
| 10 | isa => 'XML::NewsML_G2::Package_Item', | ||||||||||
| 11 | is => 'ro', | ||||||||||
| 12 | required => 1; | ||||||||||
| 13 | 20 | has '+_root_node_name', default => 'packageItem'; | |||||||||
| 14 | 20 | has '_group_id', | |||||||||
| 15 | isa => 'Num', | ||||||||||
| 16 | is => 'rw', | ||||||||||
| 17 | default => 0, | ||||||||||
| 18 | traits => ['Counter'], | ||||||||||
| 19 | handles => { _next_group_id => 'inc' }; | ||||||||||
| 20 | |||||||||||
| 21 | sub _build__root_item { | ||||||||||
| 22 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_build__root_item: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 1 | return $self->package_item; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | sub BUILD { | ||||||||||
| 27 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
BUILD: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 28 | 1 | my $test_group = $self->scheme_manager->build_qcode( 'group', 'test' ); | |||||||||
| 29 | 1 | ▶ | croak 'You need to register a scheme for groups' unless $test_group; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 1 | return; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | sub _create_item_meta_title { | ||||||||||
| 34 | 0 | ▶ | my ( $self, $im ) = @_; | ||||||||
|
Subroutine
_create_item_meta_title: not called CC=2 SCAR=17.9
| |||||||||||
| 35 | 0 | my $t = $self->package_item->title; | |||||||||
| 36 | 0 | ▶ | $im->appendChild( $self->create_element( 'title', _text => $t ) ) if $t; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | return; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | ▶ | sub _create_rights_info { | |||||||||
|
Subroutine
_create_rights_info: called CC=1 SCAR=0.0
| |||||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | ▶ | sub _create_content_meta { | |||||||||
|
Subroutine
_create_content_meta: not called CC=1 SCAR=0.0
| |||||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | sub _create_group { | ||||||||||
| 47 | 0 | ▶ | my ( $self, $parent, $group, $id ) = @_; | ||||||||
|
Subroutine
_create_group: not called CC=5 SCAR=34.0
| |||||||||||
| 48 | |||||||||||
| 49 | 0 | $parent->appendChild( my $result = | |||||||||
| 50 | $self->create_element( 'group', id => $id ) ); | ||||||||||
| 51 | 0 | $self->scheme_manager->add_role( $result, 'group', $group->role ); | |||||||||
| 52 | |||||||||||
| 53 | 0 | ▶ | if ( $group->mode ne 'bag' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | my ($mode) = $group->mode =~ /^(...)/; | |||||||||
| 55 | 0 | my $qcode = $self->scheme_manager->build_qcode( 'pgrmod', $mode ); | |||||||||
| 56 | 0 | ▶ | $result->setAttribute( 'mode', $qcode ) if $qcode; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 0 | foreach my $item ( @{ $group->items } ) { | |||||||||
| 60 | 0 | ▶ | if ( $item->isa('XML::NewsML_G2::Group') ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 0 | my $group_id = 'group_' . $self->_next_group_id(); | |||||||||
| 62 | |||||||||||
| 63 | 0 | $result->appendChild( my $child = | |||||||||
| 64 | $self->create_element( 'groupRef', idref => $group_id ) ); | ||||||||||
| 65 | 0 | $self->_create_group( $parent, $item, $group_id ); | |||||||||
| 66 | |||||||||||
| 67 | } | ||||||||||
| 68 | else { # it's a News_Item | ||||||||||
| 69 | 0 | $result->appendChild( | |||||||||
| 70 | my $child = $self->create_element( | ||||||||||
| 71 | 'itemRef', | ||||||||||
| 72 | residref => $item->guid, | ||||||||||
| 73 | version => $item->doc_version | ||||||||||
| 74 | ) | ||||||||||
| 75 | ); | ||||||||||
| 76 | 0 | $child->appendChild( my $ic = | |||||||||
| 77 | $self->create_element('itemClass') ); | ||||||||||
| 78 | 0 | $self->scheme_manager->add_qcode( $ic, 'ninat', $item->nature ); | |||||||||
| 79 | 0 | $child->appendChild( | |||||||||
| 80 | $self->create_element( 'title', _text => $item->title ) ); | ||||||||||
| 81 | } | ||||||||||
| 82 | } | ||||||||||
| 83 | 0 | return; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | sub _create_content { | ||||||||||
| 87 | 0 | ▶ | my ( $self, $root ) = @_; | ||||||||
|
Subroutine
_create_content: not called CC=1 SCAR=6.9
| |||||||||||
| 88 | 0 | my $main_id = $self->package_item->root_id; | |||||||||
| 89 | |||||||||||
| 90 | 0 | $root->appendChild( my $gs = | |||||||||
| 91 | $self->create_element( 'groupSet', root => $main_id ) ); | ||||||||||
| 92 | |||||||||||
| 93 | 0 | $self->_create_group( $gs, $self->package_item->root_group, $main_id ); | |||||||||
| 94 | 0 | return; | |||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | 20 | __PACKAGE__->meta->make_immutable; | |||||||||
| 98 | |||||||||||
| 99 | 20 | 1; | |||||||||
| 100 | __END__ | ||||||||||
| 101 | |||||||||||
| 102 | =head1 NAME | ||||||||||
| 103 | |||||||||||
| 104 | XML::NewsML_G2::Writer::Package_Item - create DOM tree conforming to | ||||||||||
| 105 | NewsML-G2 for Package Items | ||||||||||
| 106 | |||||||||||
| 107 | =for test_synopsis | ||||||||||
| 108 | my ($pi, $sm); | ||||||||||
| 109 | |||||||||||
| 110 | =head1 SYNOPSIS | ||||||||||
| 111 | |||||||||||
| 112 | my $w = XML::NewsML_G2::Writer::Package_Item->new | ||||||||||
| 113 | (package_item => $pi, scheme_manager => $sm); | ||||||||||
| 114 | |||||||||||
| 115 | my $p = $w->create_element('p', class => 'main', _text => 'blah'); | ||||||||||
| 116 | |||||||||||
| 117 | my $dom = $w->create_dom(); | ||||||||||
| 118 | |||||||||||
| 119 | =head1 DESCRIPTION | ||||||||||
| 120 | |||||||||||
| 121 | This module implements the creation of a DOM tree conforming to | ||||||||||
| 122 | NewsML-G2 for Package Items. Depending on the version of the standard | ||||||||||
| 123 | specified, a version-dependent role will be applied. For the API of | ||||||||||
| 124 | this module, see the documentation of the superclass L<XML::NewsML_G2::Writer>. | ||||||||||
| 125 | |||||||||||
| 126 | =head1 ATTRIBUTES | ||||||||||
| 127 | |||||||||||
| 128 | =over 4 | ||||||||||
| 129 | |||||||||||
| 130 | =item package_item | ||||||||||
| 131 | |||||||||||
| 132 | L<XML::NewsML_G2::Package_Item> instance used to create the output document | ||||||||||
| 133 | |||||||||||
| 134 | =back | ||||||||||
| 135 | |||||||||||
| 136 | =head1 AUTHOR | ||||||||||
| 137 | |||||||||||
| 138 | Philipp Gortan C<< <philipp.gortan@apa.at> >> | ||||||||||
| 139 | |||||||||||
| 140 | =head1 LICENCE AND COPYRIGHT | ||||||||||
| 141 | |||||||||||
| 142 | Copyright (c) 2014, APA-IT. All rights reserved. | ||||||||||
| 143 | |||||||||||
| 144 | See L<XML::NewsML_G2> for the license. | ||||||||||