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.3521'; |
5
|
|
|
|
|
|
|
# Abstraction layer for dynamic module loading |
6
|
|
|
|
|
|
|
|
7
|
199
|
|
|
199
|
|
1582459
|
use strict; |
|
199
|
|
|
|
|
665
|
|
|
199
|
|
|
|
|
5554
|
|
8
|
199
|
|
|
199
|
|
1042
|
use warnings; |
|
199
|
|
|
|
|
452
|
|
|
199
|
|
|
|
|
5525
|
|
9
|
199
|
|
|
199
|
|
103658
|
use Module::Runtime qw/ use_module /; |
|
199
|
|
|
|
|
361917
|
|
|
199
|
|
|
|
|
1249
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub load { |
12
|
911
|
|
|
911
|
1
|
232350
|
my ($class, $module, $version) = @_; |
13
|
|
|
|
|
|
|
|
14
|
911
|
|
|
|
|
3226
|
my ($res, $error) = $class->require($module, $version); |
15
|
911
|
100
|
|
|
|
14286
|
return wantarray ? ($res, $error) : $res; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub require { |
19
|
951
|
|
|
951
|
1
|
3760
|
my ($class, $module, $version) = @_; |
20
|
951
|
50
|
|
|
|
1761
|
eval { defined $version ? use_module( $module, $version ) |
|
951
|
100
|
|
|
|
4402
|
|
|
|
100
|
|
|
|
|
|
21
|
|
|
|
|
|
|
: use_module( $module ) } |
22
|
|
|
|
|
|
|
or return wantarray ? (0, $@) : 0; |
23
|
931
|
|
|
|
|
1731215
|
return 1; #success |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub load_with_params { |
27
|
39
|
|
|
39
|
1
|
874
|
my ($class, $module, @args) = @_; |
28
|
39
|
|
|
|
|
135
|
my ($res, $error) = $class->require($module); |
29
|
39
|
0
|
|
|
|
171
|
$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
|
|
|
|
394
|
if ($module->can('import')) { |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# bump Exporter Level to import symbols in the caller |
36
|
39
|
|
50
|
|
|
238
|
local $Exporter::ExportLevel = ($Exporter::ExportLevel || 0) + 1; |
37
|
39
|
|
|
|
|
81
|
local $@; |
38
|
39
|
|
|
|
|
93
|
eval { $module->import(@args) }; |
|
39
|
|
|
|
|
154
|
|
39
|
39
|
|
|
|
|
218668
|
my $error = $@; |
40
|
39
|
0
|
|
|
|
178
|
$error and return wantarray ? (0, $error) : 0; |
|
|
50
|
|
|
|
|
|
41
|
|
|
|
|
|
|
} |
42
|
39
|
|
|
|
|
418
|
return 1; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub use_lib { |
46
|
194
|
|
|
194
|
1
|
811
|
my ($class, @args) = @_; |
47
|
199
|
|
|
199
|
|
137528
|
use lib; |
|
199
|
|
|
|
|
134170
|
|
|
199
|
|
|
|
|
1265
|
|
48
|
194
|
|
|
|
|
555
|
local $@; |
49
|
194
|
|
|
|
|
1680
|
lib->import(@args); |
50
|
194
|
|
|
|
|
25762
|
my $error = $@; |
51
|
194
|
0
|
|
|
|
909
|
$error and return wantarray ? (0, $error) : 0; |
|
|
50
|
|
|
|
|
|
52
|
194
|
|
|
|
|
907
|
return 1; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub class_from_setting { |
56
|
438
|
|
|
438
|
1
|
1663
|
my ($self, $namespace, $setting) = @_; |
57
|
|
|
|
|
|
|
|
58
|
438
|
|
|
|
|
1348
|
my $class = ''; |
59
|
438
|
|
|
|
|
2023
|
for my $token (split /_/, $setting) { |
60
|
439
|
|
|
|
|
1378
|
$class .= ucfirst($token); |
61
|
|
|
|
|
|
|
} |
62
|
438
|
|
|
|
|
2139
|
return "${namespace}::${class}"; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |