line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::AssetPack::Util; |
2
|
34
|
|
|
34
|
|
4850420
|
use Mojo::Base 'Exporter'; |
|
34
|
|
|
|
|
392
|
|
|
34
|
|
|
|
|
204
|
|
3
|
|
|
|
|
|
|
|
4
|
34
|
|
|
34
|
|
4903
|
use Carp 'confess'; |
|
34
|
|
|
|
|
72
|
|
|
34
|
|
|
|
|
1446
|
|
5
|
34
|
|
|
34
|
|
190
|
use Mojo::Util; |
|
34
|
|
|
|
|
71
|
|
|
34
|
|
|
|
|
1292
|
|
6
|
|
|
|
|
|
|
|
7
|
34
|
|
50
|
34
|
|
172
|
use constant DEBUG => $ENV{MOJO_ASSETPACK_DEBUG} || 0; |
|
34
|
|
|
|
|
64
|
|
|
34
|
|
|
|
|
2771
|
|
8
|
34
|
|
50
|
34
|
|
190
|
use constant TESTING => $ENV{HARNESS_IS_VERBOSE} || 0; |
|
34
|
|
|
|
|
64
|
|
|
34
|
|
|
|
|
18809
|
|
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
|
11340
|
sub checksum { substr Mojo::Util::sha1_sum($_[0]), 0, $SUM_LEN } |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub diag { |
19
|
2
|
100
|
|
2
|
1
|
921
|
my $f = @_ > 1 ? shift : '%s'; |
20
|
2
|
|
|
|
|
5
|
my ($i, $pkg) = (0); |
21
|
2
|
50
|
|
|
|
8
|
while ($pkg = caller $i++) { $pkg =~ s!.*::(AssetPack::)Pipe::!$1! and last } |
|
2
|
|
|
|
|
9
|
|
22
|
2
|
50
|
|
|
|
6
|
$pkg = 'AssetPack' unless $pkg; |
23
|
2
|
50
|
|
|
|
24
|
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
|
315
|
my ($name, $builder) = @_; |
32
|
71
|
|
|
|
|
179
|
my $caller = caller; |
33
|
|
|
|
|
|
|
|
34
|
71
|
|
100
|
1
|
|
440
|
$builder ||= sub { confess qq("$name" is required in constructor') }; |
|
1
|
|
|
|
|
99
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Mojo::Util::monkey_patch( |
37
|
|
|
|
|
|
|
$caller => $name => sub { |
38
|
369
|
100
|
|
369
|
|
3468
|
confess qq("$name" is read-only") if @_ > 1; |
|
|
|
|
364
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
|
5
|
|
|
|
39
|
367
|
|
66
|
|
|
2180
|
$_[0]->{$name} //= $_[0]->$builder(); |
40
|
|
|
|
|
|
|
} |
41
|
71
|
|
|
|
|
409
|
); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub load_module { |
45
|
18
|
|
|
23
|
1
|
55
|
my $module = shift; |
46
|
18
|
50
|
50
|
|
|
180
|
confess qq(Invalid module name "$module") if ($module || '') !~ /^\w(?:[\w:']*\w)?$/; |
47
|
18
|
50
|
66
|
|
|
1489
|
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
|
|
244
|
use Cwd (); |
|
34
|
|
|
|
|
65
|
|
|
34
|
|
|
|
|
515
|
|
53
|
34
|
|
|
34
|
|
151
|
use File::Spec; |
|
34
|
|
|
|
|
65
|
|
|
34
|
|
|
|
|
5912
|
|
54
|
34
|
|
|
34
|
|
549
|
sub TIESCALAR { bless [Cwd::getcwd], $_[0] } |
55
|
3
|
|
|
3
|
|
554
|
sub FETCH { $_[0]->[0] } |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub STORE { |
58
|
3
|
100
|
|
3
|
|
428
|
defined $_[1] or return; |
59
|
2
|
|
|
|
|
21
|
my $dir = File::Spec->rel2abs($_[1]); |
60
|
2
|
50
|
|
|
|
24
|
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 |