CPL/AnnotationList.pm

filter: Statementstmt 69.3% 52 / 75 Branchbran 22.2% 4 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 9 / 12 Podpod 83.3% 5 / 6 totaltotal 63.0% 70 / 111 CC 17 SCAR 18.6
CC
17
Cov
60%
target
20.0
pusht
6.0
xmlo
5.5
CRAP 6.4
« CPL/Annotation.pm ↑ Summary CPL/TargetList.pm »
1 package Video::CPL::AnnotationList;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use XML::Writer;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Video::CPL::Annotation;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Video::CPL::AnnotationList - Manages a list of Annotation objects. Generally invoked by other Video::CPL modules.
14  
15 =head1 VERSION
16  
17 Version 0.10
18  
19 =cut
20  
21 1 our $VERSION = '0.10';
22  
23 =head1 SYNOPSIS
24  
25 Video::CPL::AnnotationList is normally called by Video::CPL.pm. If need be it can be
26 called directly to create or modify Video::CPL::AnnotationList objects.
27  
28 =head1 METHODS
29  
30 =cut
31  
32 1 our @FIELDS = qw(target);
33  
34 =head2 target([@targetarray])
35  
36 Accessor function to get or set the target array.
37  
38 =cut
39  
40 0 ▶sub target {
Subroutine target: not called CC=4 SCAR=30.0
Pod documented
41 0 my $obj = shift;
42 0 ▶ if (@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
43 0 my @a = @_;
44 0 delete $obj->{target};
45 0 foreach my $x (@a){
46 0 $obj->pusht($x);
47 }
48 }
49 0 ▶ return () if !exists($obj->{target});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $obj->{"target"} 0 0 0
50 0 return @{$obj->{target}};
51 }
52  
53 =head2 new([target=>$targetarray])
54  
55 Create a new AnnotationList object.
56  
57 =cut
58  
59 2 ▶sub new {
Subroutine new: called CC=5 SCAR=16.3
Pod documented
60 2 my $pkg = shift;
61 2 my %parms = @_;
62 2 my $ret = {};
63 2 bless $ret,$pkg;
64  
65 2 foreach my $x (@FIELDS){
66 2 ▶ $ret->{$x} = $parms{$x} if defined $parms{$x};
Branch: 1 branch
BranchTrueFalseTotal
if defined $parms{$x} 2 0 2
67 }
68 2 foreach my $x (keys %parms){
69 2 ▶ confess("Parameter ('$x') given to Video::CPL::AnnotationList::new, but not understood\n") if !defined $ret->{$x};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ret->{$x} 0 2 2
70 }
71  
72 2 return $ret;
73 }
74  
75 =head2 pusht($target)
76  
77 Push a target onto the target array.
78  
79 =cut
80  
81 0 ▶sub pusht {
Subroutine pusht: not called CC=2 SCAR=17.9
Pod documented
82 0 my $obj = shift;
83 0 my $t = shift;
84 0 ▶ if (defined $obj->{target}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj->{'target'}) { } 0 0 0
85 0 push @{$obj->{target}},$t;
86 } else {
87 0 $obj->{target} = [$t];
88 }
89 }
90  
91 =head2 xmlo
92
93 Given an XML::Writer object, add the xml information for this AnnotationList.
94  
95 =cut
96  
97 1 ▶sub xmlo {
Subroutine xmlo: called CC=5 SCAR=17.0
Pod documented
98 1 my $obj = shift;
99 1 my $xo = shift;
100 1 my %p;
101 1 foreach my $x (@FIELDS){
102 1 ▶ next if $x eq "target";
Branch: 1 branch
BranchTrueFalseTotal
if $x eq "target" 1 0 1
103 0 ▶ $p{$x} = $obj->{$x} if defined $obj->{$x};
Branch: 1 branch
BranchTrueFalseTotal
if defined $obj->{$x} 0 0 0
104 }
105 1 $xo->startTag("annotationList",%p);
106 1 foreach my $c (@{$obj->{target}}){ #if we are a targetList we must have target
107 1 $c->xmlo($xo);
108 }
109 1 $xo->endTag("annotationList");
110 }
111  
112 =head2 xml()
113  
114 Return the xml format of a AnnotationList object. Intended for special cases; normally the Video::CPL
115 method <b>xml</b> is called to obtain XML for the entire Video::CPL object at once.
116  
117 =cut
118  
119 0 ▶sub xml {
Subroutine xml: not called CC=1 SCAR=6.9
Pod documented
120 0 my $obj = shift;
121 0 my $a;
122 0 my $xo = new XML::Writer(OUTPUT=>\$a);
123 0 $obj->xmlo($xo);
124 0 $xo->end();
125 0 return $a;
126 }
127  
128 1 ▶sub fromxml {
Subroutine fromxml: called CC=5 SCAR=16.7
Pod undocumented
129 1 my $s = shift;
130 1 my %s = %{$s};
131 1 my %parms;
132 1 foreach my $q (@FIELDS){
133 1 ▶ next if $q eq "target";
Branch: 1 branch
BranchTrueFalseTotal
if $q eq "target" 1 0 1
134 0 ▶ $parms{$q} = $s{$q} if defined($s{$q});
Branch: 1 branch
BranchTrueFalseTotal
if defined $s{$q} 0 0 0
135 }
136 #process targets
137 1 my @t;
138 1 foreach my $x (@{$s{target}}){
139 1 push @t,Video::CPL::Target::fromxml($x);
140 }
141 1 $parms{target} = \@t;
142 1 return new Video::CPL::AnnotationList(%parms);
143 }
144  
145 =head1 AUTHOR
146  
147 Carl Rosenberg, C<< <perl at coincident.tv> >>
148  
149 =head1 BUGS
150  
151 Please report any bugs or feature requests to Coincident TV.
152  
153 =head1 SUPPORT
154  
155 You can find documentation for this module with the perldoc command.
156  
157 =head1 LICENSE AND COPYRIGHT
158  
159 Copyright 2010 Coincident TV
160  
161 Licensed under the Apache License, Version 2.0 (the "License");
162 you may not use this file except in compliance with the License.
163 You may obtain a copy of the License at
164  
165 http://www.apache.org/licenses/LICENSE-2.0
166  
167 Unless required by applicable law or agreed to in writing, software
168 distributed under the License is distributed on an "AS IS" BASIS,
169 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
170 See the License for the specific language governing permissions and
171 limitations under the License.
172  
173 =cut
174  
175 1 1;
« CPL/Annotation.pm ↑ Summary CPL/TargetList.pm »