| 1 | package Term::Choose::ValidateOptions; | ||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 5 | 3 | ▶ | use 5.10.1; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||
| 7 | 3 | our $VERSION = '1.783'; | |||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Exporter qw( import ); | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||
| 11 | 3 | our @EXPORT_OK = qw( validate_options ); | |||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||
| 16 | 111 | ▶ | sub validate_options { | ||||||||||||||||||||||||
|
Subroutine
validate_options: called CC=21 SCAR=36.4
Pod
undocumented
| |||||||||||||||||||||||||||
| 17 | 111 | my ( $valid, $opt, $caller ) = @_; | |||||||||||||||||||||||||
| 18 | 111 | ▶ | return if ! defined $opt; # | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 19 | 111 | ▶ | if ( ! defined $caller ) { # | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 20 | 0 | $caller = ''; | |||||||||||||||||||||||||
| 21 | }; | ||||||||||||||||||||||||||
| 22 | 111 | for my $key ( keys %$opt ) { | |||||||||||||||||||||||||
| 23 | 150 | ▶ | if ( ! exists $valid->{$key} ) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 24 | 0 | croak "$caller: '$key' is not a valid option name"; | |||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||
| 26 | 150 | ▶ | next if ! defined $opt->{$key}; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 27 | 113 | ▶ | if ( $valid->{$key} =~ /^Array/ ) { | ||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||
| 28 | 16 | ▶ | croak "$caller: option '$key' => the passed value has to be an ARRAY reference." if ref $opt->{$key} ne 'ARRAY'; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 29 | 16 | ▶ | if ( $valid->{$key} eq 'Array_Int_Idx' ) { | ||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||
| 30 | 8 | for ( @{$opt->{$key}} ) { | |||||||||||||||||||||||||
| 31 | 19 | ▶ | defined or croak "$caller: option '$key' => undefined array element"; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 32 | 19 | ▶ | /^[0-9]+\z/ or croak "$caller: option '$key' => $_ is an invalid array element"; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||
| 35 | elsif ( $valid->{$key} eq 'Array_Int' ) { | ||||||||||||||||||||||||||
| 36 | 8 | for ( @{$opt->{$key}} ) { | |||||||||||||||||||||||||
| 37 | 9 | ▶ | if ( defined ) { | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 38 | 9 | ▶ | /^[0-9]+\z/ or croak "$caller: option '$key' => $_ is an invalid array element"; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||
| 43 | elsif ( $valid->{$key} =~ /^Regexp/ ) { | ||||||||||||||||||||||||||
| 44 | 0 | ▶ | croak "$caller: option '$key' => the passed value has to be a regex quoted with the 'qr' operator." if ref $opt->{$key} ne 'Regexp'; | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||
| 46 | elsif ( ref $opt->{$key} ) { | ||||||||||||||||||||||||||
| 47 | 0 | croak "$caller: option '$key' => a reference is not a valid value."; | |||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||
| 49 | elsif ( $valid->{$key} eq 'Str' ) { | ||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||
| 51 | elsif ( $opt->{$key} !~ m/^$valid->{$key}\z/x ) { | ||||||||||||||||||||||||||
| 52 | 0 | croak "$caller: option '$key' => '$opt->{$key}' is not a valid value."; | |||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||
| 62 | 3 | 1; | |||||||||||||||||||||||||