| 1 | package Dancer::ModuleLoader; | ||||||||||||||||||
| 2 | 257 | our $AUTHORITY = 'cpan:SUKRIA'; | |||||||||||||||||
| 3 | #ABSTRACT: dynamic module loading helpers for Dancer core components | ||||||||||||||||||
| 4 | 257 | $Dancer::ModuleLoader::VERSION = '1.3522'; | |||||||||||||||||
| 5 | # Abstraction layer for dynamic module loading | ||||||||||||||||||
| 6 | |||||||||||||||||||
| 7 | 257 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | 257 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 9 | 257 | ▶ | use Module::Runtime qw/ use_module /; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 10 | |||||||||||||||||||
| 11 | 964 | ▶ | sub load { | ||||||||||||||||
|
Subroutine
load: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 12 | 964 | my ($class, $module, $version) = @_; | |||||||||||||||||
| 13 | |||||||||||||||||||
| 14 | 964 | my ($res, $error) = $class->require($module, $version); | |||||||||||||||||
| 15 | 964 | ▶ | return wantarray ? ($res, $error) : $res; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 16 | } | ||||||||||||||||||
| 17 | |||||||||||||||||||
| 18 | 1004 | ▶ | sub require { | ||||||||||||||||
|
Subroutine
require: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||
| 19 | 1004 | my ($class, $module, $version) = @_; | |||||||||||||||||
| 20 | 1004 | ▶ | eval { defined $version ? use_module( $module, $version ) | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 21 | : use_module( $module ) } | ||||||||||||||||||
| 22 | or return wantarray ? (0, $@) : 0; | ||||||||||||||||||
| 23 | 987 | return 1; #success | |||||||||||||||||
| 24 | } | ||||||||||||||||||
| 25 | |||||||||||||||||||
| 26 | 39 | ▶ | sub load_with_params { | ||||||||||||||||
|
Subroutine
load_with_params: called CC=7 SCAR=22.0
Pod
documented
| |||||||||||||||||||
| 27 | 39 | my ($class, $module, @args) = @_; | |||||||||||||||||
| 28 | 39 | my ($res, $error) = $class->require($module); | |||||||||||||||||
| 29 | 39 | ▶ | $res or return wantarray ? (0, $error) : 0; | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 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 | ▶ | if ($module->can('import')) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 34 | |||||||||||||||||||
| 35 | # bump Exporter Level to import symbols in the caller | ||||||||||||||||||
| 36 | 39 | ▶ | local $Exporter::ExportLevel = ($Exporter::ExportLevel || 0) + 1; | ||||||||||||||||
|
Condition50%1/2
$Exporter::ExportLevel || 0
MC/DC0%0/1
$Exporter::ExportLevel || 0
$Exporter::ExportLevel
Truth table50%1/2
A
A= $Exporter::ExportLevel
| |||||||||||||||||||
| 37 | 39 | local $@; | |||||||||||||||||
| 38 | 39 | eval { $module->import(@args) }; | |||||||||||||||||
| 39 | 39 | my $error = $@; | |||||||||||||||||
| 40 | 39 | ▶ | $error and return wantarray ? (0, $error) : 0; | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 41 | } | ||||||||||||||||||
| 42 | 39 | return 1; | |||||||||||||||||
| 43 | } | ||||||||||||||||||
| 44 | |||||||||||||||||||
| 45 | 194 | ▶ | sub use_lib { | ||||||||||||||||
|
Subroutine
use_lib: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||
| 46 | 194 | my ($class, @args) = @_; | |||||||||||||||||
| 47 | 257 | ▶ | use lib; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 48 | 194 | local $@; | |||||||||||||||||
| 49 | 194 | lib->import(@args); | |||||||||||||||||
| 50 | 194 | my $error = $@; | |||||||||||||||||
| 51 | 194 | ▶ | $error and return wantarray ? (0, $error) : 0; | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 52 | 194 | return 1; | |||||||||||||||||
| 53 | } | ||||||||||||||||||
| 54 | |||||||||||||||||||
| 55 | 488 | ▶ | sub class_from_setting { | ||||||||||||||||
|
Subroutine
class_from_setting: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 56 | 488 | my ($self, $namespace, $setting) = @_; | |||||||||||||||||
| 57 | |||||||||||||||||||
| 58 | 488 | my $class = ''; | |||||||||||||||||
| 59 | 488 | for my $token (split /_/, $setting) { | |||||||||||||||||
| 60 | 489 | $class .= ucfirst($token); | |||||||||||||||||
| 61 | } | ||||||||||||||||||
| 62 | 488 | return "${namespace}::${class}"; | |||||||||||||||||
| 63 | } | ||||||||||||||||||
| 64 | |||||||||||||||||||
| 65 | 257 | 1; | |||||||||||||||||
| 66 | |||||||||||||||||||
| 67 | __END__ | ||||||||||||||||||