| 1 | package Treex::Core::Common; | ||||||||||||||||||||
| 2 | 71 | $Treex::Core::Common::VERSION = '2.20151210'; | |||||||||||||||||||
| 3 | 71 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 71 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 71 | ▶ | use 5.010; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 71 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 71 | ▶ | use Moose::Exporter; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 71 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 71 | ▶ | use MooseX::SemiAffordanceAccessor::Role::Attribute 0.09; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 71 | ▶ | use Treex::Core::Log; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 71 | ▶ | use Treex::Core::Config; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 71 | ▶ | use Treex::Core::Resource; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 71 | ▶ | use Treex::Core::Types; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 71 | ▶ | use Treex::Core::Files; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 71 | ▶ | use List::MoreUtils; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | 71 | ▶ | use List::Util; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 18 | 71 | ▶ | use Scalar::Util; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 71 | ▶ | use Readonly; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | 71 | ▶ | use Data::Dumper; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | # sub reference for validating of params | ||||||||||||||||||||
| 23 | # Sets default values for unspecified params | ||||||||||||||||||||
| 24 | 71 | my $validation_sub; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | # Quick alternative for MooseX::Params::Validate::pos_validated_list | ||||||||||||||||||||
| 27 | sub pos_validated_list { | ||||||||||||||||||||
| 28 | 3495 | ▶ | my $args_ref = shift; | ||||||||||||||||||
|
Subroutine
pos_validated_list: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||
| 29 | 3495 | my @args = @{$args_ref}; | |||||||||||||||||||
| 30 | 3495 | my $i = 0; | |||||||||||||||||||
| 31 | 3495 | ▶ | while ( ref $_[0] eq 'HASH' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | 4222 | my $spec = shift; | |||||||||||||||||||
| 33 | 4222 | ▶ | if ( defined $spec->{default} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | 135 | ▶ | $args[$i] //= $spec->{default}; | ||||||||||||||||||
|
Condition66%2/3
$args[$i] //= $spec->{"default"}
MC/DC50%1/2
$args[$i] //= $spec->{"default"}
$args[$i]
$spec->{"default"}
Truth table66%2/3
A //= B
A= $args[$i]B= $spec->{"default"}
| |||||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | 4222 | $i++; | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | 3495 | return @args; | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | # Choose which variant to use according to $Treex::Core::Config::params_validate | ||||||||||||||||||||
| 42 | 71 | ▶ | if ( $Treex::Core::Config::params_validate == 2 ) { ## no critic (ProhibitPackageVars) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | 0 | require MooseX::Params::Validate; | |||||||||||||||||||
| 44 | 0 | $validation_sub = \&MooseX::Params::Validate::pos_validated_list; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | else { | ||||||||||||||||||||
| 47 | 71 | $validation_sub = \&pos_validated_list; | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 71 | 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 | 410 | ▶ | feature->import(':5.10'); | ||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 81 | 410 | utf8::import(); | |||||||||||||||||||
| 82 | 410 | goto &$import; | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 71 | 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.20151210 | ||||||||||||||||||||
| 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. | ||||||||||||||||||||