line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dist::Zilla::Plugin::jQuery; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
465
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
5
|
1
|
|
|
1
|
|
287
|
use Moose; |
|
1
|
|
|
|
|
401081
|
|
|
1
|
|
|
|
|
6
|
|
6
|
1
|
|
|
1
|
|
6610
|
use Resource::Pack::jQuery; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use File::Temp qw( tempdir ); |
8
|
|
|
|
|
|
|
use Path::Class qw( file dir ); |
9
|
|
|
|
|
|
|
use Moose::Util::TypeConstraints qw( enum ); |
10
|
|
|
|
|
|
|
use File::Glob qw( bsd_glob ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Dist::Zilla::Role::FileGatherer'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use namespace::autoclean; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# ABSTRACT: Include jQuery in your distribution |
17
|
|
|
|
|
|
|
our $VERSION = '0.05'; # VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has version => ( |
21
|
|
|
|
|
|
|
is => 'ro', |
22
|
|
|
|
|
|
|
isa => 'Str', |
23
|
|
|
|
|
|
|
default => '1.8.2', |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has minified => ( |
28
|
|
|
|
|
|
|
is => 'ro', |
29
|
|
|
|
|
|
|
isa => enum([qw(yes no both)]), |
30
|
|
|
|
|
|
|
default => 'both', |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has dir => ( |
35
|
|
|
|
|
|
|
is => 'ro', |
36
|
|
|
|
|
|
|
isa => 'Str', |
37
|
|
|
|
|
|
|
lazy => 1, |
38
|
|
|
|
|
|
|
default => sub { |
39
|
|
|
|
|
|
|
my $self = shift; |
40
|
|
|
|
|
|
|
my $main_module = file( $self->zilla->main_module->name ); |
41
|
|
|
|
|
|
|
(my $base = $main_module->basename) =~ s/\.pm//; |
42
|
|
|
|
|
|
|
my $dir = $main_module->dir->subdir($base, 'public', 'js')->stringify; |
43
|
|
|
|
|
|
|
$self->log("using default dir $dir"); |
44
|
|
|
|
|
|
|
$dir; |
45
|
|
|
|
|
|
|
}, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has location => ( |
50
|
|
|
|
|
|
|
is => 'ro', |
51
|
|
|
|
|
|
|
isa => enum([qw(build root)]), |
52
|
|
|
|
|
|
|
default => 'build', |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
has cache => ( |
57
|
|
|
|
|
|
|
is => 'ro', |
58
|
|
|
|
|
|
|
isa => 'Bool', |
59
|
|
|
|
|
|
|
default => 0, |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
has _cache_dir => ( |
63
|
|
|
|
|
|
|
is => 'ro', |
64
|
|
|
|
|
|
|
isa => 'Path::Class::Dir', |
65
|
|
|
|
|
|
|
lazy => 1, |
66
|
|
|
|
|
|
|
default => sub { |
67
|
|
|
|
|
|
|
my $self = shift; |
68
|
|
|
|
|
|
|
if(!$self->cache) |
69
|
|
|
|
|
|
|
{ |
70
|
|
|
|
|
|
|
return dir( tempdir( CLEANUP => 1) ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
else |
73
|
|
|
|
|
|
|
{ |
74
|
|
|
|
|
|
|
my $dir = dir( bsd_glob '~/.local/share/Perl/dist/Dist-Zilla-Plugin-jQuery' ); |
75
|
|
|
|
|
|
|
$dir->mkpath(0,0700); |
76
|
|
|
|
|
|
|
$dir = $dir->subdir( $self->version, $self->minified ); |
77
|
|
|
|
|
|
|
unless(-d $dir) |
78
|
|
|
|
|
|
|
{ |
79
|
|
|
|
|
|
|
$dir->mkpath(0, 0755); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
return $dir; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
}, |
84
|
|
|
|
|
|
|
); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _install_temp |
88
|
|
|
|
|
|
|
{ |
89
|
|
|
|
|
|
|
my($self) = @_; |
90
|
|
|
|
|
|
|
my $dir = $self->_cache_dir; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# keep caches around for at least 30 days |
93
|
|
|
|
|
|
|
my $timestamp = $dir->file('.timestamp'); |
94
|
|
|
|
|
|
|
if(-e $timestamp && time < $timestamp->slurp + 60*60*24*30) |
95
|
|
|
|
|
|
|
{ |
96
|
|
|
|
|
|
|
return $dir; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
unlink $_->stringify for $dir->children(no_hidden => 1); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my %args = ( |
102
|
|
|
|
|
|
|
install_to => $dir->stringify, |
103
|
|
|
|
|
|
|
version => $self->version, |
104
|
|
|
|
|
|
|
); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
if($self->minified =~ /^(yes|both)$/i) |
107
|
|
|
|
|
|
|
{ Resource::Pack::jQuery->new(%args, minified => 1)->install } |
108
|
|
|
|
|
|
|
if($self->minified =~ /^(no|both)$/i) |
109
|
|
|
|
|
|
|
{ Resource::Pack::jQuery->new(%args, minified => 0)->install } |
110
|
|
|
|
|
|
|
$timestamp->spew(time); |
111
|
|
|
|
|
|
|
return $dir; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub gather_files |
115
|
|
|
|
|
|
|
{ |
116
|
|
|
|
|
|
|
my($self, $arg) = @_; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my $temp = $self->_install_temp; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
foreach my $child ($temp->children(no_hidden => 1)) |
121
|
|
|
|
|
|
|
{ |
122
|
|
|
|
|
|
|
$self->log("adding " . $child->basename . " to " . $self->dir ); |
123
|
|
|
|
|
|
|
if($self->location eq 'build') |
124
|
|
|
|
|
|
|
{ |
125
|
|
|
|
|
|
|
$self->add_file( |
126
|
|
|
|
|
|
|
Dist::Zilla::File::InMemory->new( |
127
|
|
|
|
|
|
|
content => scalar $child->slurp(iomode => '<:encoding(UTF-8)'), |
128
|
|
|
|
|
|
|
name => dir( $self->dir )->file( $child->basename )->stringify, |
129
|
|
|
|
|
|
|
), |
130
|
|
|
|
|
|
|
); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
else |
133
|
|
|
|
|
|
|
{ |
134
|
|
|
|
|
|
|
my $file = dir($self->zilla->root)->file( $self->dir, $child->basename ); |
135
|
|
|
|
|
|
|
$file->parent->mkpath(0, 0755); |
136
|
|
|
|
|
|
|
$file->spew( iomode => '>:encoding(UTF-8)', scalar $child->slurp(iomode => '<:encoding(UTF-8)') ); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
return; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
__END__ |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=pod |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=encoding UTF-8 |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 NAME |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Dist::Zilla::Plugin::jQuery - Include jQuery in your distribution |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 VERSION |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
version 0.05 |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 SYNOPSIS |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
[jQuery] |
163
|
|
|
|
|
|
|
version = 1.8.2 |
164
|
|
|
|
|
|
|
minified = both |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 DESCRIPTION |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This plugin fetches jQuery from the Internet |
169
|
|
|
|
|
|
|
using L<Resource::Pack::jQuery> and includes it into your distribution. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 version |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
The jQuery version to download. Defaults to 1.8.2 (the default may |
176
|
|
|
|
|
|
|
change in the future). |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 minified |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Whether or not the JavaScript should be minified. Defaults to both. |
181
|
|
|
|
|
|
|
Possible values. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=over 4 |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=item * yes |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item * no |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item * both |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=back |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head2 dir |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Which directory to put jQuery into. Defaults to public/js under |
196
|
|
|
|
|
|
|
the same location of your main module, so if your module is |
197
|
|
|
|
|
|
|
Foo::Bar (lib/Foo/Bar.pm), then the default dir will be |
198
|
|
|
|
|
|
|
lib/Foo/Bar/public/js. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head2 location |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Where to put jQuery. Choices are: |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=over 4 |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item build |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
This puts jQuery in the directory where the dist is currently |
209
|
|
|
|
|
|
|
being built, where it will be incorporated into the dist. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=item root |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
This puts jQuery in the root directory (The same directory |
214
|
|
|
|
|
|
|
that contains F<dist.ini>). It will also be included in the |
215
|
|
|
|
|
|
|
built distribution. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=back |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head2 cache |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Cache the results so that the Internet is required less frequently. |
222
|
|
|
|
|
|
|
Defaults to 0. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 METHODS |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head2 $plugin-E<gt>gather_files |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
This method places the fetched jQuery sources into your distribution. |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 CAVEATS |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
If you bundle jQuery into your distribution, you should update the copyright |
233
|
|
|
|
|
|
|
section to include a notice that bundled copy of jQuery is copyright |
234
|
|
|
|
|
|
|
the jQuery Project and is licensed under either the MIT or GPLv2 license. |
235
|
|
|
|
|
|
|
This module does not bundle jQuery, but its dependency L<Resource::Pack::jQuery> |
236
|
|
|
|
|
|
|
does. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head1 SEE ALSO |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
L<Resource::Pack::jQuery> |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 AUTHOR |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
Graham Ollis <perl@wdlabs.com> |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Graham Ollis. |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
251
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=cut |