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 72     72   892 use 5.10.0;
  72         154  
4              
5 72     72   259 use strict;
  72         82  
  72         1236  
6 72     72   242 use warnings;
  72         75  
  72         1640  
7 72     72   214 no warnings 'syntax';
  72         80  
  72         2252  
8              
9 72     72   256 use Regexp::Common qw /pattern clean no_defaults/;
  72         89  
  72         1069  
10              
11             our $VERSION = '2017040401';
12              
13             sub gen_list_pattern {
14 8     8 0 12 my ($pat, $sep, $lsep) = @_;
15 8 100       15 $lsep = $sep unless defined $lsep;
16 8         33 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__