File Coverage

blib/lib/Array/Contains.pm
Criterion Covered Total %
statement 35 35 100.0
branch 11 12 91.6
condition n/a
subroutine 8 8 100.0
pod 1 1 100.0
total 55 56 98.2


line stmt bran cond sub pod time code
1             package Array::Contains;
2              
3 3     3   180240 use 5.010_001;
  3         29  
4 3     3   14 use strict;
  3         5  
  3         51  
5 3     3   34 use warnings;
  3         6  
  3         123  
6 3     3   1462 use diagnostics;
  3         588924  
  3         28  
7 3     3   834 use mro 'c3';
  3         6  
  3         25  
8 3     3   1757 use English;
  3         9608  
  3         17  
9             our $VERSION = 2.8;
10 3     3   1226 use Carp;
  3         7  
  3         582  
11              
12             require Exporter;
13              
14             our @ISA = qw(Exporter);
15              
16             our @EXPORT = qw(contains);
17              
18             sub contains {
19 10     10 1 2126 my ($value, $dataset) = @_;
20              
21 10 100       30 if(!defined($value)) {
22 1         99 croak('value is not defined in contains()');
23             }
24              
25 9 100       22 if(!defined($dataset)) {
26 2         276 croak('dataset is not defined in contains()');
27             }
28              
29 7 100       22 if(ref($value) ne '') {
30 1         109 croak('value is not a scalar in contains()');
31             }
32              
33 6 100       18 if(ref($dataset) ne 'ARRAY') {
34 2         223 croak('dataset is not an array reference in contains()');
35             }
36              
37 4         16 foreach my $key (@{$dataset}) {
  4         7  
38 28 50       39 next if(ref($key) ne '');
39 28 100       41 if($value eq $key) {
40 2         11 return 1;
41             }
42             }
43              
44 2         9 return 0;
45             }
46              
47             1;
48             __END__