| 1 | |||||||||||||||||||||||||||||
| 2 | package Mojolicious::Plugin::AssetPack::Pipe::ExportToDirectory; | ||||||||||||||||||||||||||||
| 3 | 1 | $Mojolicious::Plugin::AssetPack::Pipe::ExportToDirectory::VERSION = '0.001003'; | |||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Mojo::Base 'Mojolicious::Plugin::AssetPack::Pipe'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Mojo::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use File::Basename 'dirname'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use File::Path 'make_path'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use PerlIO::gzip; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | has 'export_dir' => sub { $ENV{MOJO_ASSETPACK_EXPORT_DIRECTORY} || '' }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | 1 | has 'use_checksum_subdir' => 1; | |||||||||||||||||||||||||||
| 15 | 1 | has 'store_gzip_variant' => 0; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub process { | ||||||||||||||||||||||||||
|
Subroutine
process: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 0 | my ( $self, $assets ) = @_; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | my $dir = $self->export_dir; | |||||||||||||||||||||||||||
| 22 | 0 | ▶ | unless ( defined $dir and -e -w -d $dir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $dir and -e -w -d $dir
MC/DC0%0/2
defined $dir and -e -w -d $dir
defined $dir
-e -w -d $dir
Truth table0%0/3
A and B
A= defined $dirB= -e -w -d $dir
| |||||||||||||||||||||||||||||
| 23 | 0 | die "Missing or inaccesable export base directory '$dir'"; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | $assets->each( | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 28 | 0 | my $asset = shift; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | my ( $file, $path ) = ( '', '' ); | |||||||||||||||||||||||||||
| 31 | 0 | ▶ | if ( $self->use_checksum_subdir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ▶ | if ( $self->store_gzip_variant ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 1; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||||||||||