File Coverage

blib/lib/Regexp/Common/list.pm
Criterion Covered Total %
statement 17 17 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 25 26 96.1


line stmt bran cond sub pod time code
1             package Regexp::Common::list;
2              
3 71     71   625 use 5.10.0;
  71         158  
4              
5 71     71   231 use strict;
  71         80  
  71         1287  
6 71     71   214 use warnings;
  71         74  
  71         1617  
7 71     71   211 no warnings 'syntax';
  71         73  
  71         2085  
8              
9 71     71   238 use Regexp::Common qw /pattern clean no_defaults/;
  71         89  
  71         459  
10              
11             our $VERSION = '2016060801';
12              
13             sub gen_list_pattern {
14 8     8 0 12 my ($pat, $sep, $lsep) = @_;
15 8 100       18 $lsep = $sep unless defined $lsep;
16 8         40 return "(?k:(?:(?:$pat)(?:$sep))*(?:$pat)(?k:$lsep)(?:$pat))";
17             }
18              
19             my $defpat = '.*?\S';
20             my $defsep = '\s*,\s*';
21              
22             pattern name => ['list', "-pat=$defpat", "-sep=$defsep", '-lastsep'],
23             create => sub {gen_list_pattern (@{$_[1]}{-pat, -sep, -lastsep})},
24             ;
25              
26             pattern name => ['list', 'conj', '-word=(?:and|or)'],
27             create => sub {gen_list_pattern($defpat, $defsep,
28             '\s*,?\s*'.$_[1]->{-word}.'\s*');
29             },
30             ;
31              
32             pattern name => ['list', 'and'],
33             create => sub {gen_list_pattern ($defpat, $defsep, '\s*,?\s*and\s*')},
34             ;
35              
36             pattern name => ['list', 'or'],
37             create => sub {gen_list_pattern ($defpat, $defsep, '\s*,?\s*or\s*')},
38             ;
39              
40              
41             1;
42              
43             __END__