| 1 | package Scalar::In; ## no critic (TidyCode) | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Sub::Exporter -setup => { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | exports => [ qw( string_in numeric_in ) ], | ||||||||||||||||||||||||||||
| 7 | groups => { | ||||||||||||||||||||||||||||
| 8 | default => [ qw( string_in ) ], | ||||||||||||||||||||||||||||
| 9 | }, | ||||||||||||||||||||||||||||
| 10 | 4 | }; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 4 | our $VERSION = '0.002'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # using dualvars | ||||||||||||||||||||||||||||
| 15 | 4 | my $true = ! 0; | |||||||||||||||||||||||||||
| 16 | 4 | my $false = ! 1; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 32 | ▶ | sub string_in (++) { ## no critic (SubroutinePrototypes) | ||||||||||||||||||||||||||
|
Subroutine
string_in: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 32 | my ( $any1, $any2 ) = @_; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 32 | my $ref_any1 = ref $any1; | |||||||||||||||||||||||||||
| 22 | my @any1 | ||||||||||||||||||||||||||||
| 23 | = $ref_any1 eq 'ARRAY' | ||||||||||||||||||||||||||||
| 24 | 14 | ▶ | ? @{$any1} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | : $ref_any1 eq 'HASH' | ||||||||||||||||||||||||||||
| 26 | 32 | ▶ | ? keys %{$any1} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | : $any1; | ||||||||||||||||||||||||||||
| 28 | 32 | for my $string ( @any1 ) { | |||||||||||||||||||||||||||
| 29 | 32 | ▶ | if ( defined $string ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 23 | $string .= q{}; # stingify object | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | 32 | my $ref_any2 = ref $any2; | |||||||||||||||||||||||||||
| 33 | my @any2 | ||||||||||||||||||||||||||||
| 34 | = $ref_any2 eq 'ARRAY' | ||||||||||||||||||||||||||||
| 35 | 14 | ▶ | ? @{$any2} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | : $ref_any2 eq 'HASH' | ||||||||||||||||||||||||||||
| 37 | 32 | ▶ | ? keys %{$any2} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | : $any2; | ||||||||||||||||||||||||||||
| 39 | ITEM: | ||||||||||||||||||||||||||||
| 40 | 32 | for my $item ( @any2 ) { | |||||||||||||||||||||||||||
| 41 | 36 | ▶ | if ( ! defined $string || ! defined $item ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $string and defined $item
MC/DC100%2/2
defined $string and defined $item
defined $string
defined $item
Truth table100%3/3
A and B
A= defined $stringB= defined $item
| |||||||||||||||||||||||||||||
| 42 | 12 | ▶ | return ! ( defined $string xor defined $item ); | ||||||||||||||||||||||||||
|
Condition75%3/4
defined $string ^^ defined $item
MC/DC100%2/2
defined $string ^^ defined $item
defined $string
defined $item
Truth table75%3/4
A ^^ B
A= defined $stringB= defined $item
| |||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 24 | ▶ | if ( ref $item eq 'Regexp' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 6 | ▶ | $string =~ $item | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | and return $true; | ||||||||||||||||||||||||||||
| 47 | 3 | next ITEM; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 18 | ▶ | ref $item eq 'CODE' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | and return $item->($string); | ||||||||||||||||||||||||||||
| 51 | 17 | ▶ | $string eq q{} . $item # stingify object | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | and return $true; | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 8 | return $false; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 32 | ▶ | sub numeric_in (++) { ## no critic (SubroutinePrototypes) | ||||||||||||||||||||||||||
|
Subroutine
numeric_in: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 32 | my ( $any1, $any2 ) = @_; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 32 | my $ref_any1 = ref $any1; | |||||||||||||||||||||||||||
| 63 | my @any1 | ||||||||||||||||||||||||||||
| 64 | = $ref_any1 eq 'ARRAY' | ||||||||||||||||||||||||||||
| 65 | 13 | ▶ | ? @{$any1} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | : $ref_any1 eq 'HASH' | ||||||||||||||||||||||||||||
| 67 | 32 | ▶ | ? keys %{$any1} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | : $any1; | ||||||||||||||||||||||||||||
| 69 | 32 | for my $numeric ( @any1 ) { | |||||||||||||||||||||||||||
| 70 | 32 | ▶ | if ( defined $numeric ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 24 | $numeric += 0; # numify object | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 32 | my $ref_any2 = ref $any2; | |||||||||||||||||||||||||||
| 74 | my @any2 | ||||||||||||||||||||||||||||
| 75 | = $ref_any2 eq 'ARRAY' | ||||||||||||||||||||||||||||
| 76 | 14 | ▶ | ? @{$any2} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | : $ref_any2 eq 'HASH' | ||||||||||||||||||||||||||||
| 78 | 32 | ▶ | ? keys %{$any2} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | : $any2; | ||||||||||||||||||||||||||||
| 80 | ITEM: | ||||||||||||||||||||||||||||
| 81 | 32 | for my $item ( @any2 ) { | |||||||||||||||||||||||||||
| 82 | 35 | ▶ | if ( ! defined $numeric || ! defined $item ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $numeric and defined $item
MC/DC100%2/2
defined $numeric and defined $item
defined $numeric
defined $item
Truth table100%3/3
A and B
A= defined $numericB= defined $item
| |||||||||||||||||||||||||||||
| 83 | 11 | ▶ | return ! ( defined $numeric xor defined $item ); | ||||||||||||||||||||||||||
|
Condition75%3/4
defined $numeric ^^ defined $item
MC/DC100%2/2
defined $numeric ^^ defined $item
defined $numeric
defined $item
Truth table75%3/4
A ^^ B
A= defined $numericB= defined $item
| |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 24 | ▶ | if ( ref $item eq 'Regexp' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 6 | ▶ | $numeric =~ $item | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | and return $true; | ||||||||||||||||||||||||||||
| 88 | 3 | next ITEM; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 18 | ▶ | ref $item eq 'CODE' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | and return $item->($numeric); | ||||||||||||||||||||||||||||
| 92 | 17 | ▶ | $numeric == ( 0 + $item ) # numify object | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | and return $true; | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 8 | return $false; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # $Id$ | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 4 | 1; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | __END__ | ||||||||||||||||||||||||||||