lib/Treex/Core/Common.pm

filter: Statementstmt 97.1% 69 / 71 Branchbran 83.3% 5 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 19 / 19 Podpod 100% 1 / 1 totaltotal 95.1% 97 / 102 CC 4 SCAR 4.4
CC
4
Cov
95%
pos_validated_list
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.5
« lib/Treex/Core/WildAttr.pm ↑ Summary lib/Treex/Block/Read/Text.pm »
1 package Treex::Core::Common;
2 {
3 83 $Treex::Core::Common::VERSION = '0.08633_1';
4 }
5 83 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 83 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 83 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 83 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 83 ▶use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 83 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 83 ▶use MooseX::SemiAffordanceAccessor::Role::Attribute 0.09;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 83 ▶use Treex::Core::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 83 ▶use Treex::Core::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 83 ▶use Treex::Core::Resource;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 83 ▶use Treex::Core::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 83 ▶use Treex::Core::Files;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 83 ▶use List::MoreUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 83 ▶use List::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 83 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 83 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 83 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 # sub reference for validating of params
25 # Sets default values for unspecified params
26 83 my $validation_sub;
27  
28 # Quick alternative for MooseX::Params::Validate::pos_validated_list
29 sub pos_validated_list {
30 2601 ▶ my $args_ref = shift;
Subroutine pos_validated_list: called CC=4 SCAR=13.9
Pod documented
31 2601 my $i = 0;
32 2601 ▶ while ( ref $_[0] eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq "HASH") 3114 2599 5713
33 3114 my $spec = shift;
34 3114 ▶ if ( defined $spec->{default} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $spec->{"default"}) 119 2995 3114
35 119 ▶ $args_ref->[$i] ||= $spec->{default};
Condition66%2/3
$args_ref->[$i] ||= $spec->{"default"}
l!l&&r!l&&!r
29090
MC/DC50%1/2
$args_ref->[$i] ||= $spec->{"default"}
$args_ref->[$i] $spec->{"default"}
Truth table66%2/3
A ||= B
A= $args_ref->[$i]B= $spec->{"default"}
ABresult
1X1
011
000
36 }
37 3112 $i++;
38 }
39 2599 return @{$args_ref};
40 }
41  
42 # Choose which variant to use according to $Treex::Core::Config::params_validate
43 83 ▶if ( $Treex::Core::Config::params_validate == 2 ) { ## no critic (ProhibitPackageVars)
Branch: 1 branch
BranchTrueFalseTotal
if ($Treex::Core::Config::params_validate == 2) { } 0 83 83
44 0 require MooseX::Params::Validate;
45 0 $validation_sub = \&MooseX::Params::Validate::pos_validated_list;
46 }
47 else {
48 83 $validation_sub = \&pos_validated_list;
49 }
50  
51 83 my ( $import, $unimport, $init_meta ) =
52 Moose::Exporter->build_import_methods(
53 install => [qw(unimport init_meta)],
54 class_metaroles => { attribute => ['MooseX::SemiAffordanceAccessor::Role::Attribute'] },
55 as_is => [
56 \&Treex::Core::Log::log_fatal,
57 \&Treex::Core::Log::log_warn,
58 \&Treex::Core::Log::log_debug,
59 \&Treex::Core::Log::log_set_error_level,
60 \&Treex::Core::Log::log_info,
61 \&Treex::Core::Types::get_lang_name,
62 \&Treex::Core::Types::is_lang_code,
63 \&Treex::Core::Resource::require_file_from_share,
64 \&List::MoreUtils::first_index,
65 \&List::MoreUtils::all,
66 \&List::MoreUtils::any,
67 \&List::Util::first,
68 \&Readonly::Readonly,
69 \&Scalar::Util::weaken,
70 \&Data::Dumper::Dumper,
71 \&Moose::Util::TypeConstraints::enum,
72 $validation_sub,
73 ]
74 );
75  
76 sub import {
77 779 ▶ feature->import(':5.10');
Subroutine import: called CC=1 SCAR=0.0
78 779 utf8::import();
79 779 goto &$import;
80 }
81  
82 83 1;
83  
84 __END__
85  
86 =encoding utf-8
87  
88 =head1 NAME
89  
90 Treex::Core::Common - shorten the "C<use>" part of your Perl codes
91  
92 =head1 VERSION
93  
94 version 0.08633_1
95  
96 =head1 SYNOPSIS
97  
98 Write just
99  
100 use Treex::Core::Common;
101  
102 Instead of
103  
104 use utf8;
105 use strict;
106 use warnings;
107 use Moose::Util::TypeConstraints qw(enum);
108 use MooseX::SemiAffordanceAccessor;
109 use MooseX::Params::Validate qw(pos_validated_list);
110 use Treex::Core::Log;
111 use Treex::Core::Config;
112 use Treex::Core::Resource;
113 use Treex::Core::Types;
114 use Treex::Core::Files;
115 use List::MoreUtils qw(all any first_index);
116 use List::Util qw(first);
117 use Scalar::Util qw(weaken);
118 use Readonly qw(Readonly);
119 use Data::Dumper qw(Dumper);
120  
121  
122 =head1 SUBROUTINES
123  
124 =over
125  
126 =item $language_name = get_lang_name($iso639_code)
127  
128 =item $bool = is_lang_code($iso639_code)
129  
130 =item pos_validated_list
131  
132 This subroutine is automatically exported. Depending on the value of
133 L<$Treex::Core::Config::params_validate|Treex::Core::Config/params_validate>
134 it is either the (slow) one from
135 L<MooseX::Params::Validate> or a fast one, that does
136 no type checking.
137  
138 =back
139  
140 =head1 AUTHOR
141  
142 Martin Popel <popel@ufal.mff.cuni.cz>
143  
144 =head1 COPYRIGHT AND LICENSE
145  
146 Copyright © 2011 by Institute of Formal and Applied Linguistics, Charles University in Prague
147  
148 This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
« lib/Treex/Core/WildAttr.pm ↑ Summary lib/Treex/Block/Read/Text.pm »