Dojo.pm

filter: Statementstmt 82.2% 97 / 118 Branchbran 57.8% 37 / 64 Conditioncond 78.9% 15 / 19 MC/DCmcdc 70.0% 7 / 10 Subroutinesub 94.1% 16 / 17 Podpod 100% 4 / 4 totaltotal 75.8% 176 / 232 CC 45 SCAR 21.9
CC
45
Cov
74%
_file_common
30.1
list
9.4
_list_src
9.0
CRAP 8.9
↑ Summary Dojo/common.pm »
1 package HTML::Dojo;
2  
3 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Carp qw/ croak /;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 our $VERSION = '0.0403.0';
9  
10 3 our $COMMON_DATA;
11 3 our $EDITIONS_DATA;
12 3 our $SRC_DATA;
13  
14 =head1 NAME
15  
16 HTML::Dojo - Provides the Dojo JavaScript / AJAX distribution 0.4.3 files.
17  
18 =head1 SYNOPSIS
19  
20 use HTML::Dojo;
21
22 my $dojo = HTML::Dojo->new;
23
24 my @editions = $dojo->editions();
25
26 my @files = $dojo->list( \%options );
27
28 my $data = $dojo->file( $filename, \%options );
29  
30 =head1 DESCRIPTION
31  
32 HTML::Dojo provides files from the Dojo JavaScript / AJAX distribution.
33  
34 These files include the C<dojo.js> file, the entire C<src> directory,
35 the C<iframe_history.html> file, various C<*.swf> files, the C<LICENSE>,
36 C<README> and C<build.txt> files.
37  
38 =head1 METHODS
39  
40 =head2 new
41  
42 $dojo->new( %options );
43  
44 This returns a HTML::Dojo object.
45  
46 Optional arguments are:
47  
48 =over
49  
50 =item C<edition>
51  
52 =back
53  
54 =cut
55  
56 2 ▶sub new {
Subroutine new: called CC=3 SCAR=15.1
Pod documented
57 2 my ($class, %args) = @_;
58
59 2 ▶ if (exists $args{edition}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"edition"}) 0 2 2
60 croak "invalid edition"
61 0 ▶ unless grep { $_ eq $args{edition} } $class->editions;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $args{"edition"};} $class->editions 0 0 0
62 }
63
64 2 return bless \%args, $class;
65 }
66  
67 # support a :no_files import flag, so that build_packages.pl can
68 # use us without locking the sub-module .pm files
69  
70 3 ▶sub import {
Subroutine import: called CC=4 SCAR=16.6
71 3 my $class = shift;
72 3 my $require = 1;
73
74 3 for (@_) {
75 0 ▶ if ($_ eq ':no_files') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq ':no_files') { } 0 0 0
76 0 $require = 0;
77 }
78 else {
79 0 croak "unknown import option: $_";
80 }
81 }
82
83 3 ▶ if ($require == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($require == 1) 3 0 3
84 3 require HTML::Dojo::common;
85 3 require HTML::Dojo::editions;
86 3 require HTML::Dojo::src;
87 }
88 }
89  
90 =head2 editions
91  
92 $dojo->editions();
93  
94 This method returns a list of all available editions. Each edition
95 represents a distribution file made available by the Dojo Foundation,
96 and as such is subject to change with each release.
97  
98 The current editions available are:
99  
100 =over
101  
102 =item ajax
103  
104 =item charting
105  
106 =item dojoWebsite
107  
108 =item editor
109  
110 =item event_and_io
111  
112 =item kitchen_sink
113  
114 =item lfx
115  
116 =item moxie
117  
118 =item storage
119  
120 =item widget
121  
122 =item xdomain-ajax
123  
124 =over
125  
126 =cut
127  
128 6 ▶sub editions {
Subroutine editions: called CC=1 SCAR=0.0
Pod documented
129 6 return qw/
130 ajax
131 charting
132 editor
133 event_and_io
134 kitchen_sink
135 src
136 storage
137 widget
138 xdomain-ajax
139 /;
140 }
141  
142 =head2 list
143  
144 $dojo->list( \%options );
145  
146 Returns an array-ref of all files available.
147  
148 Optional arguments are:
149  
150 =over
151  
152 =item C<edition>
153  
154 =item C<directories>, include directory names, default C<0>
155  
156 =item C<files>, include ordinary-file names, default C<1>
157  
158 =back
159  
160 =cut
161  
162 3 ▶sub list {
Subroutine list: called CC=9 SCAR=22.4
Pod documented
163 3 my ($self, $opt) = @_;
164
165 3 ▶ my $edition = $opt->{edition} || $self->{edition} || 'ajax';
Condition40%2/5
$opt->{'edition'} || $self->{'edition'} || 'ajax'
l!l
03
$opt->{"edition"} or $self->{"edition"}
l!l&&r!l&&!r
003
MC/DC0%0/2
$opt->{'edition'} || $self->{'edition'} || 'ajax'
$opt->{"edition"} $self->{"edition"}
Truth table33%1/3
A or B
A= $opt->{"edition"}B= $self->{"edition"}
ABresult
1X1
011
000
166 3 ▶ $opt->{directories} = 0 if ! exists $opt->{directories};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opt->{"directories"} 2 1 3
167 3 ▶ $opt->{files} = 1 if ! exists $opt->{files};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opt->{"files"} 2 1 3
168
169 3 ▶ croak "too many arguments, options must be a hash-ref" if @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 2 0 3 3
170
171 croak "invalid edition"
172 3 ▶ unless grep { $_ eq $edition } $self->editions;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $edition;} $self->editions 0 3 3
173
174 3 my @files;
175
176 push @files, $self->_editions_files( $edition )
177 3 ▶ if $opt->{files};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"files"} 2 1 3
178
179 push @files, $self->_common_files()
180 3 ▶ if $opt->{files};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"files"} 2 1 3
181
182 3 push @files, $self->_list_src( $edition, $opt );
183
184 3 return \@files;
185 }
186  
187 3 ▶sub _list_src {
Subroutine _list_src: called CC=9 SCAR=22.0
188 3 my ($self, $edition, $opt) = @_;
189 3 my @files;
190
191 3 ▶ if (! defined $SRC_DATA) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $HTML::Dojo::SRC_DATA) 1 2 3
192 1 local $/;
193 1 $SRC_DATA = eval { package HTML::Dojo::src; <DATA> };
194 }
195 # use look-ahead so the __CPAN_ line isn't removed
196 3 my @data = split /^(?=__CPAN_[^\n]+\r?\n)/m, $SRC_DATA;
197
198 3 for (@data) {
199 3654 ▶ next unless length;
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ 0 3654 3654
200
201 3654 ▶ croak "unknown format: '$_'" unless /__CPAN_(DIR|FILE)__ ([^\r\n]+)/;
Branch: 1 branch
BranchTrueFalseTotal
unless /__CPAN_(DIR|FILE)__ ([^\r\n]+)/ 0 3654 3654
202  
203 3654 ▶ if ($1 eq 'DIR' && $opt->{directories}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq "DIR" and $opt->{"directories"}) 89 3565 3654
Condition100%3/3
$1 eq "DIR" and $opt->{"directories"}
!ll&&!rl&&r
338717889
MC/DC100%2/2
$1 eq "DIR" and $opt->{"directories"}
$1 eq "DIR" $opt->{"directories"}
Truth table100%3/3
A and B
A= $1 eq "DIR"B= $opt->{"directories"}
ABresult
0X0
100
111
204 89 push @files, $2;
205 }
206
207 3654 ▶ if ($1 eq 'FILE' && $opt->{files}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq "FILE" and $opt->{"files"}) 2258 1396 3654
Condition100%3/3
$1 eq "FILE" and $opt->{"files"}
!ll&&!rl&&r
26711292258
MC/DC100%2/2
$1 eq "FILE" and $opt->{"files"}
$1 eq "FILE" $opt->{"files"}
Truth table100%3/3
A and B
A= $1 eq "FILE"B= $opt->{"files"}
ABresult
0X0
100
111
208 2258 push @files, $2;
209 }
210 }
211 3 return @files;
212 }
213  
214 =head2 file
215  
216 $dojo->file( $filename, \%options )
217  
218 Returns the contents of the named file.
219  
220 Optional arguments are:
221  
222 =over
223  
224 =item C<edition>, default C<ajax>.
225  
226 =back
227  
228 =cut
229  
230 3 ▶sub file {
Subroutine file: called CC=7 SCAR=20.1
Pod documented
231 3 my ($self, $filename, $opt) = @_;
232
233 3 ▶ my $edition = $opt->{edition} || $self->{edition} || 'ajax';
Condition80%4/5
$opt->{'edition'} || $self->{'edition'} || 'ajax'
l!l
12
$opt->{"edition"} or $self->{"edition"}
l!l&&r!l&&!r
102
MC/DC50%1/2
$opt->{'edition'} || $self->{'edition'} || 'ajax'
$opt->{"edition"} $self->{"edition"}
Truth table66%2/3
A or B
A= $opt->{"edition"}B= $self->{"edition"}
ABresult
1X1
011
000
234
235 3 ▶ croak "too many arguments, options must be a hash-ref" if @_ > 3;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 3 0 3 3
236
237 croak "invalid edition"
238 3 ▶ unless grep { $_ eq $edition } $self->editions;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $edition;} $self->editions 0 3 3
239
240 3 ▶ if (grep { $filename eq $_ } $self->_common_files) {
Branch: 2 branches
BranchTrueFalseTotal
if (grep {$filename eq $_;} $self->_common_files) { } 0 3 3
elsif (grep {$filename eq $_;} $self->_editions_files) { } 2 1 3
241 0 return $self->_file_common( $filename );
242 }
243 6 elsif (grep { $filename eq $_ } $self->_editions_files) {
244 2 return $self->_file_edition( $filename, $edition );
245 }
246 else {
247 1 return $self->_file_src( $filename );
248 }
249 }
250  
251 0 ▶sub _file_common {
Subroutine _file_common: not called CC=6 SCAR=34.1
252 0 my ($self, $filename) = @_;
253
254 0 ▶ if (! defined $COMMON_DATA) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $HTML::Dojo::COMMON_DATA) 0 0 0
255 0 local $/;
256 3 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
257 0 $COMMON_DATA = eval { package HTML::Dojo::common; <DATA> };
258 }
259 # use look-ahead so the __CPAN_ line isn't removed
260 0 my @data = split /^(?=__CPAN_[^\n]+\r?\n)/m, $COMMON_DATA;
261
262 0 for (@data) {
263 0 ▶ next unless length;
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ 0 0 0
264
265 0 ▶ croak "unknown format: '$_'"
Branch: 1 branch
BranchTrueFalseTotal
unless s/__CPAN_COMMON__ ([^\r\n]+)\r?\n// 0 0 0
266 unless s/__CPAN_COMMON__ ([^\r\n]+)\r?\n//;
267
268 0 ▶ next unless $1 eq $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless $1 eq $filename 0 0 0
269
270 0 chomp;
271 0 return $_;
272 }
273
274 0 croak "didn't find data for file '$filename''";
275 }
276  
277 2 ▶sub _file_edition {
Subroutine _file_edition: called CC=7 SCAR=19.7
278 2 my ($self, $filename, $edition) = @_;
279
280 2 ▶ if (! defined $EDITIONS_DATA) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $HTML::Dojo::EDITIONS_DATA) 1 1 2
281 1 local $/;
282 3 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
283 1 $EDITIONS_DATA = eval { package HTML::Dojo::editions; <DATA> };
284 }
285 # use look-ahead so the __CPAN_ line isn't removed
286 2 my @data = split /^(?=__CPAN_[^\n]+\r?\n)/m, $EDITIONS_DATA;
287
288 2 for (@data) {
289 10 ▶ next unless length;
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ 0 10 10
290
291 10 ▶ croak "unknown format"
Branch: 1 branch
BranchTrueFalseTotal
unless s/__CPAN_EDITION__ (\w+) ([^\r\n]+)\r?\n// 0 10 10
292 unless s/__CPAN_EDITION__ (\w+) ([^\r\n]+)\r?\n//;
293
294 10 ▶ next unless $1 eq $edition;
Branch: 1 branch
BranchTrueFalseTotal
unless $1 eq $edition 8 2 10
295 2 ▶ next unless $2 eq $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless $2 eq $filename 0 2 2
296
297 2 chomp;
298 2 return $_;
299 }
300
301 0 croak "didn't find data for file '$filename', edition '$edition'";
302 }
303  
304 1 ▶sub _file_src {
Subroutine _file_src: called CC=7 SCAR=19.8
305 1 my ($self, $filename) = @_;
306
307 1 ▶ if (! defined $SRC_DATA) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $HTML::Dojo::SRC_DATA) 1 0 1
308 1 local $/;
309 1 $SRC_DATA = eval { package HTML::Dojo::src; <DATA> };
310 }
311 # use look-ahead so the __CPAN_ line isn't removed
312 1 my @data = split /^(?=__CPAN_[^\n]+\r?\n)/m, $SRC_DATA;
313
314 1 for (@data) {
315 42 ▶ next unless length;
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ 0 42 42
316
317 42 ▶ croak "unknown format" unless s/__CPAN_(DIR|FILE)__ ([^\r\n]+)\r?\n//;
Branch: 1 branch
BranchTrueFalseTotal
unless s/__CPAN_(DIR|FILE)__ ([^\r\n]+)\r?\n// 0 42 42
318
319 42 ▶ next unless $1 eq 'FILE' && $2 eq $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless $1 eq "FILE" and $2 eq $filename 41 1 42
Condition100%3/3
$1 eq "FILE" and $2 eq $filename
!ll&&!rl&&r
1401
MC/DC100%2/2
$1 eq "FILE" and $2 eq $filename
$1 eq "FILE" $2 eq $filename
Truth table100%3/3
A and B
A= $1 eq "FILE"B= $2 eq $filename
ABresult
0X0
100
111
320
321 1 chomp;
322 1 return $_;
323 }
324
325 0 croak "didn't find data for file '$filename'";
326 }
327  
328 # internals used by build_packages.pl
329  
330 5 ▶sub _editions_files {
Subroutine _editions_files: called CC=1 SCAR=0.0
331 5 return qw/
332 dojo.js
333 build.txt
334 /;
335 }
336  
337 5 ▶sub _common_files {
Subroutine _common_files: called CC=1 SCAR=0.0
338 5 return qw/
339 iframe_history.html
340 flash6_gateway.swf
341 storage_dialog.swf
342 Storage_version6.swf
343 Storage_version8.swf
344 README
345 LICENSE
346 /;
347 }
348  
349 =head1 SEE ALSO
350  
351 L<http://dojotoolkit.org>, L<HTML::Prototype>
352  
353 =head1 SUPPORT
354  
355 Catalyst mailing list:
356  
357 http://lists.rawmode.org/mailman/listinfo/catalyst
358  
359 =head1 AUTHOR
360  
361 Carl Franks, E<lt>cfranks@cpan.orgE<gt>
362  
363 =head1 COPYRIGHT AND LICENSE
364  
365 Copyright (C) 2006 by Carl Franks
366  
367 This library is free software; you can redistribute it and/or modify
368 it under the same terms as Perl itself, either Perl version 5.8.8 or,
369 at your option, any later version of Perl 5 you may have available.
370  
371 Copyright (c) 2004-2005, The Dojo Foundation
372  
373 All Rights Reserved
374  
375 The Dojo distribution files may be redistributed under either the
376 modified BSD license or the Academic Free License version 2.1.
377  
378  
379 =cut
380  
381 3 1;
↑ Summary Dojo/common.pm »