| 1 | package Declare::Opts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 7 | our $VERSION = "0.009"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use Exporter::Declare qw{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | import | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | gen_default_export | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | default_export | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 7 | ▶ | gen_default_export 'OPTS_META' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 7 | my ( $class, $caller ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 7 | my $meta = $class->new(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 7 | $meta->{class} = $caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 7 | ▶ | return sub { $meta }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 20 | ▶ | default_export opt => sub { caller->OPTS_META->opt( @_ ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 12 | ▶ | default_export parse_opts => sub { caller->OPTS_META->parse( @_ ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | default_export opt_info => sub { caller->OPTS_META->info }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | sub class { shift->{class} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 145 | ▶ | sub opts { shift->{opts} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
opts: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 9 | ▶ | sub default { shift->{default} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 7 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 7 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 7 | my ( %opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 7 | my $self = bless { opts => {}, default => {} } => $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 7 | $self->opt( $_, $opts{$_} ) for keys %opts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 7 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 24 | ▶ | sub valid_opt_params { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
valid_opt_params: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 24 | return qr/^(alias|list|bool|default|check|transform|description)$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 20 | ▶ | sub opt { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
opt: called CC=22 SCAR=31.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 20 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 20 | my ( $name, %config ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | croak "opt '$name' already defined" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 20 | ▶ | if $self->opts->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 20 | for my $prop ( keys %config ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 24 | ▶ | next if $prop =~ $self->valid_opt_params; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | croak "invalid opt property: '$prop'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 20 | $config{name} = $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | croak "'check' cannot be used with 'bool'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 20 | ▶ | if $config{bool} && $config{check}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$config{"bool"} and $config{"check"}
MC/DC0%0/2
$config{"bool"} and $config{"check"}
$config{"bool"}
$config{"check"}
Truth table66%2/3
A and B
A= $config{"bool"}B= $config{"check"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | croak "'transform' cannot be used with 'bool'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 20 | ▶ | if $config{bool} && $config{transform}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$config{"bool"} and $config{"transform"}
MC/DC0%0/2
$config{"bool"} and $config{"transform"}
$config{"bool"}
$config{"transform"}
Truth table66%2/3
A and B
A= $config{"bool"}B= $config{"transform"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | croak "opt properties 'list' and 'bool' are mutually exclusive" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 20 | ▶ | if $config{list} && $config{bool}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$config{"list"} and $config{"bool"}
MC/DC100%2/2
$config{"list"} and $config{"bool"}
$config{"list"}
$config{"bool"}
Truth table100%3/3
A and B
A= $config{"list"}B= $config{"bool"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 19 | ▶ | if (exists $config{default}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | croak "References cannot be used in default, wrap them in a sub." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | ▶ | if ref $config{default} && ref $config{default} ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $config{"default"} and ref $config{"default"} ne "CODE"
MC/DC0%0/2
ref $config{"default"} and ref $config{"default"} ne "CODE"
ref $config{"default"}
ref $config{"default"} ne "CODE"
Truth table33%1/3
A and B
A= ref $config{"default"}B= ref $config{"default"} ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | $self->default->{$name} = $config{default}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 19 | ▶ | if ( exists $config{check} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 9 | my $ref = ref $config{check}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | croak "'$config{check}' is not a valid value for 'check'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | if ($ref && $ref !~ m/^(CODE|Regexp)$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 9 | ▶ | || (!$ref && $config{check} !~ m/^(file|dir|number)$/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$ref and not $ref =~ /^(CODE|Regexp)$/ or not $ref || $config{"check"} =~ /^(file|dir|number)$/
$ref and not $ref =~ /^(CODE|Regexp)$/
$ref || $config{'check'} =~ /^(file|dir|number)$/
MC/DC100%4/4
$ref and not $ref =~ /^(CODE|Regexp)$/ or not $ref || $config{"check"} =~ /^(file|dir|number)$/
$ref
not $ref =~ /^(CODE|Regexp)$/
$ref
$config{'check'} =~ /^(file|dir|number)$/
Truth table57%4/7
A and not(B) or not(C || D)
A= $refB= not $ref =~ /^(CODE|Regexp)$/C= $refD= $config{'check'} =~ /^(file|dir|number)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 17 | ▶ | if ( exists $config{alias} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | my $aliases = ref $config{alias} ? $config{alias} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | ▶ | : [ $config{alias} ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | $config{_alias} = { map { $_ => 1 } @$aliases }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | for my $alias ( @$aliases ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | croak "Cannot use alias '$alias', name is already taken by another opt." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 3 | ▶ | if $self->opts->{$alias}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | $self->opts->{$alias} = \%config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 17 | $self->opts->{$name} = \%config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 12 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 12 | my @opts = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 12 | my $params = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 12 | my $flags = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 12 | my $no_flags = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 12 | ▶ | while ( my $opt = shift @opts ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 33 | ▶ | if ( $opt eq '--' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 3 | $no_flags++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | ▶ | elsif ( $opt =~ m/^-+([^-=]+)(?:=(.+))?$/ && !$no_flags ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$opt =~ /^-+([^-=]+)(?:=(.+))?$/ and not $no_flags
MC/DC100%2/2
$opt =~ /^-+([^-=]+)(?:=(.+))?$/ and not $no_flags
$opt =~ /^-+([^-=]+)(?:=(.+))?$/
not $no_flags
Truth table100%3/3
A and not(B)
A= $opt =~ /^-+([^-=]+)(?:=(.+))?$/B= not $no_flags
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 24 | my ( $key, $value ) = ( $1, $2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 24 | my $name = $self->_flag_name( $key ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 22 | my $values = $self->_flag_value( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | $value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | \@opts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 17 | ▶ | if( $self->opts->{$name}->{list} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 5 | push @{$flags->{$name}} => @$values; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 12 | $flags->{$name} = $values->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 6 | push @$params => $opt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # Add defaults for opts not provided | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 5 | for my $opt ( keys %{ $self->default } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 4 | ▶ | next if exists $flags->{$opt}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | my $val = $self->default->{$opt}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 2 | ▶ | $flags->{$opt} = ref $val ? $val->() : $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 5 | return ( $params, $flags ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 2 | ▶ | sub info { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
info: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 4 | ▶ | map { $self->opts->{$_}->{name} => $self->opts->{$_}->{description} || "No Description" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->opts->{$_}{'description'} || 'No Description'
MC/DC100%1/1
$self->opts->{$_}{'description'} || 'No Description'
$self->opts->{$_}{'description'}
Truth table100%2/2
A
A= $self->opts->{$_}{'description'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | keys %{ $self->opts } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 22 | ▶ | sub _flag_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_flag_value: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 22 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 22 | my ( $flag, $value, $opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 22 | my $spec = $self->opts->{$flag}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 22 | ▶ | if ( $spec->{bool} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 3 | ▶ | return [$value] if defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | ▶ | return [$spec->{default} ? 0 : 1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 19 | ▶ | my $val = defined $value ? $value : shift @$opts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 19 | ▶ | my $out = $spec->{list} ? [ split /\s*,\s*/, $val ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | : [ $val ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 19 | $self->_validate( $flag, $spec, $out ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 14 | ▶ | return $out unless $spec->{transform}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 2 | return [ map { $spec->{transform}->($_) } @$out ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 19 | ▶ | sub _validate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 19 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 19 | my ( $flag, $spec, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 19 | my $check = $spec->{check}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 19 | ▶ | return unless $check; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 12 | ▶ | my $ref = ref $check || ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
ref $check || ''
MC/DC100%1/1
ref $check || ''
ref $check
Truth table100%2/2
A
A= ref $check
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 12 | my @bad; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 12 | ▶ | if ( $ref eq 'Regexp' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 2 | @bad = grep { $_ !~ $check } @$value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | elsif ( $ref eq 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 2 | @bad = grep { !$check->( $_ ) } @$value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | elsif ( $check eq 'file' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 2 | @bad = grep { ! -f $_ } @$value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | elsif ( $check eq 'dir' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 2 | @bad = grep { ! -d $_ } @$value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | elsif ( $check eq 'number' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 4 | @bad = grep { m/\D/ } @$value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 12 | ▶ | return unless @bad; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 5 | ▶ | my $type = $ref || $check; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$ref || $check
MC/DC0%0/2
$ref || $check
$ref
$check
Truth table66%2/3
A || B
A= $refB= $check
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 5 | die "Validation Failed for '$flag=$type': " . join( ", ", @bad ) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 24 | ▶ | sub _flag_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_flag_name: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 24 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 24 | my ( $key ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # Exact match | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | return $self->opts->{$key}->{name} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 24 | ▶ | if $self->opts->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 4 | my %matches = map { $self->opts->{$_}->{name} => 1 } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 22 | grep { m/^$key/ } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 4 | keys %{ $self->opts }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 4 | my @matches = keys %matches; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 4 | ▶ | die "partial option '$key' is ambiguous, could be: " . join( ", " => @matches ) . "\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | if @matches > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 3 | ▶ | die "unknown option '$key'\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | unless @matches; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 2 | return $matches[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||