line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::Debug::LazyLoadModules; |
2
|
3
|
|
|
3
|
|
110195
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
177
|
|
3
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
107
|
|
4
|
3
|
|
|
3
|
|
879
|
use Plack::Util::Accessor qw/filter class elements/; |
|
3
|
|
|
|
|
302
|
|
|
3
|
|
|
|
|
33
|
|
5
|
3
|
|
|
3
|
|
1030
|
use parent qw/Plack::Middleware::Debug::Base/; |
|
3
|
|
|
|
|
379
|
|
|
3
|
|
|
|
|
20
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub prepare_app { |
9
|
5
|
|
|
5
|
1
|
37075
|
my $self = shift; |
10
|
5
|
100
|
|
|
|
23
|
$self->elements([qw/lazy preload/]) |
11
|
|
|
|
|
|
|
unless $self->elements; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub run { |
15
|
5
|
|
|
5
|
1
|
99106
|
my($self, $env, $panel) = @_; |
16
|
|
|
|
|
|
|
|
17
|
5
|
|
|
|
|
17
|
my %modules = (); |
18
|
5
|
|
|
|
|
738
|
$modules{$_}++ for keys %INC; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
return sub { |
21
|
5
|
|
|
5
|
|
3493
|
my %preload_modules; |
22
|
|
|
|
|
|
|
my %lazy_load_modules; |
23
|
5
|
|
|
|
|
24
|
my $preload = $self->_included('preload'); |
24
|
5
|
|
|
|
|
17
|
my $lazy = $self->_included('lazy'); |
25
|
5
|
|
|
|
|
22
|
my $filter = $self->filter; |
26
|
5
|
|
|
|
|
155
|
for my $module (keys %INC) { |
27
|
609
|
50
|
66
|
|
|
1243
|
next if $filter && _is_regexp($filter) && $module !~ /$filter/; |
|
|
|
66
|
|
|
|
|
28
|
487
|
100
|
100
|
|
|
1920
|
if ($preload && $modules{$module}) { |
|
|
100
|
100
|
|
|
|
|
29
|
362
|
|
|
|
|
796
|
$preload_modules{$self->_classnize($module)} = $INC{$module}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
elsif ($lazy && !$modules{$module}) { |
32
|
3
|
|
|
|
|
11
|
$lazy_load_modules{$self->_classnize($module)} = $INC{$module}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
5
|
|
|
|
|
82
|
$panel->title('Lazy Load Modules'); |
37
|
5
|
|
|
|
|
84
|
$panel->nav_subtitle( |
38
|
|
|
|
|
|
|
sprintf( |
39
|
|
|
|
|
|
|
"%d/%d lazy loaded", |
40
|
|
|
|
|
|
|
scalar(keys %lazy_load_modules), scalar(keys %modules), |
41
|
|
|
|
|
|
|
) |
42
|
|
|
|
|
|
|
); |
43
|
5
|
|
|
|
|
57
|
$panel->content( |
44
|
|
|
|
|
|
|
$self->render_hash( |
45
|
|
|
|
|
|
|
+{ |
46
|
|
|
|
|
|
|
lazy => \%lazy_load_modules, |
47
|
|
|
|
|
|
|
preload => \%preload_modules, |
48
|
|
|
|
|
|
|
}, |
49
|
|
|
|
|
|
|
$self->elements, |
50
|
|
|
|
|
|
|
) |
51
|
|
|
|
|
|
|
); |
52
|
5
|
|
|
|
|
84
|
}; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _classnize { |
56
|
365
|
|
|
365
|
|
438
|
my ($self, $module_path) = @_; |
57
|
|
|
|
|
|
|
|
58
|
365
|
100
|
66
|
|
|
1025
|
if ($self->class && $module_path =~ /\.pm$/) { |
59
|
123
|
|
|
|
|
1555
|
$module_path =~ s!/!::!g; |
60
|
123
|
|
|
|
|
364
|
$module_path =~ s!\.pm$!!g; |
61
|
|
|
|
|
|
|
} |
62
|
365
|
|
|
|
|
2335
|
return $module_path; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _is_regexp { |
66
|
122
|
50
|
|
122
|
|
850
|
(ref($_[0]) eq 'Regexp') ? 1 : 0; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _included { |
70
|
10
|
|
|
10
|
|
173
|
my ($self, $element) = @_; |
71
|
|
|
|
|
|
|
|
72
|
10
|
|
|
|
|
13
|
for my $e (@{$self->elements}) { |
|
10
|
|
|
|
|
33
|
|
73
|
13
|
100
|
|
|
|
100
|
return 1 if $element eq $e; |
74
|
|
|
|
|
|
|
} |
75
|
2
|
|
|
|
|
7
|
return; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |