line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::AssetPack::Util; |
2
|
34
|
|
|
34
|
|
5121720
|
use Mojo::Base 'Exporter'; |
|
34
|
|
|
|
|
406
|
|
|
34
|
|
|
|
|
193
|
|
3
|
|
|
|
|
|
|
|
4
|
34
|
|
|
34
|
|
5228
|
use Carp 'confess'; |
|
34
|
|
|
|
|
79
|
|
|
34
|
|
|
|
|
1495
|
|
5
|
34
|
|
|
34
|
|
189
|
use Mojo::Util; |
|
34
|
|
|
|
|
68
|
|
|
34
|
|
|
|
|
1429
|
|
6
|
|
|
|
|
|
|
|
7
|
34
|
|
50
|
34
|
|
197
|
use constant DEBUG => $ENV{MOJO_ASSETPACK_DEBUG} || 0; |
|
34
|
|
|
|
|
67
|
|
|
34
|
|
|
|
|
2798
|
|
8
|
34
|
|
50
|
34
|
|
195
|
use constant TESTING => $ENV{HARNESS_IS_VERBOSE} || 0; |
|
34
|
|
|
|
|
69
|
|
|
34
|
|
|
|
|
19169
|
|
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
|
9460
|
sub checksum { substr Mojo::Util::sha1_sum($_[0]), 0, $SUM_LEN } |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub diag { |
19
|
2
|
100
|
|
2
|
1
|
919
|
my $f = @_ > 1 ? shift : '%s'; |
20
|
2
|
|
|
|
|
5
|
my ($i, $pkg) = (0); |
21
|
2
|
50
|
|
|
|
9
|
while ($pkg = caller $i++) { $pkg =~ s!.*::(AssetPack::)Pipe::!$1! and last } |
|
2
|
|
|
|
|
8
|
|
22
|
2
|
50
|
|
|
|
5
|
$pkg = 'AssetPack' unless $pkg; |
23
|
2
|
50
|
|
|
|
25
|
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
|
294
|
my ($name, $builder) = @_; |
32
|
71
|
|
|
|
|
175
|
my $caller = caller; |
33
|
|
|
|
|
|
|
|
34
|
71
|
|
100
|
1
|
|
344
|
$builder ||= sub { confess qq("$name" is required in constructor') }; |
|
1
|
|
|
|
|
98
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Mojo::Util::monkey_patch( |
37
|
|
|
|
|
|
|
$caller => $name => sub { |
38
|
369
|
100
|
|
369
|
|
3361
|
confess qq("$name" is read-only") if @_ > 1; |
|
|
|
|
364
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
|
5
|
|
|
|
39
|
367
|
|
66
|
|
|
1936
|
$_[0]->{$name} //= $_[0]->$builder(); |
40
|
|
|
|
|
|
|
} |
41
|
71
|
|
|
|
|
343
|
); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub load_module { |
45
|
18
|
|
|
23
|
1
|
40
|
my $module = shift; |
46
|
18
|
50
|
50
|
|
|
158
|
confess qq(Invalid module name "$module") if ($module || '') !~ /^\w(?:[\w:']*\w)?$/; |
47
|
18
|
50
|
66
|
|
|
1287
|
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
|
|
249
|
use Cwd (); |
|
34
|
|
|
|
|
73
|
|
|
34
|
|
|
|
|
512
|
|
53
|
34
|
|
|
34
|
|
153
|
use File::Spec; |
|
34
|
|
|
|
|
69
|
|
|
34
|
|
|
|
|
6257
|
|
54
|
34
|
|
|
34
|
|
485
|
sub TIESCALAR { bless [Cwd::getcwd], $_[0] } |
55
|
3
|
|
|
3
|
|
550
|
sub FETCH { $_[0]->[0] } |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub STORE { |
58
|
3
|
100
|
|
3
|
|
451
|
defined $_[1] or return; |
59
|
2
|
|
|
|
|
21
|
my $dir = File::Spec->rel2abs($_[1]); |
60
|
2
|
50
|
|
|
|
21
|
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
|
|
|
|
|
8
|
$_[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 |