File Coverage

blib/lib/Resource/Pack/jQuery.pm
Criterion Covered Total %
statement 2 4 50.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 4 6 66.6


line stmt bran cond sub pod time code
1             package Resource::Pack::jQuery;
2             BEGIN {
3 1     1   815 $Resource::Pack::jQuery::VERSION = '0.01';
4             }
5 1     1   532 use Moose;
  0            
  0            
6             use Resource::Pack;
7              
8             extends 'Resource::Pack::Resource';
9              
10             =head1 NAME
11              
12             Resource::Pack::jQuery - Resource::Pack resource for the jQuery Javascript library
13              
14             =head1 VERSION
15              
16             version 0.01
17              
18             =head1 SYNOPSIS
19              
20             my $resource = Resource::Pack::jQuery->new(
21             install_to => '/var/www/js',
22             version => '1.4.2',
23             );
24             $resource->install;
25              
26             =head1 DESCRIPTION
27              
28             This provides the jQuery library as a L<Resource::Pack> resource.
29              
30             =cut
31              
32             =head1 ATTRIBUTES
33              
34             =cut
35              
36             =head2 version
37              
38             The desired jQuery version. Required, if C<use_bundled> is false.
39              
40             =cut
41              
42             has version => (
43             is => 'ro',
44             isa => 'Str',
45             );
46              
47             =head2 minified
48              
49             Whether or not the Javascript should be minified. Defaults to true.
50              
51             =cut
52              
53             has minified => (
54             is => 'ro',
55             isa => 'Bool',
56             default => 1,
57             );
58              
59             =head2 use_bundled
60              
61             If true, uses the bundled copy of jquery-1.4.2.min.js that is shipped with
62             this dist (and ignores the other attributes). Otherwise, uses the values of
63             C<version> and C<minified> to download a copy of the library from
64             L<http://code.jquery.com/>.
65              
66             =cut
67              
68             has use_bundled => (
69             is => 'ro',
70             isa => 'Bool',
71             default => 0,
72             );
73              
74             has '+name' => (default => 'jquery');
75              
76             sub _jquery_url {
77             my $self = shift;
78             return 'http://code.jquery.com/jquery-'
79             . $self->version
80             . ($self->minified ? '.min' : '')
81             . '.js';
82             }
83              
84             sub BUILD {
85             my $self = shift;
86              
87             if (!defined($self->version) && !$self->use_bundled) {
88             confess "version must be specified if use_bundled is false";
89             }
90              
91             resource $self => as {
92             install_from(Path::Class::Dir->new(__FILE__)->parent);
93             if ($self->use_bundled) {
94             file js => 'jquery-1.4.2.min.js';
95             }
96             else {
97             url js => $self->_jquery_url;
98             }
99             };
100             }
101              
102             __PACKAGE__->meta->make_immutable;
103             no Moose;
104             no Resource::Pack;
105              
106             =head1 BUGS
107              
108             No known bugs.
109              
110             Please report any bugs through RT: email
111             C<bug-resource-pack-jquery at rt.cpan.org>, or browse to
112             L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Resource-Pack-jQuery>.
113              
114             =head1 SEE ALSO
115              
116             L<Resource::Pack>
117              
118             L<http://jquery.com/>
119              
120             =head1 SUPPORT
121              
122             You can find this documentation for this module with the perldoc command.
123              
124             perldoc Resource::Pack::jQuery
125              
126             You can also look for information at:
127              
128             =over 4
129              
130             =item * AnnoCPAN: Annotated CPAN documentation
131              
132             L<http://annocpan.org/dist/Resource-Pack-jQuery>
133              
134             =item * CPAN Ratings
135              
136             L<http://cpanratings.perl.org/d/Resource-Pack-jQuery>
137              
138             =item * RT: CPAN's request tracker
139              
140             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Resource-Pack-jQuery>
141              
142             =item * Search CPAN
143              
144             L<http://search.cpan.org/dist/Resource-Pack-jQuery>
145              
146             =back
147              
148             =head1 AUTHOR
149              
150             Jesse Luehrs <doy at tozt dot net>
151              
152             John Resig is the author of jQuery
153              
154             =head1 COPYRIGHT AND LICENSE
155              
156             This software is copyright (c) 2010 by Jesse Luehrs.
157              
158             This is free software; you can redistribute it and/or modify it under
159             the same terms as perl itself.
160              
161             The bundled copy of jQuery is copyright (c) 2010 The jQuery Project.
162             It is licensed under either the MIT license or the GPLv2.
163              
164             =cut
165              
166             1;