File Coverage

blib/lib/List/Util/Find.pm
Criterion Covered Total %
statement 28 28 100.0
branch 13 16 81.2
condition 6 12 50.0
subroutine 6 6 100.0
pod 2 2 100.0
total 55 64 85.9


line stmt bran cond sub pod time code
1             package List::Util::Find;
2              
3 2     2   430837 use strict;
  2         4  
  2         77  
4 2     2   13 use warnings;
  2         4  
  2         137  
5              
6 2     2   13 use Exporter 'import';
  2         4  
  2         264  
7              
8             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
9             our $DATE = '2023-09-16'; # DATE
10             our $DIST = 'List-Util-Find'; # DIST
11             our $VERSION = '0.005'; # VERSION
12              
13             our @EXPORT_OK = qw(
14             hasnum
15             hasstr
16             );
17              
18             sub hasnum {
19 2     2   12 no warnings 'numeric';
  2         2  
  2         945  
20              
21 6     6 1 450473 my $needle = shift;
22 6 50       20 warn "hasnum(): needle is undefined" unless defined $needle;
23              
24 6         17 for (@_) {
25             # TODO: handle Inf & -Inf (and NaN also?)
26 45 100       92 next unless defined;
27 41 100       106 next unless $needle == $_;
28 10 100       25 if ($needle == 0) {
29             # when needle == 0, we want to make sure that we don't match "foo"
30             # as 0.
31 7 100       40 return 1 if /\A\s*[+-]?(?:0|[1-9][0-9]*)\s*\z/s; # from isint()
32 6 50 33     72 return 1 if /\A\s*[+-]?
      33        
      33        
33             (?: (?:0|[1-9][0-9]*)(\.[0-9]+)? | (\.[0-9]+) )
34             ([eE][+-]?[0-9]+)?\s*\z/sx && $1 || $2 || $3; # from isfloat()
35 6         15 next;
36             } else {
37 3         42 return 1;
38             }
39             }
40 2         11 0;
41             }
42              
43             sub hasstr {
44 5     5 1 4431 my $needle = shift;
45              
46 5 50       20 warn "hasstr(): needle is undefined" unless defined $needle;
47              
48 5         14 for (@_) {
49 32 100 100     132 return 1 if defined $_ && $needle eq $_;
50             }
51 2         15 0;
52             }
53              
54             1;
55             # ABSTRACT: List utilities related to finding items
56              
57             __END__