| 1 | package Treex::Core::Loader; | ||||||||||||||||||||||||||||
| 2 | 76 | $Treex::Core::Loader::VERSION = '2.20210102'; | |||||||||||||||||||||||||||
| 3 | 76 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 76 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 76 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 76 | ▶ | use File::Spec::Functions qw(catdir catfile splitdir); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 76 | ▶ | use File::Basename 'fileparse'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 76 | ▶ | use Treex::Core::Log; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 76 | our @EXPORT_OK = qw(class_to_path load_module search_module); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub class_to_path { return join '.', join('/', split /::|'/, shift),'pm'; } | ||||||||||||||||||||||||||
|
Subroutine
class_to_path: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | sub load_module { | ||||||||||||||||||||||||||
|
Subroutine
load_module: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 0 | my ($module) = @_; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # Check module name | ||||||||||||||||||||||||||||
| 19 | 0 | ▶ | return 0 if !$module || $module !~ /^\w(?:[\w:']*\w)?$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$module and $module =~ /^\w(?:[\w:']*\w)?$/
MC/DC0%0/2
$module and $module =~ /^\w(?:[\w:']*\w)?$/
$module
$module =~ /^\w(?:[\w:']*\w)?$/
Truth table0%0/3
A and B
A= $moduleB= $module =~ /^\w(?:[\w:']*\w)?$/
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # Load | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | return 1 if $module->can('new') || eval "require $module; 1"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$module->can("new") or eval "require $module; 1"
MC/DC0%0/2
$module->can("new") or eval "require $module; 1"
$module->can("new")
eval "require $module; 1"
Truth table0%0/3
A or B
A= $module->can("new")B= eval "require $module; 1"
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # Exists | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | return 0 if $@ =~ /^Can't locate \Q@{[class_to_path $module]}\E in \@INC/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # Real error | ||||||||||||||||||||||||||||
| 28 | 0 | log_fatal $@; | |||||||||||||||||||||||||||
| 29 | 0 | return; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub search_module { | ||||||||||||||||||||||||||
|
Subroutine
search_module: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | 0 | my ($ns) = @_; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | my (@modules, %found); | |||||||||||||||||||||||||||
| 36 | 0 | for my $directory (@INC) { | |||||||||||||||||||||||||||
| 37 | 0 | ▶ | next unless -d (my $path = catdir $directory, split(/::|'/, $ns)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # List "*.pm" files in directory | ||||||||||||||||||||||||||||
| 40 | 0 | opendir(my $dir, $path); | |||||||||||||||||||||||||||
| 41 | 0 | for my $file (grep { /\.pm$/ } readdir $dir) { | |||||||||||||||||||||||||||
| 42 | 0 | ▶ | next if -d catfile splitdir($path), $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | my $class = "${ns}::" . fileparse $file, qr/\.pm/; | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | push @modules, $class unless $found{$class}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | return \@modules; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 76 | 1; | |||||||||||||||||||||||||||
| 52 | __END__ | ||||||||||||||||||||||||||||