| blib/lib/HTML/Dojo.pm | |||
|---|---|---|---|
| Criterion | Covered | Total | % |
| statement | 93 | 114 | 81.5 |
| branch | 37 | 64 | 57.8 |
| condition | 12 | 13 | 92.3 |
| subroutine | 16 | 17 | 94.1 |
| pod | 4 | 4 | 100.0 |
| total | 162 | 212 | 76.4 |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | package HTML::Dojo; | ||||||
| 2 | |||||||
| 3 | 3 | 3 | 2589 | use 5.006; | |||
| 3 | 11 | ||||||
| 3 | 111 | ||||||
| 4 | 3 | 3 | 16 | use strict; | |||
| 3 | 5 | ||||||
| 3 | 92 | ||||||
| 5 | 3 | 3 | 25 | use warnings; | |||
| 3 | 3 | ||||||
| 3 | 119 | ||||||
| 6 | 3 | 3 | 15 | use Carp qw/ croak /; | |||
| 3 | 4 | ||||||
| 3 | 2934 | ||||||
| 7 | |||||||
| 8 | our $VERSION = '0.0403.0'; | ||||||
| 9 | |||||||
| 10 | our $COMMON_DATA; | ||||||
| 11 | our $EDITIONS_DATA; | ||||||
| 12 | 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 |
||||||
| 35 | the C |
||||||
| 36 | C |
||||||
| 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 |
||||||
| 51 | |||||||
| 52 | =back | ||||||
| 53 | |||||||
| 54 | =cut | ||||||
| 55 | |||||||
| 56 | sub new { | ||||||
| 57 | 2 | 2 | 1 | 1586 | my ($class, %args) = @_; | ||
| 58 | |||||||
| 59 | 2 | 50 | 12 | if (exists $args{edition}) { | |||
| 60 | 0 | 0 | croak "invalid edition" | ||||
| 61 | 0 | 0 | 0 | unless grep { $_ eq $args{edition} } $class->editions; | |||
| 62 | } | ||||||
| 63 | |||||||
| 64 | 2 | 22 | 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 | sub import { | ||||||
| 71 | 3 | 3 | 28 | my $class = shift; | |||
| 72 | 3 | 6 | my $require = 1; | ||||
| 73 | |||||||
| 74 | 3 | 9 | for (@_) { | ||||
| 75 | 0 | 0 | 0 | if ($_ eq ':no_files') { | |||
| 76 | 0 | 0 | $require = 0; | ||||
| 77 | } | ||||||
| 78 | else { | ||||||
| 79 | 0 | 0 | croak "unknown import option: $_"; | ||||
| 80 | } | ||||||
| 81 | } | ||||||
| 82 | |||||||
| 83 | 3 | 50 | 13 | if ($require == 1) { | |||
| 84 | 3 | 2381 | require HTML::Dojo::common; | ||||
| 85 | 3 | 23492 | require HTML::Dojo::editions; | ||||
| 86 | 3 | 72028 | 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 | sub editions { | ||||||
| 129 | 6 | 6 | 1 | 27 | 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 |
||||||
| 153 | |||||||
| 154 | =item C |
||||||
| 155 | |||||||
| 156 | =item C |
||||||
| 157 | |||||||
| 158 | =back | ||||||
| 159 | |||||||
| 160 | =cut | ||||||
| 161 | |||||||
| 162 | sub list { | ||||||
| 163 | 3 | 3 | 1 | 8154 | my ($self, $opt) = @_; | ||
| 164 | |||||||
| 165 | 3 | 50 | 39 | my $edition = $opt->{edition} || $self->{edition} || 'ajax'; | |||
| 166 | 3 | 100 | 11 | $opt->{directories} = 0 if ! exists $opt->{directories}; | |||
| 167 | 3 | 100 | 13 | $opt->{files} = 1 if ! exists $opt->{files}; | |||
| 168 | |||||||
| 169 | 3 | 50 | 9 | croak "too many arguments, options must be a hash-ref" if @_ > 2; | |||
| 170 | |||||||
| 171 | 27 | 44 | croak "invalid edition" | ||||
| 172 | 3 | 50 | 10 | unless grep { $_ eq $edition } $self->editions; | |||
| 173 | |||||||
| 174 | 3 | 7 | my @files; | ||||
| 175 | |||||||
| 176 | 3 | 100 | 13 | push @files, $self->_editions_files( $edition ) | |||
| 177 | if $opt->{files}; | ||||||
| 178 | |||||||
| 179 | 3 | 100 | 13 | push @files, $self->_common_files() | |||
| 180 | if $opt->{files}; | ||||||
| 181 | |||||||
| 182 | 3 | 11 | push @files, $self->_list_src( $edition, $opt ); | ||||
| 183 | |||||||
| 184 | 3 | 107 | return \@files; | ||||
| 185 | } | ||||||
| 186 | |||||||
| 187 | sub _list_src { | ||||||
| 188 | 3 | 3 | 6 | my ($self, $edition, $opt) = @_; | |||
| 189 | 3 | 5 | my @files; | ||||
| 190 | |||||||
| 191 | 3 | 100 | 10 | if (! defined $SRC_DATA) { | |||
| 192 | 1 | 4 | local $/; | ||||
| 193 | 1 | 2 | $SRC_DATA = eval { package HTML::Dojo::src; }; | ||||
| 1 | 58160 | ||||||
| 194 | } | ||||||
| 195 | # use look-ahead so the __CPAN_ line isn't removed | ||||||
| 196 | 3 | 85225 | my @data = split /^(?=__CPAN_[^\n]+\r?\n)/m, $SRC_DATA; | ||||
| 197 | |||||||
| 198 | 3 | 155 | for (@data) { | ||||
| 199 | 3654 | 50 | 6554 | next unless length; | |||
| 200 | |||||||
| 201 | 3654 | 50 | 15924 | croak "unknown format: '$_'" unless /__CPAN_(DIR|FILE)__ ([^\r\n]+)/; | |||
| 202 | |||||||
| 203 | 3654 | 100 | 100 | 9303 | if ($1 eq 'DIR' && $opt->{directories}) { | ||
| 204 | 89 | 205 | push @files, $2; | ||||
| 205 | } | ||||||
| 206 | |||||||
| 207 | 3654 | 100 | 100 | 15482 | if ($1 eq 'FILE' && $opt->{files}) { | ||
| 208 | 2258 | 5354 | push @files, $2; | ||||
| 209 | } | ||||||
| 210 | } | ||||||
| 211 | 3 | 1568 | 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 |
||||||
| 225 | |||||||
| 226 | =back | ||||||
| 227 | |||||||
| 228 | =cut | ||||||
| 229 | |||||||
| 230 | sub file { | ||||||
| 231 | 3 | 3 | 1 | 1290 | my ($self, $filename, $opt) = @_; | ||
| 232 | |||||||
| 233 | 3 | 100 | 28 | my $edition = $opt->{edition} || $self->{edition} || 'ajax'; | |||
| 234 | |||||||
| 235 | 3 | 50 | 9 | croak "too many arguments, options must be a hash-ref" if @_ > 3; | |||
| 236 | |||||||
| 237 | 27 | 39 | croak "invalid edition" | ||||
| 238 | 3 | 50 | 12 | unless grep { $_ eq $edition } $self->editions; | |||
| 239 | |||||||
| 240 | 3 | 50 | 11 | if (grep { $filename eq $_ } $self->_common_files) { | |||
| 21 | 100 | 45 | |||||
| 6 | 16 | ||||||
| 241 | 0 | 0 | return $self->_file_common( $filename ); | ||||
| 242 | } | ||||||
| 243 | elsif (grep { $filename eq $_ } $self->_editions_files) { | ||||||
| 244 | 2 | 7 | return $self->_file_edition( $filename, $edition ); | ||||
| 245 | } | ||||||
| 246 | else { | ||||||
| 247 | 1 | 6 | return $self->_file_src( $filename ); | ||||
| 248 | } | ||||||
| 249 | } | ||||||
| 250 | |||||||
| 251 | sub _file_common { | ||||||
| 252 | 0 | 0 | 0 | my ($self, $filename) = @_; | |||
| 253 | |||||||
| 254 | 0 | 0 | 0 | if (! defined $COMMON_DATA) { | |||
| 255 | 0 | 0 | local $/; | ||||
| 256 | 3 | 3 | 17 | no warnings 'once'; | |||
| 3 | 7 | ||||||
| 3 | 750 | ||||||
| 257 | 0 | 0 | $COMMON_DATA = eval { package HTML::Dojo::common; }; | ||||
| 0 | 0 | ||||||
| 258 | } | ||||||
| 259 | # use look-ahead so the __CPAN_ line isn't removed | ||||||
| 260 | 0 | 0 | my @data = split /^(?=__CPAN_[^\n]+\r?\n)/m, $COMMON_DATA; | ||||
| 261 | |||||||
| 262 | 0 | 0 | for (@data) { | ||||
| 263 | 0 | 0 | 0 | next unless length; | |||
| 264 | |||||||
| 265 | 0 | 0 | 0 | croak "unknown format: '$_'" | |||
| 266 | unless s/__CPAN_COMMON__ ([^\r\n]+)\r?\n//; | ||||||
| 267 | |||||||
| 268 | 0 | 0 | 0 | next unless $1 eq $filename; | |||
| 269 | |||||||
| 270 | 0 | 0 | chomp; | ||||
| 271 | 0 | 0 | return $_; | ||||
| 272 | } | ||||||
| 273 | |||||||
| 274 | 0 | 0 | croak "didn't find data for file '$filename''"; | ||||
| 275 | } | ||||||
| 276 | |||||||
| 277 | sub _file_edition { | ||||||
| 278 | 2 | 2 | 3 | my ($self, $filename, $edition) = @_; | |||
| 279 | |||||||
| 280 | 2 | 100 | 5 | if (! defined $EDITIONS_DATA) { | |||
| 281 | 1 | 5 | local $/; | ||||
| 282 | 3 | 3 | 16 | no warnings 'once'; | |||
| 3 | 9 | ||||||
| 3 | 1447 | ||||||
| 283 | 1 | 1 | $EDITIONS_DATA = eval { package HTML::Dojo::editions; }; | ||||
| 1 | 2878 | ||||||
| 284 | } | ||||||
| 285 | # use look-ahead so the __CPAN_ line isn't removed | ||||||
| 286 | 2 | 19762 | my @data = split /^(?=__CPAN_[^\n]+\r?\n)/m, $EDITIONS_DATA; | ||||
| 287 | |||||||
| 288 | 2 | 18 | for (@data) { | ||||
| 289 | 10 | 50 | 44 | next unless length; | |||
| 290 | |||||||
| 291 | 10 | 50 | 1343 | croak "unknown format" | |||
| 292 | unless s/__CPAN_EDITION__ (\w+) ([^\r\n]+)\r?\n//; | ||||||
| 293 | |||||||
| 294 | 10 | 100 | 39 | next unless $1 eq $edition; | |||
| 295 | 2 | 50 | 9 | next unless $2 eq $filename; | |||
| 296 | |||||||
| 297 | 2 | 7 | chomp; | ||||
| 298 | 2 | 334 | return $_; | ||||
| 299 | } | ||||||
| 300 | |||||||
| 301 | 0 | 0 | croak "didn't find data for file '$filename', edition '$edition'"; | ||||
| 302 | } | ||||||
| 303 | |||||||
| 304 | sub _file_src { | ||||||
| 305 | 1 | 1 | 2 | my ($self, $filename) = @_; | |||
| 306 | |||||||
| 307 | 1 | 50 | 5 | if (! defined $SRC_DATA) { | |||
| 308 | 1 | 4 | local $/; | ||||
| 309 | 1 | 2 | $SRC_DATA = eval { package HTML::Dojo::src; }; | ||||
| 1 | 9561 | ||||||
| 310 | } | ||||||
| 311 | # use look-ahead so the __CPAN_ line isn't removed | ||||||
| 312 | 1 | 32725 | my @data = split /^(?=__CPAN_[^\n]+\r?\n)/m, $SRC_DATA; | ||||
| 313 | |||||||
| 314 | 1 | 45 | for (@data) { | ||||
| 315 | 42 | 50 | 117 | next unless length; | |||
| 316 | |||||||
| 317 | 42 | 50 | 415 | croak "unknown format" unless s/__CPAN_(DIR|FILE)__ ([^\r\n]+)\r?\n//; | |||
| 318 | |||||||
| 319 | 42 | 100 | 100 | 285 | next unless $1 eq 'FILE' && $2 eq $filename; | ||
| 320 | |||||||
| 321 | 1 | 4 | chomp; | ||||
| 322 | 1 | 294 | return $_; | ||||
| 323 | } | ||||||
| 324 | |||||||
| 325 | 0 | 0 | croak "didn't find data for file '$filename'"; | ||||
| 326 | } | ||||||
| 327 | |||||||
| 328 | # internals used by build_packages.pl | ||||||
| 329 | |||||||
| 330 | sub _editions_files { | ||||||
| 331 | 5 | 5 | 12 | return qw/ | |||
| 332 | dojo.js | ||||||
| 333 | build.txt | ||||||
| 334 | /; | ||||||
| 335 | } | ||||||
| 336 | |||||||
| 337 | sub _common_files { | ||||||
| 338 | 5 | 5 | 22 | 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 |
||||||
| 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 |
||||||
| 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 | 1; |