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