File Coverage

blib/lib/Scalar/In.pm
Criterion Covered Total %
statement 51 51 100.0
branch 40 40 100.0
condition 10 14 71.4
subroutine 5 5 100.0
pod 2 2 100.0
total 108 112 96.4


line stmt bran cond sub pod time code
1             package Scalar::In; ## no critic (TidyCode)
2            
3 4     4   112872 use strict;
  4         10  
  4         157  
4 4     4   23 use warnings;
  4         10  
  4         216  
5 4         52 use Sub::Exporter -setup => {
6             exports => [ qw( string_in numeric_in ) ],
7             groups => {
8             default => [ qw( string_in ) ],
9             },
10 4     4   5659 };
  4         50394  
11            
12             our $VERSION = '0.002';
13            
14             # using dualvars
15             my $true = ! 0;
16             my $false = ! 1;
17            
18             sub string_in (++) { ## no critic (SubroutinePrototypes)
19 32     32 1 1535 my ( $any1, $any2 ) = @_;
20            
21 32         58 my $ref_any1 = ref $any1;
22             my @any1
23 14         35 = $ref_any1 eq 'ARRAY'
24 4         12 ? @{$any1}
25             : $ref_any1 eq 'HASH'
26 32 100       118 ? keys %{$any1}
    100          
27             : $any1;
28 32         60 for my $string ( @any1 ) {
29 32 100       73 if ( defined $string ) {
30 23         168 $string .= q{}; # stingify object
31             }
32 32         60 my $ref_any2 = ref $any2;
33             my @any2
34 14         33 = $ref_any2 eq 'ARRAY'
35 6         19 ? @{$any2}
36             : $ref_any2 eq 'HASH'
37 32 100       94 ? keys %{$any2}
    100          
38             : $any2;
39             ITEM:
40 32         59 for my $item ( @any2 ) {
41 34 100 66     125 if ( ! defined $string || ! defined $item ) {
42 12   75     127 return ! ( defined $string xor defined $item );
43             }
44 22 100       63 if ( ref $item eq 'Regexp' ) {
45 6 100       54 $string =~ $item
46             and return $true;
47 3         14 next ITEM;
48             }
49 16 100       41 ref $item eq 'CODE'
50             and return $item->($string);
51 15 100       100 $string eq q{} . $item # stingify object
52             and return $true;
53             }
54             }
55            
56 8         49 return $false;
57             }
58            
59             sub numeric_in (++) { ## no critic (SubroutinePrototypes)
60 32     32 1 1052 my ( $any1, $any2 ) = @_;
61            
62 32         60 my $ref_any1 = ref $any1;
63             my @any1
64 13         30 = $ref_any1 eq 'ARRAY'
65 4         12 ? @{$any1}
66             : $ref_any1 eq 'HASH'
67 32 100       105 ? keys %{$any1}
    100          
68             : $any1;
69 32         64 for my $numeric ( @any1 ) {
70 32 100       75 if ( defined $numeric ) {
71 24         108 $numeric += 0; # numify object
72             }
73 32         55 my $ref_any2 = ref $any2;
74             my @any2
75 14         30 = $ref_any2 eq 'ARRAY'
76 6         19 ? @{$any2}
77             : $ref_any2 eq 'HASH'
78 32 100       88 ? keys %{$any2}
    100          
79             : $any2;
80             ITEM:
81 32         59 for my $item ( @any2 ) {
82 37 100 66     139 if ( ! defined $numeric || ! defined $item ) {
83 11   75     109 return ! ( defined $numeric xor defined $item );
84             }
85 26 100       62 if ( ref $item eq 'Regexp' ) {
86 6 100       62 $numeric =~ $item
87             and return $true;
88 3         16 next ITEM;
89             }
90 20 100       48 ref $item eq 'CODE'
91             and return $item->($numeric);
92 19 100       108 $numeric == ( 0 + $item ) # numify object
93             and return $true;
94             }
95             }
96            
97 8         44 return $false;
98             }
99            
100             # $Id$
101            
102             1;
103            
104             __END__