| 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
Condition66%2/3
builtin::blessed($type_or_name) and $type_or_name->isa("Moose::Meta::TypeConstraint::Union")
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")
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 2 | ▶ | my $current = blessed($type_or_name) ? $type_or_name : find_type_constraint($type_or_name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 2 | ▶ | (defined $current) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | || confess "Could not find the type constraint for '$type_or_name'"; | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 2 | ▶ | while (my $parent = $current->parent) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 2 | ▶ | return 1 if exists $option_type_map{$parent->name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
builtin::blessed($type_or_name) and $type_or_name->isa("Moose::Meta::TypeConstraint::Union")
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")
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 475 | ▶ | return $option_type_map{$name} if exists $option_type_map{$name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 2 | ▶ | my $current = ref $type_or_name ? $type_or_name : find_type_constraint($type_or_name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 2 | ▶ | (defined $current) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | || confess "Could not find the type constraint for '$type_or_name'"; | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 2 | ▶ | while ( $current = $current->parent ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | return $option_type_map{$current->name} | ||||||||||||||||||||||||||||
| 72 | 2 | ▶ | if exists $option_type_map{$current->name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $type_name and defined $option_string
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
| |||||||||||||||||||||||||||||
| 81 | || confess "You must supply both a type name and an option string"; | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 29 | ▶ | if ( blessed($type_name) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 24 | $type_name = $type_name->name; | |||||||||||||||||||||||||||
| 85 | } else { | ||||||||||||||||||||||||||||
| 86 | 5 | ▶ | (find_type_constraint($type_name)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||