line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Treex::Core::Common; |
2
|
|
|
|
|
|
|
$Treex::Core::Common::VERSION = '2.20150928'; |
3
|
27
|
|
|
27
|
|
18893
|
use strict; |
|
27
|
|
|
|
|
61
|
|
|
27
|
|
|
|
|
742
|
|
4
|
27
|
|
|
27
|
|
143
|
use warnings; |
|
27
|
|
|
|
|
56
|
|
|
27
|
|
|
|
|
690
|
|
5
|
27
|
|
|
27
|
|
866
|
use 5.010; |
|
27
|
|
|
|
|
85
|
|
6
|
|
|
|
|
|
|
|
7
|
27
|
|
|
27
|
|
22917
|
use utf8; |
|
27
|
|
|
|
|
284
|
|
|
27
|
|
|
|
|
147
|
|
8
|
27
|
|
|
27
|
|
1467
|
use Moose::Exporter; |
|
27
|
|
|
|
|
149287
|
|
|
27
|
|
|
|
|
222
|
|
9
|
27
|
|
|
27
|
|
1861
|
use Moose::Util::TypeConstraints; |
|
27
|
|
|
|
|
136151
|
|
|
27
|
|
|
|
|
280
|
|
10
|
27
|
|
|
27
|
|
66265
|
use MooseX::SemiAffordanceAccessor::Role::Attribute 0.09; |
|
27
|
|
|
|
|
422889
|
|
|
27
|
|
|
|
|
850
|
|
11
|
27
|
|
|
27
|
|
16878
|
use Treex::Core::Log; |
|
27
|
|
|
|
|
101
|
|
|
27
|
|
|
|
|
2887
|
|
12
|
27
|
|
|
27
|
|
16396
|
use Treex::Core::Config; |
|
27
|
|
|
|
|
107
|
|
|
27
|
|
|
|
|
878
|
|
13
|
27
|
|
|
27
|
|
14580
|
use Treex::Core::Resource; |
|
27
|
|
|
|
|
98
|
|
|
27
|
|
|
|
|
1475
|
|
14
|
27
|
|
|
27
|
|
15876
|
use Treex::Core::Types; |
|
27
|
|
|
|
|
142
|
|
|
27
|
|
|
|
|
1120
|
|
15
|
27
|
|
|
27
|
|
17873
|
use Treex::Core::Files; |
|
27
|
|
|
|
|
122
|
|
|
27
|
|
|
|
|
1328
|
|
16
|
27
|
|
|
27
|
|
276
|
use List::MoreUtils; |
|
27
|
|
|
|
|
58
|
|
|
27
|
|
|
|
|
489
|
|
17
|
27
|
|
|
27
|
|
9313
|
use List::Util; |
|
27
|
|
|
|
|
60
|
|
|
27
|
|
|
|
|
1793
|
|
18
|
27
|
|
|
27
|
|
190
|
use Scalar::Util; |
|
27
|
|
|
|
|
60
|
|
|
27
|
|
|
|
|
1011
|
|
19
|
27
|
|
|
27
|
|
145
|
use Readonly; |
|
27
|
|
|
|
|
61
|
|
|
27
|
|
|
|
|
1394
|
|
20
|
27
|
|
|
27
|
|
31523
|
use Data::Dumper; |
|
27
|
|
|
|
|
161830
|
|
|
27
|
|
|
|
|
11854
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# sub reference for validating of params |
23
|
|
|
|
|
|
|
# Sets default values for unspecified params |
24
|
|
|
|
|
|
|
my $validation_sub; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Quick alternative for MooseX::Params::Validate::pos_validated_list |
27
|
|
|
|
|
|
|
sub pos_validated_list { |
28
|
0
|
|
|
0
|
1
|
0
|
my $args_ref = shift; |
29
|
0
|
|
|
|
|
0
|
my @args = @{$args_ref}; |
|
0
|
|
|
|
|
0
|
|
30
|
0
|
|
|
|
|
0
|
my $i = 0; |
31
|
0
|
|
|
|
|
0
|
while ( ref $_[0] eq 'HASH' ) { |
32
|
0
|
|
|
|
|
0
|
my $spec = shift; |
33
|
0
|
0
|
|
|
|
0
|
if ( defined $spec->{default} ) { |
34
|
0
|
|
0
|
|
|
0
|
$args[$i] //= $spec->{default}; |
35
|
|
|
|
|
|
|
} |
36
|
0
|
|
|
|
|
0
|
$i++; |
37
|
|
|
|
|
|
|
} |
38
|
0
|
|
|
|
|
0
|
return @args; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Choose which variant to use according to $Treex::Core::Config::params_validate |
42
|
|
|
|
|
|
|
if ( $Treex::Core::Config::params_validate == 2 ) { ## no critic (ProhibitPackageVars) |
43
|
|
|
|
|
|
|
require MooseX::Params::Validate; |
44
|
|
|
|
|
|
|
$validation_sub = \&MooseX::Params::Validate::pos_validated_list; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else { |
47
|
|
|
|
|
|
|
$validation_sub = \&pos_validated_list; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my ( $import, $unimport, $init_meta ) = |
51
|
|
|
|
|
|
|
Moose::Exporter->build_import_methods( |
52
|
|
|
|
|
|
|
install => [qw(unimport init_meta)], |
53
|
|
|
|
|
|
|
class_metaroles => { attribute => ['MooseX::SemiAffordanceAccessor::Role::Attribute'] }, |
54
|
|
|
|
|
|
|
as_is => [ |
55
|
|
|
|
|
|
|
\&Treex::Core::Log::log_fatal, |
56
|
|
|
|
|
|
|
\&Treex::Core::Log::log_warn, |
57
|
|
|
|
|
|
|
\&Treex::Core::Log::log_debug, |
58
|
|
|
|
|
|
|
\&Treex::Core::Log::log_set_error_level, |
59
|
|
|
|
|
|
|
\&Treex::Core::Log::log_info, |
60
|
|
|
|
|
|
|
\&Treex::Core::Types::get_lang_name, |
61
|
|
|
|
|
|
|
\&Treex::Core::Types::is_lang_code, |
62
|
|
|
|
|
|
|
\&Treex::Core::Resource::require_file_from_share, |
63
|
|
|
|
|
|
|
\&List::MoreUtils::first_index, |
64
|
|
|
|
|
|
|
\&List::MoreUtils::all, |
65
|
|
|
|
|
|
|
\&List::MoreUtils::any, |
66
|
|
|
|
|
|
|
\&List::MoreUtils::none, |
67
|
|
|
|
|
|
|
\&List::MoreUtils::uniq, |
68
|
|
|
|
|
|
|
\&List::Util::first, |
69
|
|
|
|
|
|
|
\&List::Util::min, |
70
|
|
|
|
|
|
|
\&List::Util::max, |
71
|
|
|
|
|
|
|
\&Readonly::Readonly, |
72
|
|
|
|
|
|
|
\&Scalar::Util::weaken, |
73
|
|
|
|
|
|
|
\&Data::Dumper::Dumper, |
74
|
|
|
|
|
|
|
\&Moose::Util::TypeConstraints::enum, |
75
|
|
|
|
|
|
|
$validation_sub, |
76
|
|
|
|
|
|
|
] |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub import { |
80
|
111
|
|
|
111
|
|
11358
|
feature->import(':5.10'); |
81
|
111
|
|
|
|
|
603
|
utf8::import(); |
82
|
111
|
|
|
|
|
878
|
goto &$import; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
__END__ |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=encoding utf-8 |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 NAME |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Treex::Core::Common - shorten the "C<use>" part of your Perl codes |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 VERSION |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
version 2.20150928 |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 SYNOPSIS |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Write just |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
use Treex::Core::Common; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Instead of |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
use utf8; |
108
|
|
|
|
|
|
|
use strict; |
109
|
|
|
|
|
|
|
use warnings; |
110
|
|
|
|
|
|
|
use Moose::Util::TypeConstraints qw(enum); |
111
|
|
|
|
|
|
|
use MooseX::SemiAffordanceAccessor; |
112
|
|
|
|
|
|
|
use MooseX::Params::Validate qw(pos_validated_list); |
113
|
|
|
|
|
|
|
use Treex::Core::Log; |
114
|
|
|
|
|
|
|
use Treex::Core::Config; |
115
|
|
|
|
|
|
|
use Treex::Core::Resource; |
116
|
|
|
|
|
|
|
use Treex::Core::Types; |
117
|
|
|
|
|
|
|
use Treex::Core::Files; |
118
|
|
|
|
|
|
|
use List::MoreUtils qw(all any none uniq first_index); |
119
|
|
|
|
|
|
|
use List::Util qw(first min max); |
120
|
|
|
|
|
|
|
use Scalar::Util qw(weaken); |
121
|
|
|
|
|
|
|
use Readonly qw(Readonly); |
122
|
|
|
|
|
|
|
use Data::Dumper qw(Dumper); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SUBROUTINES |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=over |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item $language_name = get_lang_name($iso639_code) |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item $bool = is_lang_code($iso639_code) |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item pos_validated_list |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
This subroutine is automatically exported. Depending on the value of |
136
|
|
|
|
|
|
|
L<$Treex::Core::Config::params_validate|Treex::Core::Config/params_validate> |
137
|
|
|
|
|
|
|
it is either the (slow) one from |
138
|
|
|
|
|
|
|
L<MooseX::Params::Validate> or a fast one, that does |
139
|
|
|
|
|
|
|
no type checking. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=back |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 AUTHOR |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Martin Popel <popel@ufal.mff.cuni.cz> |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
Copyright © 2011 by Institute of Formal and Applied Linguistics, Charles University in Prague |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |