blib/lib/MouseX/Getopt/OptionTypeMap.pm

filter: Statementstmt 91.6% 33 / 36 Branchbran 60.0% 18 / 30 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 76.5% 62 / 81 SCAR 30.6
CC
17
Cov
75%
has_option_type
9.1
get_option_type
8.3
add_option_type_to_map
5.5
CRAP 21.3
« blib/lib/MouseX/Getopt/Basic.pm ↑ Summary blib/lib/MouseX/Getopt/GLD.pm »
1 package MouseX::Getopt::OptionTypeMap;
2 # ABSTRACT: Storage for the option to type mappings
3  
4 22 ▶use Mouse 'confess', 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 22 ▶use Mouse::Util::TypeConstraints 'find_type_constraint';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 22 my %option_type_map = (
8 'Bool' => '!',
9 'Str' => '=s',
10 'Int' => '=i',
11 'Num' => '=f',
12 'ArrayRef' => '=s@',
13 'HashRef' => '=s%',
14 );
15  
16 sub has_option_type {
17 545 ▶ my (undef, $type_or_name) = @_;
Subroutine has_option_type: called CC=7 SCAR=22.1
Pod documented
18  
19 545 ▶ 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} 543 2 545
builtin::blessed($type_or_name) ? : 545 0 545
20  
21 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
22  
23 2 ▶ (defined $current)
Branch: 1 branch
BranchTrueFalseTotal
defined $current or confess("Could not find the type constraint for '${type_or_name}'") 0 2 2
24 || confess "Could not find the type constraint for '$type_or_name'";
25  
26 2 ▶ while (my $parent = $current->parent) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent = $current->parent) 2 0 2
27 2 ▶ return 1 if exists $option_type_map{$parent->name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $option_type_map{$parent->name} 2 0 2
28 0 $current = $parent;
29 }
30  
31 0 return 0;
32 }
33  
34 sub get_option_type {
35 545 ▶ my (undef, $type_or_name) = @_;
Subroutine get_option_type: called CC=7 SCAR=21.2
Pod documented
36  
37 545 ▶ my $name = blessed($type_or_name) ? $type_or_name->name : $type_or_name;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($type_or_name) ? : 545 0 545
38  
39 545 ▶ return $option_type_map{$name} if exists $option_type_map{$name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $option_type_map{$name} 543 2 545
40  
41 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
42  
43 2 ▶ (defined $current)
Branch: 1 branch
BranchTrueFalseTotal
defined $current or confess("Could not find the type constraint for '${type_or_name}'") 0 2 2
44 || confess "Could not find the type constraint for '$type_or_name'";
45  
46 2 ▶ while ( $current = $current->parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current = $current->parent) 2 0 2
47 return $option_type_map{$current->name}
48 2 ▶ if exists $option_type_map{$current->name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $option_type_map{$current->name} 2 0 2
49 }
50  
51 0 return;
52 }
53  
54 sub add_option_type_to_map {
55 9 ▶ my (undef, $type_name, $option_string) = @_;
Subroutine add_option_type_to_map: called CC=5 SCAR=17.0
Pod documented
56 9 ▶ (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") 0 9 9
Condition33%1/3
defined $type_name and defined $option_string
!ll&&!rl&&r
009
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
57 || confess "You must supply both a type name and an option string";
58  
59 9 ▶ if ( blessed($type_name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($type_name)) { } 4 5 9
60 4 $type_name = $type_name->name;
61 } else {
62 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") 0 5 5
63 || confess "The type constraint '$type_name' does not exist";
64 }
65  
66 9 $option_type_map{$type_name} = $option_string;
67 }
68  
69 22 ▶no Mouse::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 22 ▶no Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
71  
72 22 1;
73  
74 =head1 DESCRIPTION
75  
76 See the I<Custom Type Constraints> section in the L<MouseX::Getopt> docs
77 for more info about how to use this module.
78  
79 =over 4
80  
81 =item B<has_option_type ($type_or_name)>
82  
83 =item B<get_option_type ($type_or_name)>
84  
85 =item B<add_option_type_to_map ($type_name, $option_spec)>
86  
87 =back
88  
89 =cut
« blib/lib/MouseX/Getopt/Basic.pm ↑ Summary blib/lib/MouseX/Getopt/GLD.pm »