CPL.pm

filter: Statementstmt 34.9% 240 / 687 Branchbran 18.2% 57 / 312 Conditioncond 8.2% 6 / 73 MC/DCmcdc 0.0% 0 / 42 Subroutinesub 47.3% 45 / 95 Podpod 86.2% 69 / 80 totaltotal 32.3% 417 / 1289 CC 210 SCAR 43.8
CC
210
Cov
28%
embed
600.0
converttarget
210.0
video
132.0
CRAP 80.0
↑ Summary CPL/Cue.pm »
1 package Video::CPL;
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 Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Path qw(make_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use List::Util qw(shuffle);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use LWP::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use XML::Writer;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use Video::CPL::Cue;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Video::CPL::Annotation;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Video::CPL::Story;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Video::CPL::Layout;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 our $VAR1; #useful for evals
21  
22 =head1 NAME
23  
24 Video::CPL - Create and manipulate Coincident TV Programming Language (CPL) files.
25  
26 =head1 VERSION
27  
28 Version 0.10
29  
30 =cut
31  
32 1 our $VERSION = '0.10';
33  
34 =head1 SYNOPSIS
35  
36 Video::CPL provides an object-oriented module for creating CPL files. CPL files control interactive video experiences.
37  
38 A simple example might be displaying a video, e.g. from Youtube, in a player on a webpage.
39  
40 A more complex example might include images, which the user clicks on to jump to other videos.
41  
42 In conjunction with CGI.pm it is straightforward to create fully interactive web pages with dynamically created video experiences.
43  
44 Video::CPL does not create the video file itself; it works with videos on services such as Youtube, or created with tools such as Video::FFmpeg.
45  
46 A tutorial is available at http://metabase.coincident.tv/cpan.
47  
48 Short code sample: create a file using CPL, and then embed a link to the file in your html as shown below.
49  
50 use CPL;
51 my $ctv = new Video::CPL(videoSource=>"http://www.youtube.com/watch?v=0ZexPPDLXRA"
52 html=>$htmlfilelocation);
53 $ctv->programEnd(30); #end after 30 seconds
54 print $ctv->print(); #prints out cpl file
55  
56 #and then, when writing html:
57 print $ctv->embed(); #print out an HTML embed pointing to the temporary file
58  
59 =head1 METHODS
60  
61 =head2 new(videoSource=>$url,[backgroundHTML=>$url,frameHeight=>$k,
62 frameWidth=>$k,loggingService=>$url,skinButtons=>$url,
63 videoHeight=>$k,videoViewLayout=>$name,videoWidth=>$k,
64 videoX=>$k,videoY=>$k,webViewLayout=>$name,
65 xUniqueID=$string,xVersionCPL=>$string,
66 xWebServiceLog=>$string],[html=>$loc,ref=>$url],[htmldir=>$dir,htmlurl=>$url)
67 or
68 new(initfromctv=$urlORxml);
69  
70 Create a new Video::CPL object. There is one videoSource per Video::CPL object.
71  
72 A videoSource such as videoSource=>"http://www.youtube.com/watch?v=0b75cl4-qRE", must be specified unless initializing from another Video::CPL file. All other parameters are optional; most of them are specified in the CPL language definition available from Coincident.tv. Additional file placement options are described below.
73  
74 initfromctv=>"foo.ctv" . Given a string which is either valid XML or a filename, use it to initialize the Video::CPL object.
75  
76 If the Video::CPL object will be output using the <b>xml()</b> method, there is no need to specify a location for it. It is convenient to specify a location where the Video::CPL XML can be accessed, if multiple Video::CPL objects interact, or if the <b>embed</b> or <b>print</b> methods will be used.
77  
78 For automatic creation of a Video::CPL file, the location of a directory where the file can be created, along with the matching URL to reach that location, must be provided. An example would be <b>htmldir="/var/www/tmp"</b> and <b>htmlref=>"http://www.foo.com/tmp" </b>
79  
80  
81 =cut
82  
83 2 ▶sub new {
Subroutine new: called CC=22 SCAR=39.2
Pod documented
84 2 my $pkg = shift;
85 2 my %parms = @_;
86 2 my $ret = {};
87 2 bless $ret,$pkg;
88  
89 2 ▶ $ret->{xVersionCPL} = $parms{xVersionCPL} || "0.8.0";
Condition50%1/2
$parms{'xVersionCPL'} || '0.8.0'
l!l
02
MC/DC0%0/1
$parms{'xVersionCPL'} || '0.8.0'
$parms{'xVersionCPL'}
Truth table50%1/2
A
A= $parms{'xVersionCPL'}
Aresult
11
00
90  
91 #The directory on the host system which is the top level html directory.
92 #normally used in embed when printing out the html.
93 #If not used, i.e. if you are collecting the ctv and placing it yourself, this can be invalid.
94 2 ▶ $ret->{html} = $parms{html} || $ENV{CPLDIR};
Condition33%1/3
$parms{'html'} || $ENV{'CPLDIR'}
l!l&&r!l&&!r
002
MC/DC0%0/2
$parms{'html'} || $ENV{'CPLDIR'}
$parms{'html'} $ENV{'CPLDIR'}
Truth table33%1/3
A || B
A= $parms{'html'}B= $ENV{'CPLDIR'}
ABresult
1X1
011
000
95  
96 #ref is the base of the URL to be used for intra-ctv references. It should point to the same location as html
97 2 ▶ $ret->{ref} = $parms{ref} || $ENV{CPLURL};
Condition33%1/3
$parms{'ref'} || $ENV{'CPLURL'}
l!l&&r!l&&!r
002
MC/DC0%0/2
$parms{'ref'} || $ENV{'CPLURL'}
$parms{'ref'} $ENV{'CPLURL'}
Truth table33%1/3
A || B
A= $parms{'ref'}B= $ENV{'CPLURL'}
ABresult
1X1
011
000
98  
99 #XML-isms
100 2 ▶ $ret->{'xsi:noNamespaceSchemaLocation'} = $parms{'xsi:noNamespaceSchemaLocation'} || ($ret->{xVersionCPL} eq "0.7.0")?"CPL_v0.7_validator.xsd":"CPL_v0.8_validator.xsd";
Branch: 1 branch
BranchTrueFalseTotal
$parms{'xsi:noNamespaceSchemaLocation'} || $ret->{'xVersionCPL'} eq '0.7.0' ? : 0 2 2
Condition33%1/3
$parms{"xsi:noNamespaceSchemaLocation"} or $ret->{"xVersionCPL"} eq "0.7.0"
l!l&&r!l&&!r
002
MC/DC0%0/2
$parms{"xsi:noNamespaceSchemaLocation"} or $ret->{"xVersionCPL"} eq "0.7.0"
$parms{"xsi:noNamespaceSchemaLocation"} $ret->{"xVersionCPL"} eq "0.7.0"
Truth table33%1/3
A or B
A= $parms{"xsi:noNamespaceSchemaLocation"}B= $ret->{"xVersionCPL"} eq "0.7.0"
ABresult
1X1
011
000
101 2 ▶ $ret->{'xmlns:xsi'} = $parms{'xmlns:xsi'} || "http://www.w3.org/2001/XMLSchema-instance";
Condition50%1/2
$parms{'xmlns:xsi'} || 'http://www.w3.org/2001/XMLSchema-instance'
l!l
02
MC/DC0%0/1
$parms{'xmlns:xsi'} || 'http://www.w3.org/2001/XMLSchema-instance'
$parms{'xmlns:xsi'}
Truth table50%1/2
A
A= $parms{'xmlns:xsi'}
Aresult
11
00
102  
103 2 ▶ $ret->parsectv($parms{initfromctv}) if $parms{initfromctv};
Branch: 1 branch
BranchTrueFalseTotal
if $parms{"initfromctv"} 1 1 2
104 2 warn("CPL new v1($parms{v1})\n");
105 2 ▶ $ret->v1($parms{v1}) if exists $parms{v1};
Branch: 1 branch
BranchTrueFalseTotal
if exists $parms{"v1"} 0 2 2
106 2 ▶ delete $parms{v1} if exists $parms{v1};
Branch: 1 branch
BranchTrueFalseTotal
if exists $parms{"v1"} 0 2 2
107 2 ▶ $ret->v2($parms{v2}) if exists $parms{v2};
Branch: 1 branch
BranchTrueFalseTotal
if exists $parms{"v2"} 0 2 2
108 2 ▶ delete $parms{v2} if exists $parms{v2};
Branch: 1 branch
BranchTrueFalseTotal
if exists $parms{"v2"} 0 2 2
109 2 ▶ $ret->v3($parms{v3}) if exists $parms{v3};
Branch: 1 branch
BranchTrueFalseTotal
if exists $parms{"v3"} 0 2 2
110 2 ▶ delete $parms{v3} if exists $parms{v3};
Branch: 1 branch
BranchTrueFalseTotal
if exists $parms{"v3"} 0 2 2
111 #check parameters; confess on typos etc.
112 2 foreach my $q (keys %parms){
113 17 ▶ next if $q =~ /xVersionCPL|videoSource|videoWidth|videoHeight|backgroundHTML|xWebServiceLoc|xUniqueID|xProgLevelDir|loggingService|html|ref|xsi:noNamespaceSchemaLocation|xmlns:xsi|xProgLevelData|skinButtons|webViewLayout|videoViewLayout|frameWidth|frameHeight|videoX|videoY|youtubeID|initfromctv/;
Branch: 1 branch
BranchTrueFalseTotal
if $q =~ /xVersionCPL|videoSource|videoWidth|videoHeight|backgroundHTML|xWebServiceLoc|xUniqueID|xProgLevelDir|loggingService|html|ref|xsi:noNamespaceSchemaLocation|xmlns:xsi|xProgLevelData|skinButtons|webViewLayout|videoViewLayout|frameWidth|frameHeight|videoX|videoY|youtubeID|initfromctv/ 17 0 17
114 0 confess("new CPL does not know what to do with parameter($q)\n");
115 }
116  
117 2 foreach my $q (qw(xVersionCPL videoSource videoWidth videoHeight backgroundHTML xWebServiceLoc xUniqueID xProgLevelDir loggingService xProgLevelData skinButtons webViewLayout videoViewLayout frameWidth frameHeight videoX videoY youtubeID)){
118 36 ▶ $ret->{$q} = $parms{$q} if defined($parms{$q});
Branch: 1 branch
BranchTrueFalseTotal
if defined $parms{$q} 16 20 36
119 }
120  
121 #Errors: no source file specified
122 #Error: parameter given but not used
123 ##Errors: no source file specified
124 #Error: parameter given but not used
125 2 ▶ if (!defined($parms{initfromctv})){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $parms{"initfromctv"}) 1 1 2
126 1 $ret->{cuePoints} = [];
127 1 $ret->{cuePoints}[0] = Video::CPL::Cue->new(name=>"CPLBegin",time=>0,cueType=>"regular",parent=>$ret);
128 }
129  
130 2 ▶ if (exists($parms{htmlurl})){
Branch: 2 branches
BranchTrueFalseTotal
if (exists $parms{'htmlurl'}) { } 0 2 2
elsif (defined $ret->{'html'}) { } 0 2 2
131 0 ▶ $ret->{htmlrel} = $parms{htmlrel} || ".";
Condition0%0/2
$parms{'htmlrel'} || '.'
l!l
00
MC/DC0%0/1
$parms{'htmlrel'} || '.'
$parms{'htmlrel'}
Truth table0%0/2
A
A= $parms{'htmlrel'}
Aresult
11
00
132 0 $ret->{htmlurl} = $parms{htmlurl};
133 } elsif (defined($ret->{html})){
134 #open up a temporary file now to avoid race conditions. Might not even be used.
135 0 my $fh = File::Temp->new(UNLINK=>0,DIR=>"$ret->{html}",SUFFIX=>".ctv");
136 0 my $filename = $fh->filename;
137 0 $ret->{fullfilename} = $filename;
138 0 chmod 0644,$filename;
139 0 $filename =~ s/.*\///;
140 0 $ret->{ctvfilename} = $filename;
141 0 $ret->{fh} = $fh;
142 }
143 2 return $ret;
144 }
145  
146 0 ▶sub datepref {
Subroutine datepref: not called CC=3 SCAR=24.8
Pod undocumented
147 0 my $x = shift;
148 0 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($x);
149 0 $year+=1900;
150 0 $mon++;
151 0 ▶ $mon = "0".$mon if length($mon) == 1;
Branch: 1 branch
BranchTrueFalseTotal
if length $mon == 1 0 0 0
152 0 ▶ $mday = "0".$mday if length($mday) == 1;
Branch: 1 branch
BranchTrueFalseTotal
if length $mday == 1 0 0 0
153 0 return "$year-$mon-$mday";
154 }
155  
156 0 ▶sub fixfile {
Subroutine fixfile: not called CC=5 SCAR=34.0
Pod undocumented
157 0 my $obj = shift;
158 0 ▶ return if $obj->{filefixed};
Branch: 1 branch
BranchTrueFalseTotal
if $obj->{"filefixed"} 0 0 0
159 0 my $dseg = datepref($^T); #convert time of script starting to 2010-01-01 format
160 0 ▶ $obj->{htmlrel} = "." if !exists($obj->{htmlrel});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $obj->{"htmlrel"} 0 0 0
161 0 my $dir = $obj->{htmlrel}."/".$dseg;
162 0 ▶ make_path($dir) if !-d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 0 0 0
163 0 ▶ confess("$0: Video::CPL Fatal Error. Could not create or access directory ($dir).\n") if !-d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 0 0 0
164 #create file with File::Temp chmod 0644 etc.
165 0 my $fh = File::Temp->new(UNLINK=>0,DIR=>$dir,SUFFIX=>".ctv");
166 0 $obj->{fh} = $fh;
167 0 my $filename = $fh->filename;
168 0 chmod 0644,$filename;
169 0 $filename =~ s/.*\///;
170 0 $obj->{ctvfilename} = $filename;
171 0 $obj->{relfilename} = "$dir/$filename";
172 0 $obj->{relfilename} =~ s/^\.\///; #if we are ./foo.ctv become foo.ctv
173 0 $obj->{relfilename} =~ s/\/\//\//g;
174 0 $obj->{url} = $obj->{htmlurl}."/$dseg/$filename";
175 #set full relative pathname and fh
176 0 $obj->{filefixed} = 1;;
177 0 return;
178 }
179  
180 =head2 asurl()
181  
182 Returns the URL which will recreate this URL. This will be a file or a reference to this script.
183  
184 Used when creating the media parameter for the CTV player, which requires a full URL.
185  
186 =cut
187  
188 0 ▶sub asurl {
Subroutine asurl: not called CC=4 SCAR=30.0
Pod documented
189 0 my $obj = shift;
190  
191 0 ▶ confess("$0: Fatal Error. URL reference to a Video::CPL object which is marked 'noref'.\n") if $obj->{noref};
Branch: 1 branch
BranchTrueFalseTotal
if $obj->{"noref"} 0 0 0
192  
193 0 ▶ if ($obj->{isdyn}){
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{'isdyn'}) { } 0 0 0
194 0 confess("NYI");
195 } else {
196 0 ▶ $obj->fixfile() if !$obj->{filefixed};
Branch: 1 branch
BranchTrueFalseTotal
unless $obj->{"filefixed"} 0 0 0
197 0 return $obj->{url};
198 }
199 }
200  
201 =head2 asrel([$otherCPL])
202  
203 Returns the URL fragment (e.g. foo/goo.ctv) which will access this file from the current directory. If given
204 a parameter of another Video::CPL object, will return a URL fragment which is valid in that objects context.
205  
206 =cut
207  
208 0 ▶sub asrel {
Subroutine asrel: not called CC=4 SCAR=30.0
Pod documented
209 0 my $obj = shift;
210 #optional second param. Return from the perspective of this cpl.
211 0 ▶ confess("$0: Fatal Error. URL reference to a Video::CPL object which is marked 'noref'.\n") if $obj->{noref};
Branch: 1 branch
BranchTrueFalseTotal
if $obj->{"noref"} 0 0 0
212  
213 0 ▶ if ($obj->{isdyn}){
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{'isdyn'}) { } 0 0 0
214 0 confess("NYI");
215 } else {
216 0 ▶ $obj->fixfile() if !$obj->{filefixed};
Branch: 1 branch
BranchTrueFalseTotal
unless $obj->{"filefixed"} 0 0 0
217 0 return $obj->{relfilename};
218 }
219 }
220  
221 0 ▶sub asreldir {
Subroutine asreldir: not called CC=2 SCAR=17.9
Pod undocumented
222 0 my $obj = shift;
223 0 my $x = $obj->asrel();
224 0 ▶ return $1 if $x =~ /^(.*)\//; #normal case, foo/goo/hoo.ctv, return foo/goo
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ m[^(.*)/] 0 0 0
225 0 return "."; #if there was no slash, current directory
226 }
227  
228 0 ▶sub asreltail {
Subroutine asreltail: not called CC=2 SCAR=17.9
Pod undocumented
229 0 my $obj = shift;
230 0 my $x = $obj->asrel();
231 0 ▶ return $1 if $x =~ /^.*\/(.*)$/; #normal case, foo/goo/hoo.ctv, return hoo.ctv
Branch: 1 branch
BranchTrueFalseTotal
if $x =~ m[^.*/(.*)$] 0 0 0
232 0 return "$x"; #if there was no slash, return self
233 }
234  
235 0 ▶sub reffrom {
Subroutine reffrom: not called CC=4 SCAR=30.0
Pod undocumented
236 0 my $obj = shift;
237 0 my $from = shift;
238 0 ▶ if ($from && ($from != $obj)){
Branch: 1 branch
BranchTrueFalseTotal
if ($from and $from != $obj) { } 0 0 0
Condition0%0/3
$from and $from != $obj
!ll&&!rl&&r
000
MC/DC0%0/2
$from and $from != $obj
$from $from != $obj
Truth table0%0/3
A and B
A= $fromB= $from != $obj
ABresult
0X0
100
111
239 0 ▶ if ($obj->{noref}){
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{"noref"}) 0 0 0
240 0 warn("Video::CPL: this object has noref set, cannot be referenced from other objects, fatal error.\n");
241 0 return undef;
242 }
243 } else {
244 0 return $obj->{tail};
245 }
246 }
247  
248 #=head2 tmpfile(ext=>".ctv")
249 #
250 # Create a temporary file. Return the filehandle, and an address usable in the current CTV.
251 #
252 #=cut
253 #
254 #sub tmpfile {
255 # my $obj = shift;
256 # my %p = @_;
257 # confess; #this is a placeholder
258 #}
259  
260 =head2 xVersionCPL([$string])
261  
262 Accessor routine to set or read xVersionCPL.
263  
264 =cut
265  
266 2 ▶sub xVersionCPL { my $obj = shift; $obj->{xVersionCPL} = shift if @_; return $obj->{xVersionCPL};};
Subroutine xVersionCPL: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
267  
268 =head2 videoSource([$url])
269  
270 Accessor routine to set or read videoSource.
271  
272 =cut
273  
274 2 ▶sub videoSource { my $obj = shift; $obj->{videoSource} = shift if @_; return $obj->{videoSource};};
Subroutine videoSource: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
275  
276 =head2 xWebServiceLoc([$url])
277  
278 Accessor routine to set or read xWebServiceLoc.
279  
280 =cut
281  
282 2 ▶sub xWebServiceLoc { my $obj = shift; $obj->{xWebServiceLoc} = shift if @_; return $obj->{xWebServiceLoc};};
Subroutine xWebServiceLoc: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
283  
284 =head2 loggingService([$url])
285  
286 Accessor routine to set or read loggingService.
287  
288 =cut
289  
290 2 ▶sub loggingService { my $obj = shift; $obj->{loggingService} = shift if @_; return $obj->{loggingService};};
Subroutine loggingService: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
291  
292 =head2 skinButtons([$url])
293  
294 Accessor routine to set or read skinButtons. These are optional, and used to form the control bar.
295  
296 =cut
297  
298 2 ▶sub skinButtons { my $obj = shift; $obj->{skinButtons} = shift if @_; return $obj->{skinButtons};};
Subroutine skinButtons: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
299  
300 =head2 backgroundHTML([$url])
301  
302 Accessor routine to set or read backgroundHTML.
303  
304 =cut
305  
306 2 ▶sub backgroundHTML { my $obj = shift; $obj->{backgroundHTML} = shift if @_; return $obj->{backgroundHTML};};
Subroutine backgroundHTML: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
307  
308 =head2 videoWidth([$string])
309  
310 Accessor routine to set or read videoWidth (the width of the video image within the overall CPL layout).
311  
312 =cut
313  
314 2 ▶sub videoWidth { my $obj = shift; $obj->{videoWidth} = shift if @_; return $obj->{videoWidth};};
Subroutine videoWidth: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
315  
316 =head2 videoHeight([$string])
317  
318 Accessor routine to set or read videoHeight (the height of the video image).
319  
320 =cut
321  
322 2 ▶sub videoHeight { my $obj = shift; $obj->{videoHeight} = shift if @_; return $obj->{videoHeight};};
Subroutine videoHeight: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
323  
324 =head2 frameWidth([$string])
325  
326 Accessor routine to set or read frameWidth (the width of the entire CPL frame).
327  
328 =cut
329  
330 2 ▶sub frameWidth { my $obj = shift; $obj->{frameWidth} = shift if @_; return $obj->{frameWidth};};
Subroutine frameWidth: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
331  
332 =head2 frameHeight([$string])
333  
334 Accessor routine to set or read frameHeight (the height of the entire CPL frame).
335  
336 =cut
337  
338 2 ▶sub frameHeight { my $obj = shift; $obj->{frameHeight} = shift if @_; return $obj->{frameHeight};};
Subroutine frameHeight: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
339  
340 =head2 videoX([$string])
341  
342 Accessor routine to set or read videoX.
343  
344 =cut
345  
346 2 ▶sub videoX { my $obj = shift; $obj->{videoX} = shift if @_; return $obj->{videoX};};
Subroutine videoX: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
347  
348 =head2 videoY([$string])
349  
350 Accessor routine to set or read videoY.
351  
352 =cut
353  
354 2 ▶sub videoY { my $obj = shift; $obj->{videoY} = shift if @_; return $obj->{videoY};};
Subroutine videoY: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
355  
356 =head2 videoViewLayout([$layoutname])
357  
358 Accessor routine to set or read videoViewLayout.
359  
360 =cut
361  
362 2 ▶sub videoViewLayout { my $obj = shift; $obj->{videoViewLayout} = shift if @_; return $obj->{videoViewLayout};};
Subroutine videoViewLayout: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
363  
364 =head2 webViewLayout([$layoutname])
365  
366 Accessor routine to set or read webViewLayout.
367  
368 =cut
369  
370 2 ▶sub webViewLayout { my $obj = shift; $obj->{webViewLayout} = shift if @_; return $obj->{webViewLayout};};
Subroutine webViewLayout: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
371  
372 =head2 youtubeID([$id])
373  
374 Accessor routine to set or read youtubeID.
375  
376 =cut
377  
378 2 ▶sub youtubeID { my $obj = shift; $obj->{youtubeID} = shift if @_; return $obj->{youtubeID};};
Subroutine youtubeID: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
379  
380 =head2 xUniqueID([$id])
381  
382 Accessor routine to set or read xUniqueID.
383  
384 =cut
385  
386 2 ▶sub xUniqueID { my $obj = shift; $obj->{xUniqueID} = shift if @_; return $obj->{xUniqueID};};
Subroutine xUniqueID: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
387  
388 =head2 xProgLevelDir([$id])
389  
390 Accessor routine to set or read xProgLevelDir.
391  
392 =cut
393  
394 2 ▶sub xProgLevelDir { my $obj = shift; $obj->{xProgLevelDir} = shift if @_; return $obj->{xProgLevelDir};};
Subroutine xProgLevelDir: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
395  
396 =head2 video([$video1,$video2,$video3}])
397  
398 Accessor routine for the video field, which contains an array of three different video sources which can be used.
399 Returns an array, or undef if it has not been set.
400 Takes an array of 3 urls.
401 There is no way to set an individual URL with this accessor; read and then write to set one.
402  
403 =cut
404  
405 0 ▶sub video {
Subroutine video: not called CC=11 SCAR=48.8
Pod documented
406 0 my $obj = shift;
407 0 ▶ if (@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
408 0 ▶ if ($obj->{video}){
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{'video'}) { } 0 0 0
409 0 warn("Video called with ".join('/',@_).", video exists\n");
410 0 my @a = @{$obj->{video}[0]{source}};
411 0 my @new = @_;
412 #who knows if the number of video fields will change in the future
413 0 ▶ confess("confused on video a $#a new $#new\n") if ($#a != $#new) && (($#a != 2) || ($#new != 2));
Branch: 1 branch
BranchTrueFalseTotal
if $#a != $#new and $#a != 2 || $#new != 2 0 0 0
Condition0%0/6
$#a != $#new and $#a != 2 || $#new != 2
!ll&&!rl&&r
000
$#a != 2 or $#new != 2
l!l&&r!l&&!r
000
MC/DC0%0/3
$#a != $#new and $#a != 2 || $#new != 2
$#a != $#new $#a != 2 $#new != 2
Truth table0%0/4
A and B or C
A= $#a != $#newB= $#a != 2C= $#new != 2
ABCresult
0XX0
1000
11X1
1011
414 0 foreach my $ia (0..$#a){
415 0 my %h = %{$a[$ia]};
416 0 $h{src} = $new[$ia];
417 }
418 0 warn("Video returning ".join('/',@new)."\n");
419 0 return @new;
420 } else {
421 0 warn("Video called with ".join('/',@_).", video does not exist\n");
422 0 $obj->{video} = [{source => []}];
423 0 foreach my $s (@_){
424 0 push @{$obj->{video}[0]{source}},{src => $s};
425 }
426 0 warn("Video returning ".join('/',@_)."\n");
427 0 return @_;
428 }
429 } else {
430 0 ▶ warn("Video not there, returning undefs\n") if !$obj->{video};
Branch: 1 branch
BranchTrueFalseTotal
unless $obj->{"video"} 0 0 0
431 0 ▶ return (undef,undef,undef) if !$obj->{video};
Branch: 1 branch
BranchTrueFalseTotal
unless $obj->{"video"} 0 0 0
432 0 my @a = @{$obj->{video}[0]{source}};
433 0 my @ret;
434 0 foreach my $ia (0..$#a){
435 0 my %h = %{$a[$ia]};
436 0 push @ret,$h{src};
437 }
438 0 warn("Video accessor returning ".join('/',@ret)."\n");
439 0 return @ret;
440 }
441 }
442  
443 =head2 v1($url)
444
445 Accessor routine to get or set the first element of the video array.
446  
447 =cut
448  
449 0 ▶sub v1 {
Subroutine v1: not called CC=2 SCAR=17.9
Pod documented
450 0 my $obj = shift;
451 0 ▶ if (@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
452 0 my @a = $obj->video();
453 0 $a[0] = shift;
454 0 $obj->video(@a);
455 }
456 0 my @a = $obj->video();
457 0 warn("v1 returning ($a[0]) from ".join('/',@a)."\n");
458 0 return $a[0];
459 }
460  
461 =head2 v2($url)
462
463 Accessor routine to get or set the second element of the video array.
464  
465 =cut
466  
467 0 ▶sub v2 {
Subroutine v2: not called CC=2 SCAR=17.9
Pod documented
468 0 my $obj = shift;
469 0 ▶ if (@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
470 0 my @a = $obj->video();
471 0 $a[1] = shift;
472 0 warn("CPL v2 set a1 to $a[1]\n");
473 0 $obj->video(@a);
474 }
475 0 my @a = $obj->video();
476 0 return $a[1];
477 }
478  
479 =head2 v3($url)
480
481 Accessor routine to get or set the third element of the video array.
482  
483 =cut
484  
485 0 ▶sub v3 {
Subroutine v3: not called CC=2 SCAR=17.9
Pod documented
486 0 my $obj = shift;
487 0 ▶ if (@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
488 0 my @a = $obj->video();
489 0 $a[2] = shift;
490 0 $obj->video(@a);
491 }
492 0 my @a = $obj->video();
493 0 return $a[2];
494 }
495  
496 =head2 tl($cuepointname)
497
498 Create a targetList with one element.
499  
500 =cut
501  
502 1 ▶sub tl {
Subroutine tl: called CC=1 SCAR=0.0
Pod documented
503 1 my $obj = shift;
504 1 my $s = shift;
505 1 my $t = new Video::CPL::Target(cuePointRef=>$s);
506 1 my $tl = new Video::CPL::TargetList(target=>[$t]);
507 #print "tl returning:\n",Dumper($tl);
508 1 return $tl;
509 }
510  
511 =head2 parsectv()
512  
513 =cut
514  
515 1 my @FIELDS = qw(backgroundHTML frameHeight frameWidth loggingService skinButtons
516 videoHeight videoSource videoViewLayout videoWidth videoX videoY
517 webViewLayout xProgLevelData xProgLevelDir xUniqueID xVersionCPL
518 xWebServiceLoc xmlns:xsi xsi:noNamespaceSchemaLocation youtubeID);
519 1 my @MPFIELDS = qw(xmlns:xsi xsi:noNamespaceSchemaLocation);
520 1 my @PLMFIELDS = qw(backgroundHTML frameHeight frameWidth loggingService skinButtons
521 videoHeight videoSource videoViewLayout videoWidth videoX videoY
522 webViewLayout xProgLevelData xProgLevelDir xUniqueID xVersionCPL
523 xWebServiceLoc youtubeID);
524  
525 1 ▶sub parsectv {
Subroutine parsectv: called CC=15 SCAR=28.1
Pod documented
526 1 my $obj = shift;
527 1 my $initfromctv = shift;
528 1 my $ref = XMLin($initfromctv,ForceArray=>1,KeyAttr=>{},KeepRoot=>1);
529 1 my %d = %{$ref};
530 1 $obj->{'xsi:noNamespaceSchemaLocation'} = $d{"xsi:noNamespaceSchemaLocation"};
531 1 $obj->{'xmlns:xsi'} = $d{"xmlns:xsi"};
532 1 foreach my $q (@MPFIELDS){
533 2 ▶ $obj->{$q} = $d{MediaProgram}[0]{$q} if defined($d{MediaProgram}[0]{$q});
Branch: 1 branch
BranchTrueFalseTotal
if defined $d{"MediaProgram"}[0]{$q} 2 0 2
534 }
535 1 foreach my $q (@PLMFIELDS){
536 18 ▶ $obj->{$q} = $d{MediaProgram}[0]{progLevelMetadata}[0]{$q} if defined($d{MediaProgram}[0]{progLevelMetadata}[0]{$q});
Branch: 1 branch
BranchTrueFalseTotal
if defined $d{"MediaProgram"}[0]{"progLevelMetadata"}[0]{$q} 17 1 18
537 }
538 1 foreach my $q ("video"){
539 1 ▶ $obj->{$q} = $d{MediaProgram}[0]{progLevelMetadata}[0]{$q} if defined($d{MediaProgram}[0]{progLevelMetadata}[0]{$q});
Branch: 1 branch
BranchTrueFalseTotal
if defined $d{"MediaProgram"}[0]{"progLevelMetadata"}[0]{$q} 0 1 1
540 }
541 #$obj->{video} = $d{MediaProgram}[0]{progLevelMetadata[0]{video}
542 #process annotations
543 1 ▶ if (defined $d{MediaProgram}[0]{annotations}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $d{"MediaProgram"}[0]{"annotations"}) 1 0 1
544 1 my @a;
545 1 foreach my $x (@{$d{MediaProgram}[0]{annotations}[0]{annotation}}){
546 1 push @a,Video::CPL::Annotation::fromxml($obj,$x);
547 }
548 1 $obj->{annotations} = \@a;
549 }
550  
551 #process layouts
552 1 ▶ if (defined $d{MediaProgram}[0]{layouts}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $d{"MediaProgram"}[0]{"layouts"}) 1 0 1
553 1 my @l;
554 1 foreach my $x (@{$d{MediaProgram}[0]{layouts}[0]{layout}}){
555 2 push @l,Video::CPL::Layout::fromxml($x);
556 }
557 1 $obj->{layouts} = \@l;
558 }
559  
560 #process cuePoints
561 1 ▶ if (defined $d{MediaProgram}[0]{cuePoints}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $d{"MediaProgram"}[0]{"cuePoints"}) 1 0 1
562 1 foreach my $x (@{$d{MediaProgram}[0]{cuePoints}[0]{cuePt}}){
563 1 $obj->addcue(Video::CPL::Cue::fromxml($obj,$x));
564 }
565 }
566  
567 #process webPoints
568 1 ▶ if (defined $d{MediaProgram}[0]{webPoints}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $d{"MediaProgram"}[0]{"webPoints"}) 0 1 1
569 0 foreach my $x (@{$d{MediaProgram}[0]{webPoints}[0]{cuePt}}){
570 0 $obj->addwp(Video::CPL::Cue::fromxml($obj,$x));
571 }
572 }
573 #done
574 }
575  
576 =head2 newname("base")
577  
578 Returns a name of the form "basedddddddd" which is not used by any other cue point or annotation in this CPL object.
579  
580 =cut
581  
582 0 ▶sub newname {
Subroutine newname: not called CC=4 SCAR=30.0
Pod documented
583 0 my $obj = shift;
584 0 ▶ my $base = shift || "name";
Condition0%0/2
shift() || 'name'
l!l
00
MC/DC0%0/1
shift() || 'name'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
585 0 my $name;
586 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
not defined $obj->cuebyname($name) || defined $obj->annobyname($name) or do { do { $name = $base . int(rand 100000000) } } 0 0 0
Condition0%0/3
defined $obj->cuebyname($name) || defined $obj->annobyname($name)
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $obj->cuebyname($name) || defined $obj->annobyname($name)
defined $obj->cuebyname($name) defined $obj->annobyname($name)
Truth table0%0/3
A || B
A= defined $obj->cuebyname($name)B= defined $obj->annobyname($name)
ABresult
1X1
011
000
587 0 $name = $base.int(rand(100000000));
588 } until ! defined($obj->cuebyname($name)) && !defined($obj->annobyname($name));
589 0 return $name;
590 }
591  
592  
593 =head2 addcue($cue);
594  
595 Adds the created cue to the CPL object. This is not needed if reading the cue points from the video file itself, e.g. with a local .flv file.
596  
597 =cut
598  
599 1 ▶sub addcue {
Subroutine addcue: called CC=4 SCAR=17.1
Pod documented
600 1 my $obj = shift;
601 1 my $cue = shift;
602 1 $cue->parent($obj);
603 1 ▶ confess("addcue needs a time in cuePt\n") if !defined($cue->time());
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cue->time 0 1 1
604 1 push @{$obj->{cuePoints}},$cue;
605 1 my @a = @{$obj->{cuePoints}};
606 1 ▶ if ($#a > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($#a > 0) 0 1 1
607 0 my $last = $a[$#a];
608 0 my $nexttolast = $a[$#a-1];
609 0 ▶ if ($last->time() <= $nexttolast->time()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last->time <= $nexttolast->time) 0 0 0
610 0 @{$obj->{cuePoints}} = sort {$a->time() <=> $b->time()} @a;
611 }
612 }
613 1 return $cue;
614 }
615  
616 0 ▶sub getcptimes {
Subroutine getcptimes: not called CC=3 SCAR=24.8
Pod undocumented
617 0 my $obj = shift;
618 0 my @ret;
619 0 ▶ return @ret if !exists($obj->{cuePoints});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $obj->{"cuePoints"} 0 0 0
620 0 my @a = @{$obj->{cuePoints}};
621 0 foreach my $a (@a){
622 0 push @ret, $a->time();
623 }
624 0 return @ret;
625 }
626  
627 0 ▶sub cuetostring {
Subroutine cuetostring: not called CC=2 SCAR=17.9
Pod undocumented
628 0 my $obj = shift;
629 0 my $cue = shift;
630 0 ▶ if ($cue->parent() == $obj){
Branch: 1 branch
BranchTrueFalseTotal
if ($cue->parent == $obj) 0 0 0
631 0 return "#".$cue->name();
632 }
633 #if same object then #foo
634 #if same directory (think: dynamic, html and ref but no file) then foo.ctv#foo
635 #think. user specified full html and ref or no ref. Only need http if not specified.
636 #else full url
637 0 confess;
638 }
639  
640 0 ▶sub annotostring {
Subroutine annotostring: not called CC=1 SCAR=6.9
Pod undocumented
641 0 my $obj = shift;
642 0 my $anno = shift;
643 #see comments for cuetostring re local versus same versus remote
644 0 confess;
645 }
646  
647 0 ▶sub converttarget {
Subroutine converttarget: not called CC=14 SCAR=53.5
Pod undocumented
648 0 my $obj = shift;
649 0 my %p = @_;
650 0 ▶ return %p if !exists $p{target};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $p{"target"} 0 0 0
651 0 ▶ confess("converttarget given a null target\n") if !defined $p{target};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p{"target"} 0 0 0
652 0 my $t = $p{target};
653 0 my @a;
654 0 ▶ if (ref($t) eq "ARRAY"){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $t eq 'ARRAY') { } 0 0 0
655 0 @a = @{$t}
656 } else {
657 0 push @a,$t;
658 }
659 0 delete $p{target};
660 0 $p{targetList} = new Video::CPL::TargetList();
661 0 ▶ if (defined $p{backgroundPicLoc}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p{"backgroundPicLoc"}) 0 0 0
662 0 $p{targetList}->backgroundPicLoc($p{backgroundPicLoc});
663 0 delete $p{backgroundPicLoc};
664 }
665 0 ▶ if (defined $p{headerText}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p{"headerText"}) 0 0 0
666 0 $p{targetList}->headerText($p{headerText});
667 0 delete $p{headerText};
668 }
669 0 ▶ if (defined $p{operation}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p{"operation"}) 0 0 0
670 0 $p{targetList}->operation($p{operation});
671 0 delete $p{operation};
672 }
673 0 my @t;
674 0 foreach my $q (@a){
675 0 my $s;
676 0 ▶ if (ref($q) eq "Video::CPL::Cue"){
Branch: 2 branches
BranchTrueFalseTotal
if (ref $q eq 'Video::CPL::Cue') { } 0 0 0
elsif (ref $q eq 'Video::CPL::Annotation') { } 0 0 0
677 0 $s = $q->reffromobj($obj);
678 } elsif (ref($q) eq "Video::CPL::Annotation"){
679 0 $s = $q->reffromobj($obj);
680 } else {
681 #confess if not scalar.
682 0 $s = $q;
683 }
684 0 my %targp = (cuePointRef=>$s);
685 0 ▶ if (defined $p{modal}){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p{"modal"}) 0 0 0
686 0 $targp{modal} = $p{modal};
687 }
688 0 ▶ if (defined $p{association}){ #hmm, works best for a single target
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p{"association"}) 0 0 0
689 0 $targp{association} = $p{association};
690 }
691 #push @t,new Video::CPL::Target(cuePointRef=>$s);
692 0 push @t,new Video::CPL::Target(%targp);
693 }
694 0 ▶ delete $p{modal} if defined $p{modal};
Branch: 1 branch
BranchTrueFalseTotal
if defined $p{"modal"} 0 0 0
695 0 ▶ delete $p{association} if defined $p{association};
Branch: 1 branch
BranchTrueFalseTotal
if defined $p{"association"} 0 0 0
696 0 $p{targetList}->target(\@t);
697 0 return %p;
698 }
699  
700 0 ▶sub convertstory {
Subroutine convertstory: not called CC=9 SCAR=45.0
Pod undocumented
701 0 my $obj = shift;
702 0 our @FIELDS = qw(balloonText forever picLoc picOverLoc);
703 0 my %p = @_;
704 return %p if !defined($p{forever}) && !defined($p{balloonText}) &&
705 0 ▶ !defined($p{picLoc}) && !defined($p{picOverLoc});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p{"forever"} or defined $p{"balloonText"} or defined $p{"picLoc"} or defined $p{"picOverLoc"} 0 0 0
Condition0%0/9
defined $p{"forever"} or defined $p{"balloonText"} or defined $p{"picLoc"} or defined $p{"picOverLoc"}
l!l&&r!l&&!r
000
defined $p{"forever"} or defined $p{"balloonText"} or defined $p{"picLoc"}
l!l&&r!l&&!r
000
defined $p{"forever"} or defined $p{"balloonText"}
l!l&&r!l&&!r
000
MC/DC0%0/4
defined $p{"forever"} or defined $p{"balloonText"} or defined $p{"picLoc"} or defined $p{"picOverLoc"}
defined $p{"forever"} defined $p{"balloonText"} defined $p{"picLoc"} defined $p{"picOverLoc"}
Truth table0%0/5
A or B or C or D
A= defined $p{"forever"}B= defined $p{"balloonText"}C= defined $p{"picLoc"}D= defined $p{"picOverLoc"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
706 0 $p{story} = new Video::CPL::Story();
707 0 ▶ if (defined($p{forever})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p{"forever"}) 0 0 0
708 0 $p{story}->forever($p{forever});
709 0 delete $p{forever};
710 }
711 0 ▶ if (defined($p{balloonText})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p{"balloonText"}) 0 0 0
712 0 $p{story}->balloonText($p{balloonText});
713 0 delete $p{balloonText};
714 }
715 0 ▶ if (defined($p{picLoc})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p{"picLoc"}) 0 0 0
716 0 $p{story}->picLoc($p{picLoc});
717 0 delete $p{picLoc};
718 }
719 0 ▶ if (defined($p{picOverLoc})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p{"picOverLoc"}) 0 0 0
720 0 $p{story}->picOverLoc($p{picOverLoc});
721 0 delete $p{picLoc};
722 }
723 0 return %p;
724 }
725  
726 =head2 newcue(%cueparms)
727  
728 Create a new Cue point with the given parameters, and set the parent to this CPL object.
729  
730 =cut
731  
732 0 ▶sub newcue {
Subroutine newcue: not called CC=7 SCAR=40.3
Pod documented
733 0 my $obj = shift;
734 0 my %parms = @_;
735 0 ▶ confess("newcue needs a time in cuePt\n") if !defined($parms{'time'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parms{"time"} 0 0 0
736 0 ▶ $parms{name} = $obj->newname("cue") if !defined($parms{name});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parms{"name"} 0 0 0
737 #convert target to a targetlist with one entry. If there are other Targetlist
738 0 ▶ %parms = $obj->converttarget(%parms) if defined $parms{target};
Branch: 1 branch
BranchTrueFalseTotal
if defined $parms{"target"} 0 0 0
739 0 ▶ %parms = $obj->convertstory(%parms) if defined($parms{picLoc}) || defined($parms{picOverLoc}) || defined($parms{balloonText});
Branch: 1 branch
BranchTrueFalseTotal
if defined $parms{"picLoc"} or defined $parms{"picOverLoc"} or defined $parms{"balloonText"} 0 0 0
Condition0%0/6
defined $parms{"picLoc"} or defined $parms{"picOverLoc"} or defined $parms{"balloonText"}
l!l&&r!l&&!r
000
defined $parms{"picLoc"} or defined $parms{"picOverLoc"}
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $parms{"picLoc"} or defined $parms{"picOverLoc"} or defined $parms{"balloonText"}
defined $parms{"picLoc"} defined $parms{"picOverLoc"} defined $parms{"balloonText"}
Truth table0%0/4
A or B or C
A= defined $parms{"picLoc"}B= defined $parms{"picOverLoc"}C= defined $parms{"balloonText"}
ABCresult
1XX1
01X1
0011
0000
740 0 my $ret = new Video::CPL::Cue(%parms);
741 0 return $obj->addcue($ret);
742 }
743  
744 =head2 story(text=>"some text",pic=>"foo.jpg")
745  
746 Shorthand to create a Video::CPL::Story object.
747  
748 =cut
749  
750 0 ▶sub story {
Subroutine story: not called CC=1 SCAR=6.9
Pod documented
751 0 my $obj = shift;
752 0 my %parms = @_;
753 0 my $ret = Video::CPL::Story->new(%parms);
754 # my $text = $parms{balloonText};
755 # my $pic = $parms{picLoc};
756 # my $ret;
757 # if ($pic){
758 # if ($text){
759 # } else {
760 # $ret = Video::CPL::Story->new(picLoc=>$pic);
761 # }
762 # } else {
763 # $ret = Video::CPL::Story->new(balloonText=>$text);
764 # }
765 0 return $ret;
766 }
767  
768 =head2 layout(%parms)
769  
770 Create a new layout and install it in this CPL. Pass the parameters on to Video::CPL::Layout::new.
771  
772 =cut
773  
774 2 ▶sub layout {
Subroutine layout: called CC=1 SCAR=0.0
Pod documented
775 2 my $obj = shift;
776 2 my %parms = @_;
777 2 my $ret = new Video::CPL::Layout(%parms);
778 2 push @{$obj->{layouts}},$ret;
779 2 return $ret;
780 }
781  
782 =head2 layouts() return all layouts for the current Video::CPL as an array
783  
784 =cut
785  
786 0 ▶sub layouts {
Subroutine layouts: not called CC=2 SCAR=17.9
Pod documented
787 0 my $obj = shift;
788 0 ▶ return () if !exists($obj->{layouts});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $obj->{"layouts"} 0 0 0
789 0 return @{$obj->{layouts}};
790 }
791  
792 =head2 layoutbyname($name)
793  
794 Return the layout with the given name.
795  
796 =cut
797  
798 64 ▶sub layoutbyname {
Subroutine layoutbyname: called CC=4 SCAR=14.5
Pod documented
799 64 my $obj = shift;
800 64 my $name = shift;
801 64 ▶ return undef if !defined($obj->{layouts});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $obj->{"layouts"} 0 64 64
802 64 my @l = @{$obj->{layouts}};
803 64 foreach my $l (@l){
804 64 ▶ return $l if $l->name() eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if $l->name eq $name 64 0 64
805 }
806 0 return undef;
807 }
808  
809 =head2 allstories()
810  
811 Return an array with all of the Annotation based Story objects in this CPL.
812  
813 =cut
814  
815 0 ▶sub allstories {
Subroutine allstories: not called CC=3 SCAR=24.8
Pod documented
816 0 my $obj = shift;
817 0 my @ret = ();
818 0 my @a = $obj->annotations();
819 0 foreach my $a (@a){
820 0 ▶ push @ret,$a->story() if $a->story();
Branch: 1 branch
BranchTrueFalseTotal
if $a->story 0 0 0
821 }
822 0 return @ret;
823 }
824  
825 =head2 numcue($k)
826  
827 Returns the k-th cuePoint Cue object. Note that a normally created CPL object will always create a cue point a the beginning, easily obtained with firstcue(), below.
828  
829 =cut
830  
831 0 ▶sub numcue {
Subroutine numcue: not called CC=2 SCAR=17.9
Pod documented
832 0 my $obj = shift;
833 0 my $num = shift;
834 0 ▶ if (defined($obj->{cuePoints}[$num])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj->{"cuePoints"}[$num]) 0 0 0
835 0 return $obj->{cuePoints}[$num];
836 }
837 0 return undef;
838 }
839  
840 =head2 cuePoints()
841  
842 Returns all Cue objects.
843  
844 =cut
845  
846 0 ▶sub cuePoints {
Subroutine cuePoints: not called CC=1 SCAR=6.9
Pod documented
847 0 my $obj = shift;
848 0 return @{$obj->{cuePoints}};
849 }
850  
851 =head2 numwebcue(4)
852  
853 Returns the 4th webPoint object.
854  
855 =cut
856  
857 0 ▶sub numwebcue {
Subroutine numwebcue: not called CC=2 SCAR=17.9
Pod documented
858 0 my $obj = shift;
859 0 my $num = shift;
860 0 ▶ if (defined($obj->{webPoints}[$num])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj->{"webPoints"}[$num]) 0 0 0
861 0 return $obj->{webPoints}[$num];
862 }
863 0 die "Error: There is no web cue numbered $num for ($obj->{videoSource}). Does it not have any web cue points?\n";
864 0 return undef;
865 }
866  
867 =head2 maxweb()
868  
869 =cut
870  
871 0 ▶sub maxweb {
Subroutine maxweb: not called CC=1 SCAR=6.9
Pod documented
872 0 my $obj = shift;
873 0 my @a = @{$obj->{webPoints}};
874 0 return $#a;
875 }
876  
877 =head2 max()
878  
879 =cut
880  
881 0 ▶sub max {
Subroutine max: not called CC=1 SCAR=6.9
Pod documented
882 0 my $obj = shift;
883 0 my @a = @{$obj->{cuePoints}};
884 0 return $#a;
885 }
886  
887 =head2 firstcue()
888  
889 Returns the first cuePoint Cue object.
890  
891 =cut
892  
893 0 ▶sub firstcue {
Subroutine firstcue: not called CC=2 SCAR=17.9
Pod documented
894 0 my $obj = shift;
895 0 ▶ if (defined($obj->{cuePoints}[0])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj->{"cuePoints"}[0]) 0 0 0
896 0 return $obj->{cuePoints}[0];
897 }
898 0 die "Error: There is no first cue for ($obj->{videoSource}). Does it not have any cue points?\n";
899 0 return undef;
900 }
901  
902 =head2 lastcue()
903  
904 =cut
905  
906 0 ▶sub lastcue {
Subroutine lastcue: not called CC=2 SCAR=17.9
Pod documented
907 0 my $obj = shift;
908 0 my @a = @{$obj->{cuePoints}};
909 0 ▶ return $a[$#a] if $#a > -1;
Branch: 1 branch
BranchTrueFalseTotal
if $#a > -1 0 0 0
910 0 die "Error: There is no last cue (last is $#a) for ($obj->{videoSource}). Does it not have any cue points?\n";
911 0 return undef;
912 }
913  
914 =head2 add()
915 Adds a cue point to the end of the cue point list. The parent of the cue point should either
916 not be set, or be correctly set. Cue points may only have one parent, and can therefore not be used
917 in multiple CPL objects.
918  
919 =cut
920  
921 0 ▶sub add {
Subroutine add: not called CC=3 SCAR=24.8
Pod documented
922 0 my $obj = shift;
923 0 my $cue = shift;
924 0 ▶ confess("adding a cue that belongs to someone else\n") if $cue->{parent} && ($cue->{parent} ne $obj);
Branch: 1 branch
BranchTrueFalseTotal
if $cue->{"parent"} and $cue->{"parent"} ne $obj 0 0 0
Condition0%0/3
$cue->{"parent"} and $cue->{"parent"} ne $obj
!ll&&!rl&&r
000
MC/DC0%0/2
$cue->{"parent"} and $cue->{"parent"} ne $obj
$cue->{"parent"} $cue->{"parent"} ne $obj
Truth table0%0/3
A and B
A= $cue->{"parent"}B= $cue->{"parent"} ne $obj
ABresult
0X0
100
111
925 0 $cue->{parent} = $obj;
926 0 push @{$obj->{cuePoints}},$cue;
927 }
928  
929 =head2 webPoints() return all webPoints for the current Video::CPL as an array
930  
931 =cut
932  
933 0 ▶sub webPoints {
Subroutine webPoints: not called CC=2 SCAR=17.9
Pod documented
934 0 my $obj = shift;
935 0 ▶ return () if !exists($obj->{webPoints});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $obj->{"webPoints"} 0 0 0
936 0 return @{$obj->{webPoints}};
937 }
938  
939 =head2 addwp()
940  
941 =cut
942  
943 0 ▶sub addwp {
Subroutine addwp: not called CC=1 SCAR=6.9
Pod documented
944 0 my $obj = shift;
945 0 my $cue = shift;
946 0 $cue->{parent} = $obj;
947 0 push @{$obj->{webPoints}},$cue;
948 }
949  
950 =head2 addanno()
951  
952 =cut
953  
954 1 ▶sub addanno {
Subroutine addanno: called CC=1 SCAR=0.0
Pod documented
955 1 my $obj = shift;
956 1 my $anno = shift;
957 1 push @{$obj->{annotations}},$anno;
958 1 return $anno;
959 }
960  
961 =head2 annotations()
962  
963 =cut
964  
965 0 ▶sub annotations {
Subroutine annotations: not called CC=2 SCAR=17.9
Pod documented
966 0 my $obj = shift;
967 0 ▶ return @{$obj->{annotations}} if defined($obj->{annotations});
Branch: 1 branch
BranchTrueFalseTotal
if defined $obj->{"annotations"} 0 0 0
968 0 return ();
969 }
970  
971 =head2 webPoint(name=>"aname",interestURL=>"http://somewhere.com/foo.jpg",story=>{picLoc=>"foo.jpg"},tl=>[$target]});
972  
973 Create and add a new webPoint object.
974  
975 Target can be created with something like Video::CPL::Cue->new("Lost A");
976  
977 Story is currently just an anonymous hash. It may become an object in a future release.
978  
979 =cut
980  
981 0 ▶sub webPoint {
Subroutine webPoint: not called CC=5 SCAR=34.0
Pod documented
982 0 my $obj = shift;
983 0 my %parms = @_;
984 0 ▶ $parms{name} = $obj->newname("webcue") if !defined($parms{name});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parms{"name"} 0 0 0
985 0 ▶ %parms = $obj->convertstory(%parms) if defined($parms{picLoc}) || defined($parms{picOverLoc}) || defined($parms{balloonText});
Branch: 1 branch
BranchTrueFalseTotal
if defined $parms{"picLoc"} or defined $parms{"picOverLoc"} or defined $parms{"balloonText"} 0 0 0
Condition0%0/6
defined $parms{"picLoc"} or defined $parms{"picOverLoc"} or defined $parms{"balloonText"}
l!l&&r!l&&!r
000
defined $parms{"picLoc"} or defined $parms{"picOverLoc"}
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $parms{"picLoc"} or defined $parms{"picOverLoc"} or defined $parms{"balloonText"}
defined $parms{"picLoc"} defined $parms{"picOverLoc"} defined $parms{"balloonText"}
Truth table0%0/4
A or B or C
A= defined $parms{"picLoc"}B= defined $parms{"picOverLoc"}C= defined $parms{"balloonText"}
ABCresult
1XX1
01X1
0011
0000
986 0 my $cue = Video::CPL::Cue->new(cueType=>'webPoint',%parms);
987 0 $obj->addwp($cue);
988 0 return $cue;
989 }
990  
991 =head2 goto(name=>"aname",tl=>[$target]});
992  
993 Create and add a new goto object.
994  
995 Target can be created with something like Video::CPL::Cue->new("Lost A");
996  
997 =cut
998  
999 0 ▶sub goto {
Subroutine goto: not called CC=6 SCAR=37.4
Pod documented
1000 0 my $obj = shift;
1001 0 my %parms = @_;
1002 #support old code for a while
1003 0 ▶ if (defined($parms{dest}) && !defined($parms{target})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parms{"dest"} and not defined $parms{"target"}) 0 0 0
Condition0%0/3
defined $parms{"dest"} and not defined $parms{"target"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $parms{"dest"} and not defined $parms{"target"}
defined $parms{"dest"} not defined $parms{"target"}
Truth table0%0/3
A and not(B)
A= defined $parms{"dest"}B= not defined $parms{"target"}
ABresult
0X0
100
111
1004 0 $parms{target} = $parms{dest};
1005 0 undef($parms{dest});
1006 }
1007 0 ▶ if (defined($parms{tl}) && !defined($parms{target})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parms{"tl"} and not defined $parms{"target"}) 0 0 0
Condition0%0/3
defined $parms{"tl"} and not defined $parms{"target"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $parms{"tl"} and not defined $parms{"target"}
defined $parms{"tl"} not defined $parms{"target"}
Truth table0%0/3
A and not(B)
A= defined $parms{"tl"}B= not defined $parms{"target"}
ABresult
0X0
100
111
1008 0 $parms{target} = shift @{$parms{tl}};
1009 0 undef($parms{tl});
1010 }
1011 0 ▶ $parms{zeroLen} = "true" if !defined $parms{zeroLen};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parms{"zeroLen"} 0 0 0
1012 0 return $obj->newcue(cueType=>'goto',%parms);
1013 }
1014  
1015 =head2 regular(name=>"cuename",time=>1.0,interestURL=>"http://somewhere.com/foo.html");
1016  
1017 Create and add a new regular object.
1018  
1019 =cut
1020  
1021 0 ▶sub regular {
Subroutine regular: not called CC=1 SCAR=6.9
Pod documented
1022 0 my $obj = shift;
1023 0 my %parms = @_;
1024 0 return $obj->newcue(cueType=>'regular',%parms);
1025 }
1026  
1027 =head2 insertPt(name=>"cuename",time=>1.0);
1028  
1029 Create and add a new regular object.
1030  
1031 =cut
1032  
1033 0 ▶sub insertPt {
Subroutine insertPt: not called CC=1 SCAR=6.9
Pod documented
1034 0 my $obj = shift;
1035 0 my %parms = @_;
1036 0 return $obj->newcue(cueType=>'insertPt',%parms);
1037 }
1038  
1039 =head2 cuebyname($name)
1040  
1041 Return the first cue with the given name.
1042  
1043 =cut
1044  
1045 56 ▶sub cuebyname {
Subroutine cuebyname: called CC=2 SCAR=7.6
Pod documented
1046 56 my $obj = shift;
1047 56 my $name = shift;
1048 56 ▶ return $obj->cuePointbyname($name) || $obj->webPointbyname($name);
Condition33%1/3
$obj->cuePointbyname($name) || $obj->webPointbyname($name)
l!l&&r!l&&!r
5600
MC/DC0%0/2
$obj->cuePointbyname($name) || $obj->webPointbyname($name)
$obj->cuePointbyname($name) $obj->webPointbyname($name)
Truth table33%1/3
A || B
A= $obj->cuePointbyname($name)B= $obj->webPointbyname($name)
ABresult
1X1
011
000
1049 }
1050  
1051 =head2 cuePointbyname($name)
1052  
1053 Return the first cuePoint with the given name.
1054  
1055 =cut
1056  
1057 56 ▶sub cuePointbyname {
Subroutine cuePointbyname: called CC=5 SCAR=17.0
Pod documented
1058 56 my $obj = shift;
1059 56 my $name = shift;
1060 56 ▶ confess "cuePointbyname no name\n" if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 56 56
1061 56 ▶ if (defined($obj->{cuePoints})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj->{"cuePoints"}) 56 0 56
1062 56 my @cuePoints = @{$obj->{cuePoints}};
1063 56 foreach my $q (@cuePoints){
1064 56 ▶ return $q if $q->name() eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if $q->name eq $name 56 0 56
1065 }
1066 }
1067 0 return undef;
1068 }
1069  
1070 =head2 webPointbyname($name)
1071  
1072 Return the first webPoint with the given name.
1073  
1074 =cut
1075  
1076 0 ▶sub webPointbyname {
Subroutine webPointbyname: not called CC=4 SCAR=30.0
Pod documented
1077 0 my $obj = shift;
1078 0 my $name = shift;
1079 0 ▶ if (defined($obj->{webPoints})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj->{"webPoints"}) 0 0 0
1080 0 my @webPoints = @{$obj->{webPoints}};
1081 0 foreach my $q (@webPoints){
1082 0 ▶ return $q if $q->name() eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if $q->name eq $name 0 0 0
1083 }
1084 }
1085 0 return undef;
1086 }
1087  
1088 =head2 cuebytime($time)
1089  
1090 Return the cuePt with the given time, or undef.
1091  
1092 =cut
1093  
1094 0 ▶sub cuebytime {
Subroutine cuebytime: not called CC=4 SCAR=30.0
Pod documented
1095 0 my $obj = shift;
1096 0 my $time = shift;
1097 0 ▶ return undef if !defined($obj->{cuePoints});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $obj->{"cuePoints"} 0 0 0
1098 0 my @cuePoints = @{$obj->{cuePoints}};
1099 0 foreach my $q (@cuePoints){
1100 0 ▶ return $q if $q->time() eq $time;
Branch: 1 branch
BranchTrueFalseTotal
if $q->time eq $time 0 0 0
1101 }
1102 0 return undef;
1103 }
1104  
1105  
1106 =head2 annobyname("name")
1107  
1108 Return the first annotation with the given name.
1109  
1110 =cut
1111  
1112 44 ▶sub annobyname {
Subroutine annobyname: called CC=4 SCAR=14.5
Pod documented
1113 44 my $obj = shift;
1114 44 my $name = shift;
1115 44 ▶ return undef if !defined $obj->{annotations};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $obj->{"annotations"} 0 44 44
1116 44 my @annos = @{$obj->{annotations}};
1117 #print STDERR "in annobyanme annos is ",Dumper(\@annos),"\n";
1118 44 foreach my $q (@annos){
1119 44 ▶ return $q if $q->name() eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if $q->name eq $name 44 0 44
1120 }
1121 0 return undef;
1122 }
1123  
1124 =head2 programEnd()
1125  
1126 =cut
1127  
1128 0 ▶sub programEnd {
Subroutine programEnd: not called CC=2 SCAR=17.9
Pod documented
1129 0 my $obj = shift;
1130 0 my %parms = @_;
1131 0 ▶ $parms{zeroLen} = "true" if !defined $parms{zeroLen};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parms{"zeroLen"} 0 0 0
1132 0 return $obj->newcue(cueType=>'programEnd',%parms);
1133 }
1134  
1135 =head2 returnEnd()
1136  
1137 =cut
1138  
1139 0 ▶sub returnEnd {
Subroutine returnEnd: not called CC=2 SCAR=17.9
Pod documented
1140 0 my $obj = shift;
1141 0 my %parms = @_;
1142 0 ▶ $parms{zeroLen} = "true" if !defined $parms{zeroLen};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parms{"zeroLen"} 0 0 0
1143 0 return $obj->newcue(cueType=>'returnEnd',%parms);
1144 }
1145  
1146 =head2 annotation()
1147
1148 Create an annotation and add it to the object.
1149  
1150 =cut
1151  
1152 1 ▶sub annotation {
Subroutine annotation: called CC=2 SCAR=7.0
Pod documented
1153 1 my $obj = shift;
1154 1 my %parms = @_;
1155 1 ▶ $parms{parent} = $obj if !defined($parms{parent});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parms{"parent"} 1 0 1
1156 1 my $anno = Video::CPL::Annotation->new(%parms);
1157 1 $obj->addanno($anno);
1158 1 return $anno;
1159 }
1160  
1161 =head2 adecoration([annotation parameters])
1162  
1163 =cut
1164  
1165 0 ▶sub adecoration {
Subroutine adecoration: not called CC=2 SCAR=17.9
Pod documented
1166 0 my $obj = shift;
1167 0 my %parms = @_;
1168 0 $parms{clickBehavior} = "decoration";
1169 0 ▶ $parms{parent} = $obj if !defined($parms{parent});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parms{"parent"} 0 0 0
1170 0 my $anno = Video::CPL::Annotation->new(%parms);
1171 0 $obj->addanno($anno);
1172 0 return $anno;
1173 }
1174  
1175 =head2 agoto([annotation parameters])
1176  
1177 adecoration,agoto,ajavascript, and areturnend are shorthand notations to create an annotation and add it
1178 to the current Video::CPL object, setting the parent correctly. Generally they are recommended if the annotation
1179 will be used more than once.
1180  
1181 $anno = $cpl->agoto(balloonText=>"go somewhere",x=>10,y=>10,target=>$somecue);
1182 $cpl->numcue(1)->addanno($anno);
1183  
1184 For a single-use annotation, Annotation::goto may be more convenient.
1185  
1186 $cpl->regular(time=>10)->goto(balloontext=>"go somewhere",x=>10,y=>10);
1187  
1188 This would create a Cue and add an annotation in one statement.
1189  
1190 The annotation parameters are used with normal Annotation constructor; therefore Story parameters such as
1191 picLoc will cause a Story to be automatically generated.
1192  
1193 =cut
1194  
1195 0 ▶sub agoto {
Subroutine agoto: not called CC=3 SCAR=24.8
Pod documented
1196 0 my $obj = shift;
1197 0 my %parms = @_;
1198 0 $parms{clickBehavior} = "goto";
1199 0 ▶ $parms{tl} = [$parms{dest}] if defined($parms{dest});
Branch: 1 branch
BranchTrueFalseTotal
if defined $parms{"dest"} 0 0 0
1200 0 delete($parms{dest});
1201 0 ▶ $parms{parent} = $obj if !defined($parms{parent});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parms{"parent"} 0 0 0
1202 0 my $anno = Video::CPL::Annotation->new(%parms);
1203 0 $obj->addanno($anno);
1204 0 return $anno;
1205 }
1206  
1207 =head2 ajavascript([annotation paramters])
1208  
1209 =cut
1210  
1211 0 ▶sub ajavascript {
Subroutine ajavascript: not called CC=2 SCAR=17.9
Pod documented
1212 0 my $obj = shift;
1213 0 my %parms = @_;
1214 0 $parms{clickBehavior} = "javascript";
1215 0 ▶ $parms{parent} = $obj if !defined($parms{parent});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parms{"parent"} 0 0 0
1216 0 my $anno = Video::CPL::Annotation->new(%parms);
1217 0 $obj->addanno($anno);
1218 0 return $anno;
1219 }
1220  
1221 =head2 areturnend()
1222  
1223 my $anno = $cpl->areturnend(balloonText=>"Return please",x=>10,y=>10);
1224 $cpl->numcue(0)->addanno($anno);
1225  
1226 =cut
1227  
1228 0 ▶sub areturnend {
Subroutine areturnend: not called CC=2 SCAR=17.9
Pod documented
1229 0 my $obj = shift;
1230 0 my %parms = @_;
1231 0 $parms{clickBehavior} = "returnEnd";
1232 0 ▶ $parms{parent} = $obj if !defined($parms{parent});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parms{"parent"} 0 0 0
1233 0 my $anno = Video::CPL::Annotation->new(%parms);
1234 0 $obj->addanno($anno);
1235 0 return $anno;
1236 }
1237  
1238 =head2 userChoice()
1239  
1240 =cut
1241  
1242 0 ▶sub userChoice {
Subroutine userChoice: not called CC=1 SCAR=6.9
Pod documented
1243 0 my $obj = shift;
1244 0 my %parms = @_;
1245 0 return $obj->newcue(cueType=>'userChoice',%parms);
1246 }
1247  
1248 =head2 xmlo($xo)
1249  
1250 Add the XML to output this object to the existing XML::Writer object xo. Creation and printing is done outside this routine.
1251  
1252 =cut
1253  
1254 1 ▶sub xmlo {
Subroutine xmlo: called CC=10 SCAR=26.0
Pod documented
1255 1 my $obj = shift;
1256 1 my $xo = shift;
1257  
1258 1 my %p;
1259 1 foreach my $q (@MPFIELDS){
1260 2 ▶ $p{$q} = $obj->{$q} if defined $obj->{$q};
Branch: 1 branch
BranchTrueFalseTotal
if defined $obj->{$q} 2 0 2
1261 }
1262  
1263 1 $xo->startTag("MediaProgram",%p);
1264 1 %p = ();
1265 #the qw defines the order of the attributes, if some order is preferred.
1266 1 foreach my $q (@PLMFIELDS){
1267 18 ▶ $p{$q} = $obj->{$q} if defined($obj->{$q});
Branch: 1 branch
BranchTrueFalseTotal
if defined $obj->{$q} 17 1 18
1268 }
1269 1 ▶ if (exists($obj->{video})){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $obj->{'video'}) { } 0 1 1
1270 0 $xo->startTag("progLevelMetadata",%p);
1271 0 $xo->startTag("video");
1272 0 my @a = @{$obj->{video}[0]{source}};
1273 0 foreach my $ia (0..$#a){
1274 0 my %h = %{$a[$ia]};
1275 0 $xo->emptyTag("source",%h);
1276 }
1277 0 $xo->endTag("video");
1278 0 $xo->endTag("progLevelMetadata");
1279 } else {
1280 1 $xo->emptyTag("progLevelMetadata",%p);
1281 }
1282  
1283 1 foreach my $a (qw(cuePoints webPoints annotations layouts)){
1284 4 ▶ if ($obj->{$a}){
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{$a}) 3 1 4
1285 3 $xo->startTag($a);
1286 3 foreach my $c (@{$obj->{$a}}){
1287 4 $c->xmlo($xo);
1288 }
1289 3 $xo->endTag($a);
1290 }
1291 }
1292 1 $xo->endTag("MediaProgram");
1293 }
1294  
1295 =head2 xml()
1296  
1297 Return the xml format of the current CPL object. This is normally called from print, but can
1298 be called directly.
1299  
1300 =cut
1301  
1302 1 ▶sub xml {
Subroutine xml: called CC=1 SCAR=0.0
Pod documented
1303 1 my $obj = shift;
1304 1 my $a = "";
1305 1 my $xo = new XML::Writer(OUTPUT=>\$a,NEWLINES=>1);
1306 1 $obj->xmlo($xo);
1307 1 $xo->end();
1308 1 return $a;
1309 }
1310  
1311 =head2 print()
1312  
1313 Print out the current xml in the automatically created temporary file within the web-viewable file hiearchy. Use before calling embed.
1314  
1315 =cut
1316  
1317 0 ▶sub print {
Subroutine print: not called CC=2 SCAR=17.9
Pod documented
1318 0 my $obj = shift;
1319 0 ▶ $obj->fixfile() if !$obj->{filefixed};
Branch: 1 branch
BranchTrueFalseTotal
unless $obj->{"filefixed"} 0 0 0
1320 0 my $fh = $obj->{fh};
1321 0 print $fh $obj->xml();
1322 0 close $fh;
1323 }
1324  
1325 =head2 embed([height=>yyy,width=>xxx])
1326  
1327 Return the html code used to embed a CPL screen within an html file.
1328  
1329 The height and width parameters are optional, and may be specified as percent or pixels. If not specified, height will be set to 392 pixels and width to 680 pixels.
1330  
1331 CPL parameters that can be specified:
1332 height: Height in pixels or percent. Defaults to frameHeight else videoHeight else 680 pixels.
1333 width: Width in pixels or percent. Defaults to frameWidth else videoWidth else 415 pixels.
1334 player: a URL that reaches the desired Flash player. If not specified, will default to a player
1335 at Coincident TV. This will not be able to access images etc. from a different server unless
1336 there is a file "crossdomain.xml" at the top level of that server. This file should look like
1337  
1338 <?xml version="1.0"?>
1339 <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
1340 <cross-domain-policy>
1341 <allow-access-from domain="*" />
1342 <site-control permitted-cross-domain-policies="all"/>
1343 </cross-domain-policy>
1344  
1345 media: the URL of the media CTV. If a partial URL, it will be relative to the player.
1346 mergedstyle: if true, include the media as a CGI parameter to the player. This is the norm when using the full CPL experience.
1347  
1348 Additional Adobe parameters:
1349 align: defaults to "middle".
1350 play: defaults to "true".
1351 quality: defaults to "autohigh".
1352 allowfullscreen: defaults to "true".
1353 allowScriptAccess: defaults to "always". In this mode, a webPoint reached from "embed"-ed player
1354 will overwrite the window.
1355 type: defaults to "application/x-shockwave-flash".
1356 pluginspage: defaults to "http://www.adobecom/go/getflashplayer".
1357 bgcolor: Hex value,defaults to "#869ca7".
1358  
1359 =cut
1360  
1361 0 ▶sub embed {
Subroutine embed: not called CC=24 SCAR=64.0
Pod documented
1362 0 my $obj = shift;
1363 0 my %parms = @_;
1364 0 my $ret;
1365 0 ▶ my $media = $parms{media} || $obj->{ctvfilename};
Condition0%0/3
$parms{'media'} || $obj->{'ctvfilename'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$parms{'media'} || $obj->{'ctvfilename'}
$parms{'media'} $obj->{'ctvfilename'}
Truth table0%0/3
A || B
A= $parms{'media'}B= $obj->{'ctvfilename'}
ABresult
1X1
011
000
1366 0 ▶ my $player = $parms{flexplayer} || "http://metabase.coincident.tv/cpan/player/CTVWebPlayerS.swf";
Condition0%0/2
$parms{'flexplayer'} || 'http://metabase.coincident.tv/cpan/player/CTVWebPlayerS.swf'
l!l
00
MC/DC0%0/1
$parms{'flexplayer'} || 'http://metabase.coincident.tv/cpan/player/CTVWebPlayerS.swf'
$parms{'flexplayer'}
Truth table0%0/2
A
A= $parms{'flexplayer'}
Aresult
11
00
1367 0 my $mergedstyle = $parms{mergedstyle};
1368  
1369 0 my %pr;
1370 #my %pr = $obj->print(%parms);
1371 0 ▶ $media = $pr{url} if !$parms{media};
Branch: 1 branch
BranchTrueFalseTotal
unless $parms{"media"} 0 0 0
1372  
1373 #good values are 680x415 435x276 314x208 or 1000x595
1374 #use parameter else frameWidth else videoWidth else 680 (415)
1375 0 my $width = 680;
1376 0 ▶ $width = $obj->{videoWidth} if exists($obj->{videoWidth});
Branch: 1 branch
BranchTrueFalseTotal
if exists $obj->{"videoWidth"} 0 0 0
1377 0 ▶ $width = $obj->{frameWidth} if exists($obj->{frameWidth});
Branch: 1 branch
BranchTrueFalseTotal
if exists $obj->{"frameWidth"} 0 0 0
1378 0 ▶ $width = $parms{width} if exists($parms{width});
Branch: 1 branch
BranchTrueFalseTotal
if exists $parms{"width"} 0 0 0
1379 0 my $height = 415;
1380 0 ▶ $height = $obj->{videoHeight} if exists($obj->{videoHeight});
Branch: 1 branch
BranchTrueFalseTotal
if exists $obj->{"videoHeight"} 0 0 0
1381 0 ▶ $height = $obj->{frameHeight} if exists($obj->{frameHeight});
Branch: 1 branch
BranchTrueFalseTotal
if exists $obj->{"frameHeight"} 0 0 0
1382 0 ▶ $height = $parms{height} if exists($parms{height});
Branch: 1 branch
BranchTrueFalseTotal
if exists $parms{"height"} 0 0 0
1383  
1384 0 ▶ $media = $obj->{ctvfilename} if !$media && exists($obj->{ctvfilename});
Branch: 1 branch
BranchTrueFalseTotal
if not $media and exists $obj->{"ctvfilename"} 0 0 0
Condition0%0/3
not $media and exists $obj->{"ctvfilename"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $media and exists $obj->{"ctvfilename"}
not $media exists $obj->{"ctvfilename"}
Truth table0%0/3
not(A) and B
A= not $mediaB= exists $obj->{"ctvfilename"}
ABresult
0X0
100
111
1385 0 ▶ confess("No media in embed\n") if !$media;
Branch: 1 branch
BranchTrueFalseTotal
unless $media 0 0 0
1386 #print '<embed src="/flash_flex_player.swf" quality="high" bgcolor="#869ca7"'."\n";
1387 0 my %ret;
1388 0 ▶ $ret{src} = $mergedstyle?"$player?media=$media":$player;
Branch: 1 branch
BranchTrueFalseTotal
$mergedstyle ? : 0 0 0
1389 0 ▶ $ret{flashvars} = "media=".$media if !$mergedstyle;
Branch: 1 branch
BranchTrueFalseTotal
unless $mergedstyle 0 0 0
1390 0 $ret{width} = $width;
1391 0 $ret{height} = $height;
1392 0 ▶ $ret{align} = exists($parms{align})?$parms{align}:"middle";
Branch: 1 branch
BranchTrueFalseTotal
exists $parms{'align'} ? : 0 0 0
1393 0 ▶ $ret{play} = exists($parms{play})?$parms{play}:"true";
Branch: 1 branch
BranchTrueFalseTotal
exists $parms{'play'} ? : 0 0 0
1394 0 ▶ $ret{quality} = exists($parms{quality})?$parms{quality}:"autohigh";
Branch: 1 branch
BranchTrueFalseTotal
exists $parms{'quality'} ? : 0 0 0
1395 0 ▶ $ret{allowfullscreen} = exists($parms{allowfullscreen})?$parms{allowfullscreen}:"true";
Branch: 1 branch
BranchTrueFalseTotal
exists $parms{'allowfullscreen'} ? : 0 0 0
1396 0 ▶ $ret{allowScriptAccess} = exists($parms{allowScriptAccess})?$parms{allowScriptAccess}:"always";
Branch: 1 branch
BranchTrueFalseTotal
exists $parms{'allowScriptAccess'} ? : 0 0 0
1397 0 ▶ $ret{type} = exists($parms{type})?$parms{type}:"application/x-shockwave-flash";
Branch: 1 branch
BranchTrueFalseTotal
exists $parms{'type'} ? : 0 0 0
1398 0 ▶ $ret{pluginspage} = exists($parms{pluginspage})?$parms{pluginspage}:"http://www.adobe.com/go/getflashplayer";
Branch: 1 branch
BranchTrueFalseTotal
exists $parms{'pluginspage'} ? : 0 0 0
1399 0 ▶ $ret{bgcolor} = exists($parms{bgcolor})?$parms{bgcolor}:"#869ca7";
Branch: 1 branch
BranchTrueFalseTotal
exists $parms{'bgcolor'} ? : 0 0 0
1400 0 my @ret;
1401 0 foreach my $k (keys %ret){
1402 0 push @ret, "$k=\"$ret{$k}\"";
1403 }
1404 0 return "<embed ".join("\n",@ret).">\n";
1405 }
1406  
1407 =head2 Video::CPL::checkready(local=>$file)
1408  
1409 This is a function, and not a method. Typically it is called before creating a CPL object
1410  
1411 =cut
1412  
1413 0 ▶sub checkready {
Subroutine checkready: not called CC=10 SCAR=47.0
Pod documented
1414 0 my %p = @_;
1415 0 my $SRC = "http://metabase.coincident.tv/cpan/player/";
1416 #if local, just get the player
1417 #if dir, get everything into said directory
1418 0 ▶ if ($p{local}){
Branch: 2 branches
BranchTrueFalseTotal
if ($p{'local'}) { } 0 0 0
elsif ($p{'dir'}) { } 0 0 0
1419 0 ▶ return 1 if -r $p{local} && (-s $p{local} > 200000);
Branch: 1 branch
BranchTrueFalseTotal
if -r $p{"local"} and -s $p{"local"} > 200000 0 0 0
Condition0%0/3
-r $p{"local"} and -s $p{"local"} > 200000
!ll&&!rl&&r
000
MC/DC0%0/2
-r $p{"local"} and -s $p{"local"} > 200000
-r $p{"local"} -s $p{"local"} > 200000
Truth table0%0/3
A and B
A= -r $p{"local"}B= -s $p{"local"} > 200000
ABresult
0X0
100
111
1420 0 ▶ return 1 if getfile("$SRC/CTVWebPlayerS.swf",$p{local},200000);
Branch: 1 branch
BranchTrueFalseTotal
if getfile("$SRC/CTVWebPlayerS.swf", $p{"local"}, 200000) 0 0 0
1421 0 return 0;
1422 } elsif ($p{dir}){
1423 0 my %files = ("CTVWebPlayerS.swf"=>400000,
1424 "defaultSkin.html"=>100,
1425 "index.html"=>2000,
1426 "styles.css"=>500,
1427 "preLoader/CTVPreLoader.swf"=>2000,
1428 "scripts/CTVLayoutFunc.js"=>5000,
1429 "scripts/expressInstall.swf"=>100,
1430 "scripts/jquery-1.3.2.min.js"=>10000,
1431 "scripts/swfobject.js"=>3000,
1432 "ui/CTVCloseButton-over.png"=>100,
1433 "ui/CTVCloseButton.png"=>100);
1434 0 ▶ make_path($p{dir}) if !-d $p{dir};
Branch: 1 branch
BranchTrueFalseTotal
unless -d $p{"dir"} 0 0 0
1435 0 foreach my $x (keys %files){
1436 0 ▶ if ($x =~ /(.*)\//){
Branch: 1 branch
BranchTrueFalseTotal
if ($x =~ m[(.*)/]) 0 0 0
1437 0 my $prefix = $1;
1438 0 ▶ make_path("$p{dir}/$prefix") if !-d "$p{dir}/$prefix";
Branch: 1 branch
BranchTrueFalseTotal
unless -d qq[$p{"dir"}/$prefix] 0 0 0
1439 }
1440 0 getfile("$SRC$x","$p{dir}/$x",$files{$x});
1441 }
1442 }
1443 }
1444  
1445 0 ▶sub getfile {
Subroutine getfile: not called CC=4 SCAR=30.0
Pod undocumented
1446 0 my $url = shift;
1447 0 my $file = shift;
1448 0 my $minsize = shift;
1449 0 my $fil = get($url);
1450 0 ▶ if (length($fil) < $minsize){
Branch: 1 branch
BranchTrueFalseTotal
if (length $fil < $minsize) 0 0 0
1451 0 warn("Video::CPL checkready/getfile: tried to fetch ($file) from ($url) but it was shorter than expected ($minsize), failing.\n");
1452 0 return 0;
1453 }
1454 0 ▶ if (open(FSWF,">$file")){
Branch: 1 branch
BranchTrueFalseTotal
if (open FSWF, ">$file") { } 0 0 0
1455 0 print FSWF $fil;
1456 0 close FSWF;
1457 0 my $actual = -s $file;
1458 0 ▶ if ($actual != length($fil)){
Branch: 1 branch
BranchTrueFalseTotal
if ($actual != length $fil) 0 0 0
1459 0 warn("Video::CPL checkready/getfile: fetched ($file) from ($url) of length ".length($fil)." but only wrote $actual bytes, failing.\n");
1460 0 return 0;
1461 }
1462 0 return 1;
1463 } else {
1464 0 warn("Video::CPL checkready/getfile: fetched from ($url), could not write to ($file), failing.\n");
1465 0 return 0;
1466 }
1467 }
1468  
1469 =head2 isyoutube($url)
1470  
1471 Return true if this URL appears to be a Youtube video.
1472  
1473 =cut
1474  
1475 0 ▶sub isyoutube {
Subroutine isyoutube: not called CC=2 SCAR=17.9
Pod documented
1476 #utility routine, not an object method
1477 0 my $x = shift;
1478 0 ▶ return undef if $x !~ /http:\/\/www.youtube.com\/watch\?v=([A-Za-z0-9\-\_]{11})/;
Branch: 1 branch
BranchTrueFalseTotal
unless $x =~ m[http://www.youtube.com/watch\?v=([A-Za-z0-9\-\_]{11})] 0 0 0
1479 0 my $code = $1;
1480 0 return youtubefromcode($code);
1481 }
1482  
1483 =head1 AUTHOR
1484  
1485 Carl Rosenberg, C<< <perl at coincident.tv> >>
1486  
1487 =head1 BUGS
1488  
1489 Please report any bugs to Coincident TV.
1490  
1491 =head1 SUPPORT
1492  
1493 You can find documentation for this module with the perldoc command.
1494  
1495 perldoc CPL
1496  
1497 =head1 ACKNOWLEDGEMENTS
1498  
1499 This is actually just a straightforward interface to the work done by the rest of the Coincident team.
1500  
1501 =head1 LICENSE AND COPYRIGHT
1502  
1503 Copyright 2010 Coincident TV
1504  
1505 Licensed under the Apache License, Version 2.0 (the "License");
1506 you may not use this file except in compliance with the License.
1507 You may obtain a copy of the License at
1508  
1509 http://www.apache.org/licenses/LICENSE-2.0
1510  
1511 Unless required by applicable law or agreed to in writing, software
1512 distributed under the License is distributed on an "AS IS" BASIS,
1513 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1514 See the License for the specific language governing permissions and
1515 limitations under the License.
1516  
1517 =cut
1518  
1519 1 1; # End of CPL
↑ Summary CPL/Cue.pm »