line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer::ModuleLoader; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:SUKRIA'; |
3
|
|
|
|
|
|
|
#ABSTRACT: dynamic module loading helpers for Dancer core components |
4
|
|
|
|
|
|
|
$Dancer::ModuleLoader::VERSION = '1.3520'; |
5
|
|
|
|
|
|
|
# Abstraction layer for dynamic module loading |
6
|
|
|
|
|
|
|
|
7
|
199
|
|
|
199
|
|
1631289
|
use strict; |
|
199
|
|
|
|
|
677
|
|
|
199
|
|
|
|
|
5624
|
|
8
|
199
|
|
|
199
|
|
1054
|
use warnings; |
|
199
|
|
|
|
|
413
|
|
|
199
|
|
|
|
|
5663
|
|
9
|
199
|
|
|
199
|
|
104870
|
use Module::Runtime qw/ use_module /; |
|
199
|
|
|
|
|
373991
|
|
|
199
|
|
|
|
|
1253
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub load { |
12
|
911
|
|
|
911
|
1
|
230024
|
my ($class, $module, $version) = @_; |
13
|
|
|
|
|
|
|
|
14
|
911
|
|
|
|
|
3156
|
my ($res, $error) = $class->require($module, $version); |
15
|
911
|
100
|
|
|
|
14330
|
return wantarray ? ($res, $error) : $res; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub require { |
19
|
951
|
|
|
951
|
1
|
3839
|
my ($class, $module, $version) = @_; |
20
|
951
|
50
|
|
|
|
1803
|
eval { defined $version ? use_module( $module, $version ) |
|
951
|
100
|
|
|
|
4407
|
|
|
|
100
|
|
|
|
|
|
21
|
|
|
|
|
|
|
: use_module( $module ) } |
22
|
|
|
|
|
|
|
or return wantarray ? (0, $@) : 0; |
23
|
931
|
|
|
|
|
1761358
|
return 1; #success |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub load_with_params { |
27
|
39
|
|
|
39
|
1
|
1000
|
my ($class, $module, @args) = @_; |
28
|
39
|
|
|
|
|
137
|
my ($res, $error) = $class->require($module); |
29
|
39
|
0
|
|
|
|
161
|
$res or return wantarray ? (0, $error) : 0; |
|
|
50
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# From perlfunc : If no "import" method can be found then the call is |
32
|
|
|
|
|
|
|
# skipped, even if there is an AUTOLOAD method. |
33
|
39
|
50
|
|
|
|
385
|
if ($module->can('import')) { |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# bump Exporter Level to import symbols in the caller |
36
|
39
|
|
50
|
|
|
242
|
local $Exporter::ExportLevel = ($Exporter::ExportLevel || 0) + 1; |
37
|
39
|
|
|
|
|
83
|
local $@; |
38
|
39
|
|
|
|
|
93
|
eval { $module->import(@args) }; |
|
39
|
|
|
|
|
161
|
|
39
|
39
|
|
|
|
|
232182
|
my $error = $@; |
40
|
39
|
0
|
|
|
|
181
|
$error and return wantarray ? (0, $error) : 0; |
|
|
50
|
|
|
|
|
|
41
|
|
|
|
|
|
|
} |
42
|
39
|
|
|
|
|
435
|
return 1; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub use_lib { |
46
|
194
|
|
|
194
|
1
|
1215
|
my ($class, @args) = @_; |
47
|
199
|
|
|
199
|
|
141841
|
use lib; |
|
199
|
|
|
|
|
135442
|
|
|
199
|
|
|
|
|
1276
|
|
48
|
194
|
|
|
|
|
512
|
local $@; |
49
|
194
|
|
|
|
|
1744
|
lib->import(@args); |
50
|
194
|
|
|
|
|
25956
|
my $error = $@; |
51
|
194
|
0
|
|
|
|
879
|
$error and return wantarray ? (0, $error) : 0; |
|
|
50
|
|
|
|
|
|
52
|
194
|
|
|
|
|
907
|
return 1; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub class_from_setting { |
56
|
438
|
|
|
438
|
1
|
1604
|
my ($self, $namespace, $setting) = @_; |
57
|
|
|
|
|
|
|
|
58
|
438
|
|
|
|
|
1307
|
my $class = ''; |
59
|
438
|
|
|
|
|
2057
|
for my $token (split /_/, $setting) { |
60
|
439
|
|
|
|
|
1486
|
$class .= ucfirst($token); |
61
|
|
|
|
|
|
|
} |
62
|
438
|
|
|
|
|
2121
|
return "${namespace}::${class}"; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |