Getopt/OptionTypeMap.pm

filter: Statementstmt 90.2% 46 / 51 Branchbran 63.1% 24 / 38 Conditioncond 55.5% 5 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 76.5% 88 / 115 CC 25 SCAR 23.7
CC
25
Cov
77%
has_option_type
14.7
get_option_type
13.5
add_option_type_to_map
5.5
CRAP 10.7
↑ Summary Getopt/Basic.pm »
1 package MooseX::Getopt::OptionTypeMap;
2 # ABSTRACT: Storage for the option to type mappings
3  
4 27 our $VERSION = '0.78';
5  
6 27 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 27 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 27 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 27 ▶use Moose::Util::TypeConstraints 'find_type_constraint';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 27 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 27 my %option_type_map = (
13 'Bool' => '!',
14 'Str' => '=s',
15 'Int' => '=i',
16 'Num' => '=f',
17 'ArrayRef' => '=s@',
18 'HashRef' => '=s%',
19 );
20  
21 476 ▶sub has_option_type {
Subroutine has_option_type: called CC=11 SCAR=26.9
Pod documented
22 476 my (undef, $type_or_name) = @_;
23  
24 476 ▶ if (blessed($type_or_name)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($type_or_name) and $type_or_name->isa("Moose::Meta::TypeConstraint::Union")) 1 475 476
Condition66%2/3
builtin::blessed($type_or_name) and $type_or_name->isa("Moose::Meta::TypeConstraint::Union")
!ll&&!rl&&r
04751
MC/DC50%1/2
builtin::blessed($type_or_name) and $type_or_name->isa("Moose::Meta::TypeConstraint::Union")
builtin::blessed($type_or_name) $type_or_name->isa("Moose::Meta::TypeConstraint::Union")
Truth table66%2/3
A and B
A= builtin::blessed($type_or_name)B= $type_or_name->isa("Moose::Meta::TypeConstraint::Union")
ABresult
0X0
100
111
25 && $type_or_name->isa('Moose::Meta::TypeConstraint::Union')) {
26 1 foreach my $union_type (@{$type_or_name->type_constraints}) {
27 1 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
if __PACKAGE__->has_option_type($union_type) 1 0 1
28 if __PACKAGE__->has_option_type($union_type);
29 }
30 0 return 0;
31 }
32  
33 475 ▶ return 1 if exists $option_type_map{blessed($type_or_name) ? $type_or_name->name : $type_or_name};
Branch: 2 branches
BranchTrueFalseTotal
if exists $option_type_map{builtin::blessed($type_or_name) ? $type_or_name->name : $type_or_name} 473 2 475
builtin::blessed($type_or_name) ? : 475 0 475
34  
35 2 ▶ my $current = blessed($type_or_name) ? $type_or_name : find_type_constraint($type_or_name);
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($type_or_name) ? : 2 0 2
36  
37 2 ▶ (defined $current)
Branch: 1 branch
BranchTrueFalseTotal
defined $current or confess("Could not find the type constraint for '${type_or_name}'") 2 0 2
38 || confess "Could not find the type constraint for '$type_or_name'";
39  
40 2 ▶ while (my $parent = $current->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent = $current->parent) 2 0 2
41 2 ▶ return 1 if exists $option_type_map{$parent->name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $option_type_map{$parent->name} 2 0 2
42 0 $current = $parent;
43 }
44  
45 0 return 0;
46 }
47  
48 476 ▶sub get_option_type {
Subroutine get_option_type: called CC=11 SCAR=26.0
Pod documented
49 476 my (undef, $type_or_name) = @_;
50  
51 476 ▶ if (blessed($type_or_name)
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($type_or_name) and $type_or_name->isa("Moose::Meta::TypeConstraint::Union")) 1 475 476
Condition66%2/3
builtin::blessed($type_or_name) and $type_or_name->isa("Moose::Meta::TypeConstraint::Union")
!ll&&!rl&&r
04751
MC/DC50%1/2
builtin::blessed($type_or_name) and $type_or_name->isa("Moose::Meta::TypeConstraint::Union")
builtin::blessed($type_or_name) $type_or_name->isa("Moose::Meta::TypeConstraint::Union")
Truth table66%2/3
A and B
A= builtin::blessed($type_or_name)B= $type_or_name->isa("Moose::Meta::TypeConstraint::Union")
ABresult
0X0
100
111
52 && $type_or_name->isa('Moose::Meta::TypeConstraint::Union')) {
53 1 foreach my $union_type (@{$type_or_name->type_constraints}) {
54 1 my $option_type = __PACKAGE__->get_option_type($union_type);
55 1 ▶ return $option_type
Branch: 1 branch
BranchTrueFalseTotal
if defined $option_type 1 0 1
56 if defined $option_type;
57 }
58 0 return;
59 }
60  
61 475 ▶ my $name = blessed($type_or_name) ? $type_or_name->name : $type_or_name;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($type_or_name) ? : 475 0 475
62  
63 475 ▶ return $option_type_map{$name} if exists $option_type_map{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $option_type_map{$name} 473 2 475
64  
65 2 ▶ my $current = ref $type_or_name ? $type_or_name : find_type_constraint($type_or_name);
Branch: 1 branch
BranchTrueFalseTotal
ref $type_or_name ? : 2 0 2
66  
67 2 ▶ (defined $current)
Branch: 1 branch
BranchTrueFalseTotal
defined $current or confess("Could not find the type constraint for '${type_or_name}'") 2 0 2
68 || confess "Could not find the type constraint for '$type_or_name'";
69  
70 2 ▶ while ( $current = $current->parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current = $current->parent) 2 0 2
71 return $option_type_map{$current->name}
72 2 ▶ if exists $option_type_map{$current->name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $option_type_map{$current->name} 2 0 2
73 }
74  
75 0 return;
76 }
77  
78 29 ▶sub add_option_type_to_map {
Subroutine add_option_type_to_map: called CC=5 SCAR=17.0
Pod documented
79 29 my (undef, $type_name, $option_string) = @_;
80 29 ▶ (defined $type_name && defined $option_string)
Branch: 1 branch
BranchTrueFalseTotal
defined $type_name and defined $option_string or confess("You must supply both a type name and an option string") 29 0 29
Condition33%1/3
defined $type_name and defined $option_string
!ll&&!rl&&r
0029
MC/DC0%0/2
defined $type_name and defined $option_string
defined $type_name defined $option_string
Truth table33%1/3
A and B
A= defined $type_nameB= defined $option_string
ABresult
0X0
100
111
81 || confess "You must supply both a type name and an option string";
82  
83 29 ▶ if ( blessed($type_name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($type_name)) { } 24 5 29
84 24 $type_name = $type_name->name;
85 } else {
86 5 ▶ (find_type_constraint($type_name))
Branch: 1 branch
BranchTrueFalseTotal
find_type_constraint($type_name) or confess("The type constraint '${type_name}' does not exist") 5 0 5
87 || confess "The type constraint '$type_name' does not exist";
88 }
89  
90 29 $option_type_map{$type_name} = $option_string;
91 }
92  
93 27 1;
94  
95 __END__
↑ Summary Getopt/Basic.pm »