line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Treex::Core::Loader; |
2
|
|
|
|
|
|
|
$Treex::Core::Loader::VERSION = '2.20150928'; |
3
|
29
|
|
|
29
|
|
152
|
use strict; |
|
29
|
|
|
|
|
50
|
|
|
29
|
|
|
|
|
794
|
|
4
|
29
|
|
|
29
|
|
148
|
use warnings; |
|
29
|
|
|
|
|
59
|
|
|
29
|
|
|
|
|
1029
|
|
5
|
|
|
|
|
|
|
|
6
|
29
|
|
|
29
|
|
157
|
use Exporter 'import'; |
|
29
|
|
|
|
|
68
|
|
|
29
|
|
|
|
|
1259
|
|
7
|
29
|
|
|
29
|
|
22026
|
use File::Spec::Functions qw(catdir catfile splitdir); |
|
29
|
|
|
|
|
22766
|
|
|
29
|
|
|
|
|
2229
|
|
8
|
29
|
|
|
29
|
|
175
|
use File::Basename 'fileparse'; |
|
29
|
|
|
|
|
56
|
|
|
29
|
|
|
|
|
1833
|
|
9
|
29
|
|
|
29
|
|
145
|
use Treex::Core::Log; |
|
29
|
|
|
|
|
58
|
|
|
29
|
|
|
|
|
15295
|
|
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.20150928 |
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 |