CPL/Annotation.pm

filter: Statementstmt 64.4% 87 / 135 Branchbran 37.8% 25 / 66 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 64.2% 18 / 28 Podpod 95.0% 19 / 20 totaltotal 59.8% 149 / 249 CC 40 SCAR 20.1
CC
40
Cov
56%
picLoc
20.0
picOverLoc
20.0
adjust
12.0
CRAP 7.5
« CPL/MXMLField.pm ↑ Summary CPL/AnnotationList.pm »
1 package Video::CPL::Annotation;
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::Story;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Video::CPL::Target;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Video::CPL::TargetList;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =head1 NAME
14  
15 Video::CPL::Annotation - Video::CPL::Annotation object.
16  
17 =head1 VERSION
18  
19 Version 0.10
20  
21 =cut
22  
23 1 our $VERSION = '0.10';
24  
25 =head1 SYNOPSIS
26  
27 Video::CPL::Annotate exists to create and manipulate Annotations.
28  
29 use Video::CPL::Annotation;
30 my $foo = Video::CPL::Annotation->new(name=>"alpha-tech",clickBehavior=>"goto",x=>772,y=>66,
31 picLoc=>"foo.png");
32 #for a single use, this could also be created by helper functions, with an auto-generated name:
33 $cue->goto(x=>772,y=>66,picLoc=>"foo.png");
34  
35 =head1 METHODS
36  
37 =cut
38  
39 1 our @FIELDS = qw(name clickBehavior x y skipOnReturn showIcon story ajs alpha targetList parent);
40 1 our @SIMPLEFIELDS = qw(name clickBehavior x y skipOnReturn showIcon ajs alpha);
41 1 our %COMPLEX = (story=>1,targetList=>1,parent=>1);
42  
43 =head2 name([$name])
44  
45 Accessor routine to get or set the name.
46  
47 =cut
48 45 ▶sub name { my $obj = shift; $obj->{name} = shift if @_; return $obj->{name}; }
Subroutine name: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 45 45
49  
50 =head2 clickBehavior(["decoration|goto|returnEnd|javascript"])
51  
52 Accessor routine to get or set the clickBehavior. Other fields may need to be modified if this is changed.
53  
54 =cut
55
56 2 ▶sub clickBehavior { my $obj = shift; $obj->{clickBehavior} = shift if @_; return $obj->{clickBehavior}; }
Subroutine clickBehavior: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
57  
58 =head2 x([$k])
59  
60 Accessor routine to get or set the x value of the Annotation.
61  
62 =cut
63  
64 2 ▶sub x { my $obj = shift; $obj->{x} = shift if @_; return $obj->{x}; }
Subroutine x: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
65  
66 =head2 y([$k])
67  
68 Accessor routine to get or set the y value of the Annotation.
69  
70 =cut
71  
72 2 ▶sub y { my $obj = shift; $obj->{y} = shift if @_; return $obj->{y}; }
Subroutine y: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
73  
74 =head2 skipOnReturn(["true|false"])
75  
76 Accessor routine to get or set skipOnReturn.
77  
78 =cut
79
80 2 ▶sub skipOnReturn { my $obj = shift; $obj->{skipOnReturn} = shift if @_; return $obj->{skipOnReturn}; }
Subroutine skipOnReturn: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
81  
82 =head2 showIcon(["true|false]")
83  
84 Accessor routine to get or set showIcon.
85  
86 =cut
87  
88 2 ▶sub showIcon { my $obj = shift; $obj->{showIcon} = shift if @_; return $obj->{showIcon}; }
Subroutine showIcon: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
89  
90 =head2 ajs($javascriptcode)
91  
92 Accessor routine to get or set ajs, the javascript to be executed if clickBehavior is <b>javascript</b>.
93  
94 =cut
95  
96 0 ▶sub ajs { my $obj = shift; $obj->{ajs} = shift if @_; return $obj->{ajs}; }
Subroutine ajs: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
97  
98 =head2 story($story)
99  
100 Accessor routine to get or set the <b>story</b>.
101  
102 =cut
103  
104 16 ▶sub story { my $obj = shift; $obj->{story} = shift if @_; return $obj->{story}; }
Subroutine story: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 16 16
105 #proposed
106 #picLoc picOverLoc ballonText forever
107 #if present will create and add story
108  
109 =head2 picLoc([$urlorlocalref])
110  
111 Accessor routine to get or set the picLoc of an embedded <b>Story</b>. Will create the
112 <b>Story</b> object if it does not exist and a parameter is given.
113  
114 =cut
115  
116 0 ▶sub picLoc { my $obj = shift;
Subroutine picLoc: not called CC=4 SCAR=30.0
Pod documented
117 0 ▶ if (@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
118 0 ▶ if ($obj->story()){
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->story) { } 0 0 0
119 0 $obj->story()->picLoc(@_);
120 } else {
121 0 $obj->{story} = new Video::CPL::Story(picLoc=>@_);
122 }
123 } else {
124 0 ▶ return undef if !$obj->story();
Branch: 1 branch
BranchTrueFalseTotal
unless $obj->story 0 0 0
125 }
126 0 return $obj->story()->picLoc();
127 }
128  
129 =head2 picOverLoc([$urlorlocalref])
130  
131 Accessor routine to get or set the picOverLoc of an embedded <b>Story</b>. Will create the
132 <b>Story</b> object if it does not exist and a parameter is given.
133  
134 =cut
135  
136 0 ▶sub picOverLoc { my $obj = shift;
Subroutine picOverLoc: not called CC=4 SCAR=30.0
Pod documented
137 0 ▶ if (@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
138 0 ▶ if ($obj->story()){
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->story) { } 0 0 0
139 0 $obj->story()->picOverLoc(@_);
140 } else {
141 0 $obj->{story} = new Video::CPL::Story(picOverLoc=>@_);
142 }
143 } else {
144 0 ▶ return undef if !$obj->story();
Branch: 1 branch
BranchTrueFalseTotal
unless $obj->story 0 0 0
145 }
146 0 return $obj->story()->picOverLoc();
147 }
148 =head2 alpha([$value])
149  
150 Accessor routine to get or set alpha.
151  
152 =cut
153  
154 0 ▶sub alpha { my $obj = shift; $obj->{alpha} = shift if @_; return $obj->{alpha}; }
Subroutine alpha: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
155  
156 =head2 targetList([$targetlist])
157  
158 Accessor routine to get or set targetList.
159  
160 =cut
161  
162 0 ▶sub targetList { my $obj = shift; $obj->{targetList} = shift if @_; return $obj->{targetList}; }
Subroutine targetList: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
163 #proposed: add
164 #target [accept array or scalar. Strings or cuePt. return array if wantarray else single target if only one else croak.]
165 #backgroundPicLoc
166 #operation
167 #headerText
168  
169 =head2 parent([$VideoCPLobject])
170  
171 Accessor routine to get or set the parent. Video::CPL::Annotation uses this field to determine the parent
172 Video::CPL object.
173  
174 =cut
175  
176 0 ▶sub parent { my $obj = shift; $obj->{parent} = shift if @_; return $obj->{parent}; }
Subroutine parent: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
177  
178 =head2 new([name=>$name,clickBehavior=>$something,x=>$k,y=>$k,skipOnReturn=>$tf,showIcon=>$tf,
179 story=>$story,ajs=>$javascript,alpha=>$value,targetList=>$targetList,target=>$cuepoint,parent=>$videocpl])
180  
181 Creates a new Annotation object. Will automatically create a name if not given, and
182 will convert a <b>Cue</b> passed as <b>target</b> to a <b>targetList</b>.
183  
184 =cut
185  
186 2 ▶sub new {
Subroutine new: called CC=11 SCAR=24.6
Pod documented
187 2 my $pkg = shift;
188 2 my %p = @_;
189 2 my $ret = {};
190 2 bless $ret,$pkg;
191  
192 2 ▶ confess("new Annotation without parent\n") if !defined $p{parent};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p{"parent"} 0 2 2
193 2 ▶ $p{name} = $p{parent}->newname("anno") if !defined $p{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p{"name"} 0 2 2
194 2 my %s;
195 2 foreach my $s (@Video::CPL::Story::FIELDS){
196 10 ▶ if (defined($p{$s})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p{$s}) 1 9 10
197 1 $s{$s} = $p{$s};
198 1 delete $p{$s};
199 }
200 }
201 2 ▶ $ret->{story} = new Video::CPL::Story(%s) if %s;
Branch: 1 branch
BranchTrueFalseTotal
if %s 1 1 2
202 2 ▶ if (defined($p{target})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p{"target"}) 0 2 2
203 0 $ret->{targetList} = new Video::CPL::TargetList(target=>[new Video::CPL::Target(cuePointRef=>$p{target})]);
204 0 delete $p{target};
205 }
206  
207 2 foreach my $x (@FIELDS){
208 22 ▶ $ret->{$x} = $p{$x} if defined $p{$x};
Branch: 1 branch
BranchTrueFalseTotal
if defined $p{$x} 18 4 22
209 }
210 2 foreach my $x (keys %p){
211 18 ▶ confess("Parameter ('$x') given to Video::CPL::Annotation::new, but not understood\n") if !defined $ret->{$x};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ret->{$x} 0 18 18
212 }
213  
214 2 return $ret;
215 }
216  
217  
218 =head2 adjust([name=>$name,clickBehavior=>$what,skipOnReturn=>$tf,showIcon=>$tf,alpha=>$value,
219 skipOnReturn=>$tf,x=>$x,y=>$y,story=>$story])
220  
221 Change arbitrary fields within an Annotation point.
222  
223 =cut
224  
225 0 ▶sub adjust {
Subroutine adjust: not called CC=3 SCAR=24.8
Pod documented
226 0 my $obj = shift;
227 0 my %parms = @_;
228 0 foreach my $x (qw(name clickBehavior skipOnReturn showIcon alpha relative skip x y modal story )){
229 0 ▶ $obj->{$x} = $parms{$x} if defined($parms{$x});
Branch: 1 branch
BranchTrueFalseTotal
if defined $parms{$x} 0 0 0
230 }
231  
232 0 return $obj;
233 }
234  
235 =head2 fromxml()
236  
237 =cut
238  
239 1 ▶sub fromxml{
Subroutine fromxml: called CC=5 SCAR=16.2
Pod documented
240 1 my $parent = shift;
241 1 my $s = shift;
242 1 my %s = %{$s};
243 1 my %p = (parent=>$parent);
244 1 foreach my $k (@SIMPLEFIELDS){
245 8 ▶ $p{$k} = $s{$k} if defined($s{$k});
Branch: 1 branch
BranchTrueFalseTotal
if defined $s{$k} 6 2 8
246 }
247 1 ▶ $p{story} = Video::CPL::Story::fromxml($s{story}[0]) if defined($s{story}[0]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $s{"story"}[0] 1 0 1
248 1 ▶ $p{targetList} = Video::CPL::TargetList::fromxml($s{targetList}[0]) if defined($s{targetList}[0]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $s{"targetList"}[0] 1 0 1
249 1 return new Video::CPL::Annotation(%p);
250 }
251  
252 =head2 xmlo()
253  
254 Return the text form of the Annotation. Usually called by Video::CPL::xml().
255  
256 =cut
257  
258 1 ▶sub xmlo {
Subroutine xmlo: called CC=5 SCAR=16.2
Pod documented
259 #given parent, add stuff to it and return.
260 1 my $obj = shift;
261 1 my $xo = shift;
262 1 my %p;
263 1 foreach my $x (@SIMPLEFIELDS){
264 8 ▶ $p{$x} = $obj->{$x} if defined($obj->{$x});
Branch: 1 branch
BranchTrueFalseTotal
if defined $obj->{$x} 6 2 8
265 }
266 1 $xo->startTag("annotation",%p);
267 1 ▶ $obj->{story}->xmlo($xo) if defined $obj->{story};
Branch: 1 branch
BranchTrueFalseTotal
if defined $obj->{"story"} 1 0 1
268 1 ▶ $obj->{targetList}->xmlo($xo) if defined $obj->{targetList};
Branch: 1 branch
BranchTrueFalseTotal
if defined $obj->{"targetList"} 1 0 1
269 1 $xo->endTag("annotation");
270 }
271  
272 =head2 xml()
273  
274 Return the xml format of an Annotation object. Intended for special cases; normally the Video::CPL
275 method <b>xml</b> is called to obtain XML for the entire Video::CPL object at once.
276  
277 =cut
278  
279 0 ▶sub xml {
Subroutine xml: not called CC=1 SCAR=6.9
Pod documented
280 0 my $obj = shift;
281 0 my $a = "";
282 0 my $xo = new XML::Writer(OUTPUT=>\$a);
283 0 $obj->xmlo($xo);
284 0 $xo->end();
285 0 return $a;
286 }
287  
288 =head2 reffromobj($cplobj)
289  
290 Returns the string used to refer to this Annotation from the Video::CPL object given.
291  
292 =cut
293  
294 0 ▶sub reffromobj {
Subroutine reffromobj: not called CC=3 SCAR=24.8
Pod documented
295 0 my $obj = shift;
296 0 my $cpl = shift;
297 0 ▶ confess("Video::CPL::Annotation::reffromobj but no parent\n") if !defined($obj->{parent});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $obj->{"parent"} 0 0 0
298 0 ▶ return $obj->{name} if $obj->parent() == $cpl;
Branch: 1 branch
BranchTrueFalseTotal
if $obj->parent == $cpl 0 0 0
299 0 my $ctvfile = $obj->parent()->{ctvfilename};
300 0 return "/$ctvfile\#$obj->{name}";
301 #TODO: support for CPL objects with a different domain, think about dynamic
302 }
303  
304 =head2 printref()
305  
306 Return a cuePointRef to this Annotation.
307  
308 =cut
309  
310 0 ▶sub printref {
Subroutine printref: not called CC=1 SCAR=6.9
Pod documented
311 0 my $obj = shift;
312 0 my $name = $obj->{name};
313 0 return "<target cuePointRef=\"$name\"/>\n";
314 }
315  
316 =head1 AUTHOR
317  
318 Carl Rosenberg, C<< <perl at coincident.tv> >>
319  
320 =head1 BUGS
321  
322 Please report any bugs or feature requests to Coincident TV.
323  
324 =head1 SUPPORT
325  
326 You can find documentation for this module with the perldoc command.
327  
328 perldoc Video::CPL::Annotation
329  
330  
331 =head1 LICENSE AND COPYRIGHT
332  
333 Copyright 2010 Coincident TV
334  
335 Licensed under the Apache License, Version 2.0 (the "License");
336 you may not use this file except in compliance with the License.
337 You may obtain a copy of the License at
338  
339 http://www.apache.org/licenses/LICENSE-2.0
340  
341 Unless required by applicable law or agreed to in writing, software
342 distributed under the License is distributed on an "AS IS" BASIS,
343 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
344 See the License for the specific language governing permissions and
345 limitations under the License.
346 =cut
347  
348 1 1; # End of Video::CPL::Annotation
« CPL/MXMLField.pm ↑ Summary CPL/AnnotationList.pm »