line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::AssetPack::Preprocessors; |
2
|
3
|
|
|
3
|
|
22002
|
use Mojo::Base 'Mojo::EventEmitter'; |
|
3
|
|
|
|
|
11034
|
|
|
3
|
|
|
|
|
20
|
|
3
|
3
|
|
|
3
|
|
3096
|
use Mojo::Util (); |
|
3
|
|
|
|
|
44342
|
|
|
3
|
|
|
|
|
64
|
|
4
|
3
|
|
|
3
|
|
1247
|
use Mojolicious::Plugin::AssetPack::Preprocessor; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
23
|
|
5
|
3
|
|
|
3
|
|
76
|
use File::Basename; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
203
|
|
6
|
3
|
|
|
3
|
|
1629
|
use File::Which; |
|
3
|
|
|
|
|
2295
|
|
|
3
|
|
|
|
|
145
|
|
7
|
3
|
|
|
3
|
|
1504
|
use IPC::Run3 (); |
|
3
|
|
|
|
|
34213
|
|
|
3
|
|
|
|
|
123
|
|
8
|
3
|
|
50
|
3
|
|
23
|
use constant DEBUG => $ENV{MOJO_ASSETPACK_DEBUG} || 0; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1925
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my %PREPROCESSORS = ( |
13
|
|
|
|
|
|
|
coffee => 'Mojolicious::Plugin::AssetPack::Preprocessor::CoffeeScript', |
14
|
|
|
|
|
|
|
css => 'Mojolicious::Plugin::AssetPack::Preprocessor::Css', |
15
|
|
|
|
|
|
|
js => 'Mojolicious::Plugin::AssetPack::Preprocessor::JavaScript', |
16
|
|
|
|
|
|
|
jsx => 'Mojolicious::Plugin::AssetPack::Preprocessor::Jsx', |
17
|
|
|
|
|
|
|
less => 'Mojolicious::Plugin::AssetPack::Preprocessor::Less', |
18
|
|
|
|
|
|
|
sass => 'Mojolicious::Plugin::AssetPack::Preprocessor::Sass', |
19
|
|
|
|
|
|
|
scss => 'Mojolicious::Plugin::AssetPack::Preprocessor::Scss', |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has fallback => sub { |
23
|
|
|
|
|
|
|
require Mojolicious::Plugin::AssetPack::Preprocessor::Fallback; |
24
|
|
|
|
|
|
|
Mojolicious::Plugin::AssetPack::Preprocessor::Fallback->new; |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub add { |
28
|
4
|
|
|
4
|
1
|
9
|
my ($self, $extension, $arg) = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# create object |
31
|
4
|
100
|
|
|
|
9
|
if (@_ == 4) { |
32
|
2
|
50
|
|
|
|
8
|
my $class |
33
|
|
|
|
|
|
|
= $arg =~ /::/ ? $arg : "Mojolicious::Plugin::AssetPack::Preprocessor::$arg"; |
34
|
2
|
50
|
|
|
|
204
|
eval "require $class;1" or die "Could not load $class: $@\n"; |
35
|
2
|
|
|
|
|
6
|
warn "[AssetPack] Adding $class preprocessor for $extension.\n" if DEBUG; |
36
|
2
|
|
|
|
|
19
|
my $object = $class->new(pop); |
37
|
2
|
|
|
|
|
22
|
return $self->add($extension => $object); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# back compat |
41
|
2
|
50
|
|
|
|
8
|
if (ref $arg eq 'CODE') { |
42
|
0
|
|
|
|
|
0
|
$arg = Mojolicious::Plugin::AssetPack::Preprocessor->new(processor => $arg); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
2
|
|
|
|
|
14
|
$self->on($extension => $arg); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub can_process { |
49
|
0
|
|
|
0
|
1
|
0
|
my ($self, $extension) = @_; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
for my $p ($self->_preprocessors($extension)) { |
52
|
0
|
0
|
|
|
|
0
|
return 1 if $p->can_process; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
0
|
return 0; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub checksum { |
59
|
3
|
|
|
3
|
1
|
21
|
my ($self, $extension, $text, $filename) = @_; |
60
|
3
|
|
|
|
|
93
|
my $cwd = Mojolicious::Plugin::AssetPack::Preprocessors::CWD->new(dirname $filename); |
61
|
3
|
|
|
|
|
7
|
my @checksum; |
62
|
|
|
|
|
|
|
|
63
|
3
|
|
|
|
|
11
|
for my $p ($self->_preprocessors($extension)) { |
64
|
3
|
|
|
|
|
33
|
$p->cwd($cwd->[0]); |
65
|
3
|
|
|
|
|
83
|
push @checksum, $p->checksum($text, $filename); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
3
|
50
|
|
|
|
18
|
return @checksum == 1 ? $checksum[0] : Mojo::Util::md5_sum(join '', @checksum); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub process { |
72
|
1
|
|
|
1
|
1
|
5
|
my ($self, $extension, $assetpack, $text, $filename) = @_; |
73
|
1
|
|
|
|
|
25
|
my $cwd = Mojolicious::Plugin::AssetPack::Preprocessors::CWD->new(dirname $filename); |
74
|
1
|
|
|
|
|
3
|
my @err; |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
3
|
for my $p ($self->_preprocessors($extension)) { |
77
|
1
|
|
|
|
|
5
|
$p->cwd($cwd->[0]); |
78
|
1
|
|
|
|
|
9
|
$p->($p, $assetpack, $text, $filename); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
3
|
return $self; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
0
|
1
|
0
|
sub remove { shift->unsubscribe(@_) } |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub _preprocessors { |
87
|
4
|
|
|
4
|
|
6
|
my ($self, $extension) = @_; |
88
|
4
|
|
|
|
|
4
|
my @preprocessors = @{$self->subscribers($extension)}; |
|
4
|
|
|
|
|
23
|
|
89
|
|
|
|
|
|
|
|
90
|
4
|
100
|
|
|
|
43
|
return @preprocessors if @preprocessors; |
91
|
2
|
|
|
|
|
6
|
my $class = $PREPROCESSORS{$extension}; |
92
|
2
|
50
|
|
|
|
13
|
return $self->add($extension => $class => {}) if $class; |
93
|
0
|
|
|
|
|
0
|
return $self->fallback; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
package Mojolicious::Plugin::AssetPack::Preprocessors::CWD; |
97
|
3
|
|
|
3
|
|
18
|
use Cwd; |
|
3
|
|
|
|
|
43
|
|
|
3
|
|
|
|
|
378
|
|
98
|
5
|
|
|
5
|
|
1152
|
sub new { my $self = bless [getcwd], $_[0]; chdir $_[1]; return $self; } |
|
5
|
|
|
|
|
52
|
|
|
5
|
|
|
|
|
8
|
|
99
|
5
|
|
|
5
|
|
478
|
sub DESTROY { chdir $_[0]->[0]; } |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=encoding utf8 |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 NAME |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Mojolicious::Plugin::AssetPack::Preprocessors - DEPRECATED |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 DESCRIPTION |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
L will be DEPRECATED. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 fallback |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 METHODS |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 add |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 can_process |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 checksum |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 process |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 map_type |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 remove |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 SEE ALSO |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
L |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |