| 1 | package Mojolicious::Plugin::AssetPack::Util; | ||||||||||||||||||||||||||||||||||||||
| 2 | 38 | ▶ | use Mojo::Base 'Exporter'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||
| 4 | 38 | ▶ | use Carp 'confess'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | 38 | ▶ | use Mojo::Util; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||
| 7 | 38 | ▶ | use constant DEBUG => $ENV{MOJO_ASSETPACK_DEBUG} || 0; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Condition50%1/2
$ENV{'MOJO_ASSETPACK_DEBUG'} || 0
MC/DC0%0/1
$ENV{'MOJO_ASSETPACK_DEBUG'} || 0
$ENV{'MOJO_ASSETPACK_DEBUG'}
Truth table50%1/2
A
A= $ENV{'MOJO_ASSETPACK_DEBUG'}
| |||||||||||||||||||||||||||||||||||||||
| 8 | 38 | ▶ | use constant TESTING => $ENV{HARNESS_IS_VERBOSE} || 0; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Condition50%1/2
$ENV{'HARNESS_IS_VERBOSE'} || 0
MC/DC0%0/1
$ENV{'HARNESS_IS_VERBOSE'} || 0
$ENV{'HARNESS_IS_VERBOSE'}
Truth table50%1/2
A
A= $ENV{'HARNESS_IS_VERBOSE'}
| |||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||
| 10 | 38 | our @EXPORT = qw(checksum diag dumper has_ro load_module $CWD DEBUG); | |||||||||||||||||||||||||||||||||||||
| 11 | 38 | our $SUM_LEN = 10; | |||||||||||||||||||||||||||||||||||||
| 12 | 38 | our ($TOPIC, %LOADED); | |||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||
| 14 | 38 | ▶ | tie our ($CWD), 'Mojolicious::Plugin::AssetPack::Util::_chdir' or die q(Can't tie $CWD); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||
| 16 | 47 | ▶ | sub checksum { substr Mojo::Util::sha1_sum($_[0]), 0, $SUM_LEN } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
checksum: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | sub diag { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
diag: called CC=6 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | my $f = @_ > 1 ? shift : '%s'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 20 | 2 | my ($i, $pkg) = (0); | |||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | while ($pkg = caller $i++) { $pkg =~ s!.*::(AssetPack::)Pipe::!$1! and last } | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | $pkg = 'AssetPack' unless $pkg; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | warn sprintf "%s[%s%s] $f\n", TESTING ? "# " : "", $pkg, $TOPIC ? "/$TOPIC" : "", @_; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | sub dumper { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
dumper: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 27 | 0 | Data::Dumper->new([@_])->Indent(0)->Sortkeys(1)->Terse(1)->Useqq(1)->Dump; | |||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||
| 30 | 95 | ▶ | sub has_ro { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
has_ro: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 31 | 95 | my ($name, $builder) = @_; | |||||||||||||||||||||||||||||||||||||
| 32 | 95 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||
| 34 | 95 | ▶ | $builder ||= sub { confess qq("$name" is required in constructor') }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Condition66%2/3
$builder ||= sub {
confess(qq["$name" is required in constructor']);
}
MC/DC0%0/2
$builder ||= sub {
confess(qq["$name" is required in constructor']);
}
$builder
sub {
confess(qq["$name" is required in constructor']);
}
Truth table66%2/3
A ||= B
A= $builderB= sub {
confess(qq["$name" is required in constructor']);
}
| |||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||
| 36 | Mojo::Util::monkey_patch( | ||||||||||||||||||||||||||||||||||||||
| 37 | 295 | ▶ | $caller => $name => sub { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.3
Subroutine
ua: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||
| 38 | 295 | ▶ | confess qq("$name" is read-only") if @_ > 1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 39 | 295 | ▶ | $_[0]->{$name} //= $_[0]->$builder(); | ||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$_[0]{$name} //= $_[0]->$builder
$_[0]{$name} //= $_[0]->$builder
MC/DC0%0/2
$_[0]{$name} //= $_[0]->$builder
$_[0]{$name}
$_[0]->$builder
MC/DC0%0/2
$_[0]{$name} //= $_[0]->$builder
$_[0]{$name}
$_[0]->$builder
Truth table66%2/3
A //= B
A= $_[0]{$name}B= $_[0]->$builder
Truth table66%2/3
A //= B
A= $_[0]{$name}B= $_[0]->$builder
| |||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||
| 41 | 95 | ); | |||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||
| 44 | 36 | ▶ | sub load_module { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
load_module: called CC=5 SCAR=18.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 45 | 36 | my $module = shift; | |||||||||||||||||||||||||||||||||||||
| 46 | 36 | ▶ | confess qq(Invalid module name "$module") if ($module || '') !~ /^\w(?:[\w:']*\w)?$/; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$module || ''
MC/DC0%0/1
$module || ''
$module
Truth table50%1/2
A
A= $module
| |||||||||||||||||||||||||||||||||||||||
| 47 | 36 | ▶ | return $module if $LOADED{$module} ||= eval "require $module; 1"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$Mojolicious::Plugin::AssetPack::Util::LOADED{$module} ||= eval "require $module; 1"
MC/DC0%0/2
$Mojolicious::Plugin::AssetPack::Util::LOADED{$module} ||= eval "require $module; 1"
$Mojolicious::Plugin::AssetPack::Util::LOADED{$module}
eval "require $module; 1"
Truth table66%2/3
A ||= B
A= $Mojolicious::Plugin::AssetPack::Util::LOADED{$module}B= eval "require $module; 1"
| |||||||||||||||||||||||||||||||||||||||
| 48 | 0 | confess qq(Could not load "$module": $@); | |||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||
| 51 | package Mojolicious::Plugin::AssetPack::Util::_chdir; | ||||||||||||||||||||||||||||||||||||||
| 52 | 38 | ▶ | use Cwd (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 53 | 38 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 54 | 38 | ▶ | sub TIESCALAR { bless [Cwd::getcwd], $_[0] } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
TIESCALAR: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 55 | 3 | ▶ | sub FETCH { $_[0]->[0] } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
FETCH: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||
| 57 | 3 | ▶ | sub STORE { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
STORE: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||
| 58 | 3 | ▶ | defined $_[1] or return; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 59 | 2 | my $dir = File::Spec->rel2abs($_[1]); | |||||||||||||||||||||||||||||||||||||
| 60 | 2 | ▶ | chdir $dir or die "chdir $dir: $!"; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 61 | 2 | Mojolicious::Plugin::AssetPack::Util::diag("chdir $dir") if Mojolicious::Plugin::AssetPack::Util::DEBUG >= 3; | |||||||||||||||||||||||||||||||||||||
| 62 | 2 | $_[0]->[0] = $dir; | |||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||
| 65 | 38 | 1; | |||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||
| 67 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||
| 69 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||
| 71 | Mojolicious::Plugin::AssetPack::Util - Utility functions for pipes | ||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||
| 73 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||
| 75 | L<Mojolicious::Plugin::AssetPack::Util> holds utility functions. | ||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||
| 77 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||
| 79 | use Mojolicious::Plugin::AssetPack::Util; | ||||||||||||||||||||||||||||||||||||||
| 80 | use Mojolicious::Plugin::AssetPack::Util qw(checksum diag DEBUG) | ||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||
| 82 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||
| 84 | =head2 checksum | ||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||
| 86 | $str = checksum $bytes; | ||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||
| 88 | Used to calculate checksum of C<$bytes>. | ||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||
| 90 | =head2 diag | ||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||
| 92 | diag "some messsage"; | ||||||||||||||||||||||||||||||||||||||
| 93 | diag "some %s", "messsage"; | ||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||
| 95 | Same as C<warn()>, but with a prefix. It will also use C<sprintf()> if | ||||||||||||||||||||||||||||||||||||||
| 96 | more than one argument is given. | ||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||
| 98 | =head2 dumper | ||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||
| 100 | $str = dumper $any; | ||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||
| 102 | Dump a Perl data structure into a single line with L<Data::Dumper>. | ||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||
| 104 | =head2 has_ro | ||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||
| 106 | Same as L<Mojo::Base/has>, but creates a read-only attribute. | ||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||
| 108 | =head2 load_module | ||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||
| 110 | $module = load_module $module; | ||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||
| 112 | Used to load a C<$module>. Will confess on failure. | ||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||
| 114 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||
| 116 | L<Mojolicious::Plugin::AssetPack>. | ||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||
| 118 | =cut | ||||||||||||||||||||||||||||||||||||||