line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Treex::Core::Loader; |
2
|
|
|
|
|
|
|
$Treex::Core::Loader::VERSION = '2.20210102'; |
3
|
29
|
|
|
29
|
|
217
|
use strict; |
|
29
|
|
|
|
|
73
|
|
|
29
|
|
|
|
|
926
|
|
4
|
29
|
|
|
29
|
|
169
|
use warnings; |
|
29
|
|
|
|
|
63
|
|
|
29
|
|
|
|
|
864
|
|
5
|
|
|
|
|
|
|
|
6
|
29
|
|
|
29
|
|
151
|
use Exporter 'import'; |
|
29
|
|
|
|
|
72
|
|
|
29
|
|
|
|
|
1072
|
|
7
|
29
|
|
|
29
|
|
14158
|
use File::Spec::Functions qw(catdir catfile splitdir); |
|
29
|
|
|
|
|
25149
|
|
|
29
|
|
|
|
|
2249
|
|
8
|
29
|
|
|
29
|
|
259
|
use File::Basename 'fileparse'; |
|
29
|
|
|
|
|
77
|
|
|
29
|
|
|
|
|
2383
|
|
9
|
29
|
|
|
29
|
|
208
|
use Treex::Core::Log; |
|
29
|
|
|
|
|
72
|
|
|
29
|
|
|
|
|
16348
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(class_to_path load_module search_module); |
12
|
|
|
|
|
|
|
|
13
|
0
|
|
|
0
|
0
|
|
sub class_to_path { return join '.', join('/', split /::|'/, shift),'pm'; } |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub load_module { |
16
|
0
|
|
|
0
|
0
|
|
my ($module) = @_; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Check module name |
19
|
0
|
0
|
0
|
|
|
|
return 0 if !$module || $module !~ /^\w(?:[\w:']*\w)?$/; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Load |
22
|
0
|
0
|
0
|
|
|
|
return 1 if $module->can('new') || eval "require $module; 1"; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Exists |
25
|
0
|
0
|
|
|
|
|
return 0 if $@ =~ /^Can't locate \Q@{[class_to_path $module]}\E in \@INC/; |
|
0
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Real error |
28
|
0
|
|
|
|
|
|
log_fatal $@; |
29
|
0
|
|
|
|
|
|
return; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub search_module { |
33
|
0
|
|
|
0
|
0
|
|
my ($ns) = @_; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my (@modules, %found); |
36
|
0
|
|
|
|
|
|
for my $directory (@INC) { |
37
|
0
|
0
|
|
|
|
|
next unless -d (my $path = catdir $directory, split(/::|'/, $ns)); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# List "*.pm" files in directory |
40
|
0
|
|
|
|
|
|
opendir(my $dir, $path); |
41
|
0
|
|
|
|
|
|
for my $file (grep { /\.pm$/ } readdir $dir) { |
|
0
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
next if -d catfile splitdir($path), $file; |
43
|
0
|
|
|
|
|
|
my $class = "${ns}::" . fileparse $file, qr/\.pm/; |
44
|
0
|
0
|
|
|
|
|
push @modules, $class unless $found{$class}++; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
return \@modules; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
__END__ |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 NAME |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Treex::Core::Loader - Loader |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 VERSION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
version 2.20210102 |
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 |