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/Core/Node/Ordered.pm »
1 package Treex::Core::Loader;
2 77 $Treex::Core::Loader::VERSION = '2.20151210';
3 77 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 77 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 77 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 77 ▶use File::Spec::Functions qw(catdir catfile splitdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 77 ▶use File::Basename 'fileparse';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 77 ▶use Treex::Core::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 77 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 sub load_module {
16 0 ▶ my ($module) = @_;
Subroutine load_module: not called CC=6 SCAR=37.4
Pod undocumented
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 sub search_module {
33 0 ▶ my ($ns) = @_;
Subroutine search_module: not called CC=6 SCAR=37.4
Pod undocumented
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 77 1;
52 __END__
53  
54 =head1 NAME
55  
56 Treex::Core::Loader - Loader
57  
58 =head1 VERSION
59  
60 version 2.20151210
61  
62 =head1 SYNOPSIS
63  
64 use Treex::Core::Loader;
65  
66 =head1 DESCRIPTION
67  
68 Stub documentation for Treex::Core::Loader,
69  
70 Blah blah blah.
71  
72 =head2 EXPORT
73  
74 None by default.
75  
76 =head1 SEE ALSO
77  
78 Mention other useful documentation such as the documentation of
79 related modules or operating system documentation (such as man pages
80 in UNIX), or any relevant external documentation such as RFCs or
81 standards.
82  
83 If you have a mailing list set up for your module, mention it here.
84  
85 If you have a web site set up for your module, mention it here.
86  
87 =head1 AUTHOR
88  
89 Michal Sedlak, E<lt>sedlakmichal@gmail.comE<gt>
90  
91 =head1 COPYRIGHT AND LICENSE
92  
93 Copyright (C) 2014 by Michal Sedlak
94  
95 This program is free software; you can redistribute it and/or modify
96 it under the same terms as Perl itself, either Perl version 5.8.2 or,
97 at your option, any later version of Perl 5 you may have available.
98  
99 =head1 BUGS
100  
101 None reported... yet.
102  
103 =cut
« Treex/Core/TredView/Vallex.pm ↑ Summary Treex/Core/Node/Ordered.pm »