blib/lib/Dancer/ModuleLoader.pm

filter: Statementstmt 100% 44 / 44 Branchbran 50.0% 11 / 22 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 84.3% 70 / 83 SCAR 27.1
CC
14
Cov
82%
load_with_params
9.1
require
4.0
use_lib
3.1
CRAP 15.1
« lib/Dancer/Plugin/Ajax.pm ↑ Summary blib/lib/Dancer/Handler/PSGI.pm »
1 package Dancer::ModuleLoader;
2 248 our $AUTHORITY = 'cpan:SUKRIA';
3 #ABSTRACT: dynamic module loading helpers for Dancer core components
4 248 $Dancer::ModuleLoader::VERSION = '1.3520';
5 # Abstraction layer for dynamic module loading
6  
7 248 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 248 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 248 ▶use Module::Runtime qw/ use_module /;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub load {
12 955 ▶ my ($class, $module, $version) = @_;
Subroutine load: called CC=2 SCAR=6.9
Pod documented
13  
14 955 my ($res, $error) = $class->require($module, $version);
15 955 ▶ return wantarray ? ($res, $error) : $res;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 503 452 955
16 }
17  
18 sub require {
19 995 ▶ my ($class, $module, $version) = @_;
Subroutine require: called CC=4 SCAR=13.9
Pod documented
20 995 ▶ eval { defined $version ? use_module( $module, $version )
Branch: 3 branches
BranchTrueFalseTotal
eval { do { defined $version ? &use_module($module, $version) : &use_module($module) } } or return wantarray ? (0, $@) : 0 17 978 995
defined $version ? : 49 946 995
wantarray ? : 17 0 17
21 : use_module( $module ) }
22 or return wantarray ? (0, $@) : 0;
23 978 return 1; #success
24 }
25  
26 sub load_with_params {
27 39 ▶ my ($class, $module, @args) = @_;
Subroutine load_with_params: called CC=7 SCAR=22.0
Pod documented
28 39 my ($res, $error) = $class->require($module);
29 39 ▶ $res or return wantarray ? (0, $error) : 0;
Branch: 2 branches
BranchTrueFalseTotal
$res or return wantarray ? (0, $error) : 0 0 39 39
wantarray ? : 0 0 0
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
BranchTrueFalseTotal
if ($module->can("import")) 39 0 39
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
l!l
039
MC/DC0%0/1
$Exporter::ExportLevel || 0
$Exporter::ExportLevel
Truth table50%1/2
A
A= $Exporter::ExportLevel
Aresult
11
00
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
BranchTrueFalseTotal
$error and return wantarray ? (0, $error) : 0 0 39 39
wantarray ? : 0 0 0
41 }
42 39 return 1;
43 }
44  
45 sub use_lib {
46 194 ▶ my ($class, @args) = @_;
Subroutine use_lib: called CC=3 SCAR=11.3
Pod documented
47 248 ▶ 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
BranchTrueFalseTotal
$error and return wantarray ? (0, $error) : 0 0 194 194
wantarray ? : 0 0 0
52 194 return 1;
53 }
54  
55 sub class_from_setting {
56 479 ▶ my ($self, $namespace, $setting) = @_;
Subroutine class_from_setting: called CC=2 SCAR=6.9
Pod documented
57  
58 479 my $class = '';
59 479 for my $token (split /_/, $setting) {
60 480 $class .= ucfirst($token);
61 }
62 479 return "${namespace}::${class}";
63 }
64  
65 248 1;
66  
67 __END__
« lib/Dancer/Plugin/Ajax.pm ↑ Summary blib/lib/Dancer/Handler/PSGI.pm »