AssetPack/Pipe/CoffeeScript.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 44 CC 5 SCAR 24.8
CC
5
Cov
0%
process
20.0
_install_coffee
6.0
BEGIN
2.0
CRAP 12.0
1 package Mojolicious::Plugin::AssetPack::Pipe::CoffeeScript;
2 use Mojo::Base 'Mojolicious::Plugin::AssetPack::Pipe';
3  
4 use Mojolicious::Plugin::AssetPack::Util qw(diag $CWD DEBUG);
5  
6 sub process {
7 my ($self, $assets) = @_;
8 my $store = $self->assetpack->store;
9 my $file;
10  
11 $assets->each(sub {
12 my ($asset, $index) = @_;
13 return if $asset->format ne 'coffee';
14 my $attrs = $asset->TO_JSON;
15 @$attrs{qw(format key)} = qw(js coffee);
16 return $asset->content($file)->FROM_JSON($attrs) if $file = $store->load($attrs);
17 diag 'Process "%s" with checksum %s.', $asset->url, $attrs->{checksum} if DEBUG;
18 $self->run([qw(coffee --compile --stdio)], \$asset->content, \my $js);
19 $asset->content($store->save(\$js, $attrs))->FROM_JSON($attrs);
20 });
21 }
22  
23 sub _install_coffee {
24 my $self = shift;
25 my $path = $self->app->home->rel_file('node_modules/.bin/coffee');
26 return $path if -e $path;
27 local $CWD = $self->app->home->to_string;
28 $self->app->log->warn('Installing coffeescript... Please wait. (npm install coffeescript)');
29 $self->run([qw(npm install coffeescript)]);
30 return $path;
31 }
32  
33 1;
34  
35 =encoding utf8
36  
37 =head1 NAME
38  
39 Mojolicious::Plugin::AssetPack::Pipe::CoffeeScript - Process CoffeeScript
40  
41 =head1 DESCRIPTION
42  
43 L<Mojolicious::Plugin::AssetPack::Pipe::CoffeeScript> will process
44 L<http://coffeescript.org/> files into JavaScript.
45  
46 This module require the C<coffee> program to be installed. C<coffee> will be
47 automatically installed using L<https://www.npmjs.com/> unless already
48 installed.
49  
50 =head1 METHODS
51  
52 =head2 process
53  
54 See L<Mojolicious::Plugin::AssetPack::Pipe/process>.
55  
56 =head1 SEE ALSO
57  
58 L<Mojolicious::Plugin::AssetPack>.
59  
60 =cut