NewsML_G2/Writer/Package_Item.pm

filter: Statementstmt 100% 48 / 48 Branchbran 80.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 1 totaltotal 95.6% 66 / 69 CC 7 SCAR 9.2
CC
7
Cov
97%
_create_group
5.0
BUILD
2.0
_create_item_meta_title
2.0
CRAP 2.5
« NewsML_G2/Role/Writer/News_Item_Audio.pm ↑ Summary NewsML_G2/Role/Writer.pm »
1 package XML::NewsML_G2::Writer::Package_Item;
2  
3 21 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 21 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 21 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 21 extends 'XML::NewsML_G2::Writer';
8  
9 21 has 'package_item',
10 isa => 'XML::NewsML_G2::Package_Item',
11 is => 'ro',
12 required => 1;
13 21 has '+_root_node_name', default => 'packageItem';
14 21 has '_group_id',
15 isa => 'Num',
16 is => 'rw',
17 default => 0,
18 traits => ['Counter'],
19 handles => { _next_group_id => 'inc' };
20  
21 6 ▶sub _build__root_item {
Subroutine _build__root_item: called CC=1 SCAR=0.0
22 6 my $self = shift;
23 6 return $self->package_item;
24 }
25  
26 6 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=7.0
Pod undocumented
27 6 my $self = shift;
28 6 my $test_group = $self->scheme_manager->build_qcode( 'group', 'test' );
29 6 ▶ croak 'You need to register a scheme for groups' unless $test_group;
Branch: 1 branch
BranchTrueFalseTotal
unless $test_group 0 6 6
30 6 return;
31 }
32  
33 6 ▶sub _create_item_meta_title {
Subroutine _create_item_meta_title: called CC=2 SCAR=6.9
34 6 my ( $self, $im ) = @_;
35 6 my $t = $self->package_item->title;
36 6 ▶ $im->appendChild( $self->create_element( 'title', _text => $t ) ) if $t;
Branch: 1 branch
BranchTrueFalseTotal
if $t 1 5 6
37 6 return;
38 }
39  
40 6 ▶sub _create_rights_info {
Subroutine _create_rights_info: called CC=1 SCAR=0.0
41 }
42  
43 6 ▶sub _create_content_meta {
Subroutine _create_content_meta: called CC=1 SCAR=0.0
44 }
45  
46 11 ▶sub _create_group {
Subroutine _create_group: called CC=5 SCAR=16.1
47 11 my ( $self, $parent, $group, $id ) = @_;
48  
49 11 $parent->appendChild( my $result =
50 $self->create_element( 'group', id => $id ) );
51 11 $self->scheme_manager->add_role( $result, 'group', $group->role );
52  
53 11 ▶ if ( $group->mode ne 'bag' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($group->mode ne "bag") 1 10 11
54 1 my ($mode) = $group->mode =~ /^(...)/;
55 1 my $qcode = $self->scheme_manager->build_qcode( 'pgrmod', $mode );
56 1 ▶ $result->setAttribute( 'mode', $qcode ) if $qcode;
Branch: 1 branch
BranchTrueFalseTotal
if $qcode 1 0 1
57 }
58  
59 11 foreach my $item ( @{ $group->items } ) {
60 25 ▶ if ( $item->isa('XML::NewsML_G2::Group') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item->isa('XML::NewsML_G2::Group')) { } 5 20 25
61 5 my $group_id = 'group_' . $self->_next_group_id();
62  
63 5 $result->appendChild( my $child =
64 $self->create_element( 'groupRef', idref => $group_id ) );
65 5 $self->_create_group( $parent, $item, $group_id );
66  
67 }
68 else { # it's a News_Item
69 20 $result->appendChild(
70 my $child = $self->create_element(
71 'itemRef',
72 residref => $item->guid,
73 version => $item->doc_version
74 )
75 );
76 20 $child->appendChild( my $ic =
77 $self->create_element('itemClass') );
78 20 $self->scheme_manager->add_qcode( $ic, 'ninat', $item->nature );
79 20 $child->appendChild(
80 $self->create_element( 'title', _text => $item->title ) );
81 }
82 }
83 11 return;
84 }
85  
86 6 ▶sub _create_content {
Subroutine _create_content: called CC=1 SCAR=0.0
87 6 my ( $self, $root ) = @_;
88 6 my $main_id = $self->package_item->root_id;
89  
90 6 $root->appendChild( my $gs =
91 $self->create_element( 'groupSet', root => $main_id ) );
92  
93 6 $self->_create_group( $gs, $self->package_item->root_group, $main_id );
94 6 return;
95 }
96  
97 21 __PACKAGE__->meta->make_immutable;
98  
99 21 1;
100 __END__
« NewsML_G2/Role/Writer/News_Item_Audio.pm ↑ Summary NewsML_G2/Role/Writer.pm »