Treex/Core/Loader.pm

filter: Statementstmt 52.5% 21 / 40 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 66.6% 6 / 9 Podpod 0.0% 0 / 3 totaltotal 36.4% 27 / 74 CC 11 SCAR 32.9
CC
11
Cov
36%
load_module
42.0
search_module
42.0
class_to_path
2.0
CRAP 26.9
« Treex/Core/TredView/Vallex.pm ↑ Summary Treex/Block/Read/Sentences.pm »
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
BranchTrueFalseTotal
unless $module and $module =~ /^\w(?:[\w:']*\w)?$/ 0 0 0
Condition0%0/3
$module and $module =~ /^\w(?:[\w:']*\w)?$/
!ll&&!rl&&r
000
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)?$/
ABresult
0X0
100
111
20  
21 # Load
22 0 ▶ return 1 if $module->can('new') || eval "require $module; 1";
Branch: 1 branch
BranchTrueFalseTotal
if $module->can("new") or eval "require $module; 1" 0 0 0
Condition0%0/3
$module->can("new") or eval "require $module; 1"
l!l&&r!l&&!r
000
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"
ABresult
1X1
011
000
23  
24 # Exists
25 0 ▶ return 0 if $@ =~ /^Can't locate \Q@{[class_to_path $module]}\E in \@INC/;
Branch: 1 branch
BranchTrueFalseTotal
if $@ =~ /^Can't locate \Q@{[class_to_path($module)];}\E in \@INC/ 0 0 0
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
BranchTrueFalseTotal
unless -d (my $path = catdir($directory, split(/::|'/, $ns, 0))) 0 0 0
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
BranchTrueFalseTotal
if -d catfile(splitdir($path), $file) 0 0 0
43 0 my $class = "${ns}::" . fileparse $file, qr/\.pm/;
44 0 ▶ push @modules, $class unless $found{$class}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $found{$class}++ 0 0 0
45 }
46 }
47  
48 0 return \@modules;
49 }
50  
51 76 1;
52 __END__
« Treex/Core/TredView/Vallex.pm ↑ Summary Treex/Block/Read/Sentences.pm »