| 1 | # | ||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||
| 3 | # | ||||||||||||
| 4 | |||||||||||||
| 5 | package Rex::Require; | ||||||||||||
| 6 | |||||||||||||
| 7 | 108 | ▶ | use v5.14.4; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 108 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 108 | our $VERSION = '1.16.1'; # VERSION | |||||||||||
| 11 | |||||||||||||
| 12 | 108 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 108 | require Rex::Logger; | |||||||||||
| 14 | |||||||||||||
| 15 | # some code borrowed from: UNIVERSAL::require (neilb) | ||||||||||||
| 16 | |||||||||||||
| 17 | 108 | ▶ | BEGIN { require UNIVERSAL; } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | |||||||||||||
| 19 | 108 | my $module_name_rx = qr/[A-Z_a-z][0-9A-Z_a-z]*(?:::[0-9A-Z_a-z]+)*/; | |||||||||||
| 20 | |||||||||||||
| 21 | 428 | ▶ | sub UNIVERSAL::require { | ||||||||||
|
Subroutine
require: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||
| 22 | 428 | my ( $module, %option ) = @_; | |||||||||||
| 23 | |||||||||||||
| 24 | 428 | ▶ | $option{level} ||= 0; | ||||||||||
|
Condition100%2/2
$option{"level"} ||= 0
MC/DC100%1/1
$option{"level"} ||= 0
$option{"level"}
Truth table100%2/2
A
A= $option{"level"}
| |||||||||||||
| 25 | |||||||||||||
| 26 | 428 | my ( $caller_package, $caller_file, $caller_line ) = caller( $option{level} ); | |||||||||||
| 27 | |||||||||||||
| 28 | 428 | my $file = $module . ".pm"; | |||||||||||
| 29 | 428 | $file =~ s/::/\//g; | |||||||||||
| 30 | |||||||||||||
| 31 | # check if module is already loaded. | ||||||||||||
| 32 | 428 | ▶ | return eval { 1 } if $INC{$file}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | |||||||||||||
| 34 | 274 | my $ret = eval "CORE::require(\$file)"; | |||||||||||
| 35 | |||||||||||||
| 36 | 274 | ▶ | if ( !$ret ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 37 | 106 | confess $@; | |||||||||||
| 38 | } | ||||||||||||
| 39 | |||||||||||||
| 40 | 168 | return $ret; | |||||||||||
| 41 | } | ||||||||||||
| 42 | |||||||||||||
| 43 | 78 | ▶ | sub UNIVERSAL::use { | ||||||||||
|
Subroutine
use: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||
| 44 | 78 | my ( $module, @imports ) = @_; | |||||||||||
| 45 | |||||||||||||
| 46 | 78 | $module->require( level => 1 ); | |||||||||||
| 47 | |||||||||||||
| 48 | 78 | my ( $caller_package, $caller_file, $caller_line ) = caller(0); | |||||||||||
| 49 | |||||||||||||
| 50 | 78 | eval "package $caller_package;\n\$module->import(\@imports);\n1;"; | |||||||||||
| 51 | |||||||||||||
| 52 | 78 | ▶ | if ($@) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 53 | 0 | confess $@; | |||||||||||
| 54 | } | ||||||||||||
| 55 | |||||||||||||
| 56 | 78 | return 1; | |||||||||||
| 57 | } | ||||||||||||
| 58 | |||||||||||||
| 59 | 117 | ▶ | sub UNIVERSAL::is_loadable { | ||||||||||
|
Subroutine
is_loadable: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||
| 60 | 117 | my ($module) = @_; | |||||||||||
| 61 | 117 | eval { | |||||||||||
| 62 | 117 | $module->require; | |||||||||||
| 63 | 117 | 1; | |||||||||||
| 64 | }; | ||||||||||||
| 65 | |||||||||||||
| 66 | 0 | ▶ | if ($@) { return 0; } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 67 | 117 | return 1; | |||||||||||
| 68 | } | ||||||||||||
| 69 | |||||||||||||
| 70 | 108 | 1; | |||||||||||