File Coverage

blib/lib/Sub/Way.pm
Criterion Covered Total %
statement 21 26 80.7
branch 12 18 66.6
condition 3 3 100.0
subroutine 5 5 100.0
pod 1 1 100.0
total 42 53 79.2


line stmt bran cond sub pod time code
1             package Sub::Way;
2 2     2   30550 use strict;
  2         5  
  2         75  
3 2     2   10 use warnings;
  2         2  
  2         59  
4 2     2   816 use parent 'Exporter';
  2         522  
  2         9  
5              
6             our $VERSION = '0.01';
7              
8             our @EXPORT_OK = qw/ match /;
9              
10             sub match {
11 8     8 1 17 my ($target, $cond, $and) = @_;
12              
13 8 100       23 if ( ref($cond) eq 'ARRAY' ) {
14 5 50       7 if ($and) {
15 0         0 for my $c (@{$cond}) {
  0         0  
16 0 0       0 return unless _match($target, $c);
17             }
18 0         0 return 1;
19             }
20             else {
21 5         5 for my $c (@{$cond}) {
  5         15  
22 7 100       8 return 1 if _match($target, $c);
23             }
24             }
25             }
26             else {
27 3 50       5 return 1 if _match($target, $cond);
28             }
29              
30 0         0 return; # not match
31             }
32              
33             sub _match {
34 10     10   9 my ($target, $cond) = @_;
35              
36 10 100 100     33 if ( !ref($cond) || ref($cond) eq 'Regexp' ) {
    50          
37 9 100       88 return 1 if $target =~ m!$cond!;
38             }
39             elsif ( ref($cond) eq 'CODE' ) {
40 1 50       3 return 1 if $cond->($target);
41             }
42              
43 2         5 return;
44             }
45              
46             1;
47              
48             __END__