line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Treex::Core::Common; |
2
|
|
|
|
|
|
|
$Treex::Core::Common::VERSION = '2.20210102'; |
3
|
27
|
|
|
27
|
|
104176
|
use strict; |
|
27
|
|
|
|
|
73
|
|
|
27
|
|
|
|
|
2385
|
|
4
|
27
|
|
|
27
|
|
164
|
use warnings; |
|
27
|
|
|
|
|
1531
|
|
|
27
|
|
|
|
|
2071
|
|
5
|
27
|
|
|
27
|
|
660
|
use 5.010; |
|
27
|
|
|
|
|
96
|
|
6
|
|
|
|
|
|
|
|
7
|
27
|
|
|
27
|
|
17155
|
use utf8; |
|
27
|
|
|
|
|
445
|
|
|
27
|
|
|
|
|
161
|
|
8
|
27
|
|
|
27
|
|
1490
|
use Moose::Exporter; |
|
27
|
|
|
|
|
145681
|
|
|
27
|
|
|
|
|
230
|
|
9
|
27
|
|
|
27
|
|
1907
|
use Moose::Util::TypeConstraints; |
|
27
|
|
|
|
|
165345
|
|
|
27
|
|
|
|
|
259
|
|
10
|
27
|
|
|
27
|
|
67310
|
use MooseX::SemiAffordanceAccessor::Role::Attribute 0.09; |
|
27
|
|
|
|
|
487016
|
|
|
27
|
|
|
|
|
3763
|
|
11
|
27
|
|
|
27
|
|
14442
|
use Treex::Core::Log; |
|
27
|
|
|
|
|
88
|
|
|
27
|
|
|
|
|
2341
|
|
12
|
27
|
|
|
27
|
|
14446
|
use Treex::Core::Config; |
|
27
|
|
|
|
|
99
|
|
|
27
|
|
|
|
|
1067
|
|
13
|
27
|
|
|
27
|
|
13178
|
use Treex::Core::Resource; |
|
27
|
|
|
|
|
382
|
|
|
27
|
|
|
|
|
1472
|
|
14
|
27
|
|
|
27
|
|
13173
|
use Treex::Core::Types; |
|
27
|
|
|
|
|
116
|
|
|
27
|
|
|
|
|
1427
|
|
15
|
27
|
|
|
27
|
|
14769
|
use Treex::Core::Files; |
|
27
|
|
|
|
|
130
|
|
|
27
|
|
|
|
|
1478
|
|
16
|
27
|
|
|
27
|
|
265
|
use List::MoreUtils; |
|
27
|
|
|
|
|
68
|
|
|
27
|
|
|
|
|
480
|
|
17
|
27
|
|
|
27
|
|
16846
|
use List::Util; |
|
27
|
|
|
|
|
73
|
|
|
27
|
|
|
|
|
1821
|
|
18
|
27
|
|
|
27
|
|
187
|
use Scalar::Util; |
|
27
|
|
|
|
|
70
|
|
|
27
|
|
|
|
|
1071
|
|
19
|
27
|
|
|
27
|
|
177
|
use Readonly; |
|
27
|
|
|
|
|
66
|
|
|
27
|
|
|
|
|
1428
|
|
20
|
27
|
|
|
27
|
|
21801
|
use Data::Dumper; |
|
27
|
|
|
|
|
176986
|
|
|
27
|
|
|
|
|
12304
|
|
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
|
3585
|
|
|
3585
|
1
|
5727
|
my $args_ref = shift; |
29
|
3585
|
|
|
|
|
5073
|
my @args = @{$args_ref}; |
|
3585
|
|
|
|
|
7447
|
|
30
|
3585
|
|
|
|
|
5592
|
my $i = 0; |
31
|
3585
|
|
|
|
|
9404
|
while ( ref $_[0] eq 'HASH' ) { |
32
|
4314
|
|
|
|
|
6061
|
my $spec = shift; |
33
|
4314
|
100
|
|
|
|
9124
|
if ( defined $spec->{default} ) { |
34
|
135
|
|
66
|
|
|
487
|
$args[$i] //= $spec->{default}; |
35
|
|
|
|
|
|
|
} |
36
|
4314
|
|
|
|
|
9169
|
$i++; |
37
|
|
|
|
|
|
|
} |
38
|
3585
|
|
|
|
|
9298
|
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
|
269
|
|
|
269
|
|
24556
|
feature->import(':5.10'); |
81
|
269
|
|
|
|
|
1941
|
utf8::import(); |
82
|
269
|
|
|
|
|
2531
|
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.20210102 |
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. |