line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Mojolicious::Plugin::AssetPack::Pipe::ExportToDirectory; |
3
|
|
|
|
|
|
|
$Mojolicious::Plugin::AssetPack::Pipe::ExportToDirectory::VERSION = '0.001002'; |
4
|
1
|
|
|
1
|
|
13874
|
use Mojo::Base 'Mojolicious::Plugin::AssetPack::Pipe'; |
|
1
|
|
|
|
|
6786
|
|
|
1
|
|
|
|
|
4
|
|
5
|
1
|
|
|
1
|
|
115936
|
use Mojo::File; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use File::Basename 'dirname'; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
47
|
|
8
|
1
|
|
|
1
|
|
4
|
use File::Path 'make_path'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
9
|
1
|
|
|
1
|
|
3
|
use File::Spec; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
14
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
403
|
use PerlIO::gzip; |
|
1
|
|
|
|
|
413
|
|
|
1
|
|
|
|
|
275
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'export_dir' => sub { $ENV{MOJO_ASSETPACK_EXPORT_DIRECTORY} || '' }; |
14
|
|
|
|
|
|
|
has 'use_checksum_subdir' => 1; |
15
|
|
|
|
|
|
|
has 'store_gzip_variant' => 0; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub process { |
19
|
0
|
|
|
0
|
1
|
|
my ( $self, $assets ) = @_; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
my $dir = $self->export_dir; |
22
|
0
|
0
|
0
|
|
|
|
unless ( defined $dir and -e -w -d $dir ) { |
23
|
0
|
|
|
|
|
|
die "Missing or inaccesable export base directory '$dir'"; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
$assets->each( |
27
|
|
|
|
|
|
|
sub { |
28
|
0
|
|
|
0
|
|
|
my $asset = shift; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my ( $file, $path ) = ( '', '' ); |
31
|
0
|
0
|
|
|
|
|
if ( $self->use_checksum_subdir ) { |
32
|
0
|
|
|
|
|
|
$file = sprintf( "%s.%s", $asset->name, $asset->format ); |
33
|
0
|
|
|
|
|
|
$path = File::Spec->catfile( $dir, $asset->checksum ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
0
|
|
|
|
|
|
$file = sprintf( "%s-%s.%s", $asset->name, $asset->checksum, $asset->format ); |
37
|
0
|
|
|
|
|
|
$path = $dir; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $p = Mojo::File->new($path); |
41
|
0
|
|
|
|
|
|
$p->make_path; |
42
|
0
|
|
|
|
|
|
$p->child($file)->spurt( $asset->content ); |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
if ( $self->store_gzip_variant ) { |
45
|
0
|
|
|
|
|
|
$file .= '.gz'; |
46
|
0
|
|
|
|
|
|
my $p_gz = $p->child($file); |
47
|
0
|
|
|
|
|
|
my $fh = $p_gz->open('>:gzip(gzip)'); |
48
|
0
|
|
|
|
|
|
print $fh $asset->content; |
49
|
0
|
|
|
|
|
|
$fh->close; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
0
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
} ## end sub process |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |