File Coverage

blib/lib/YATT/Lite/RegexpNames.pm
Criterion Covered Total %
statement 24 27 88.8
branch 3 4 75.0
condition n/a
subroutine 8 11 72.7
pod 0 7 0.0
total 35 49 71.4


line stmt bran cond sub pod time code
1             package YATT::Lite::RegexpNames;
2 14     14   5153 use strict;
  14         30  
  14         468  
3 14     14   74 use warnings qw(FATAL all NONFATAL misc);
  14         24  
  14         657  
4              
5 14     14   74 use Exporter qw/import/;
  14         31  
  14         463  
6 14     14   77 use YATT::Lite::Util qw/globref symtab/;
  14         32  
  14         7001  
7              
8             #========================================
9              
10             sub wrap {
11 340     340 0 806 my ($re, $partial) = @_;
12 340 100       2055 $partial ? $re : qq!^$re\\z!;
13             }
14              
15             # $this->re_name returns ^\w+$ -- Total pattern, usually for user input.
16             # $this->re_name(1) returns \w+ -- Partial pattern.
17              
18 339     339 0 1554 sub re_name { wrap(qr{\w+}, $_[1]) }
19              
20 1     1 0 4 sub re_digit { wrap(qr{(?:[0-9]+)}, $_[1]) }
21              
22 0     0 0 0 sub re_integer { wrap(qr{(?:0|[1-9]\d*)}, $_[1]) }
23              
24             # Mainly for untainting.
25 0     0 0 0 sub re_any { wrap(qr{.*}s, $_[1]) }
26              
27             # 'nonempty'-check should not complain about surrounding white spaces.
28 0     0 0 0 sub re_nonempty { qr{\S.*}s }
29              
30             # aliases
31             *re_word = *re_name; *re_word = *re_name;
32             *re_int = *re_integer; *re_int = *re_integer;
33             *re_digits = *re_digit; *re_digits = *re_digit;
34              
35              
36             #========================================
37              
38             __PACKAGE__->build_exports(\ our(@EXPORT, @EXPORT_OK));
39              
40             sub build_exports {
41 14     14 0 46 my ($pack, @vars) = @_;
42 14         59 my $symtab = symtab($pack);
43 14         70 foreach my $name (grep {/^re_/} keys %$symtab) {
  224         492  
44 112         240 my $glob = $symtab->{$name};
45 112 50       149 next unless *{$glob}{CODE};
  112         356  
46 112         569 push @$_, $name for @vars;
47             }
48             }
49              
50             1;