File Coverage

blib/lib/Sub/Regex.pm
Criterion Covered Total %
statement 24 27 88.8
branch 2 4 50.0
condition n/a
subroutine 7 7 100.0
pod n/a
total 33 38 86.8


line stmt bran cond sub pod time code
1             package Sub::Regex;
2              
3 2     2   41067 use 5.006;
  2         10  
  2         78  
4 2     2   45 use strict;
  2         3  
  2         117  
5             our $VERSION = '0.02';
6             require Exporter;
7 2     2   2855 use AutoLoader;
  2         4345  
  2         11  
8             our @EXPORT = qw/AUTOLOAD/;
9             our @ISA = qw(Exporter AutoLoader);
10              
11             my %Regs;
12             my $Regprefix = q/__REGSUB__/;
13              
14 2     2   3540 use Filter::Simple;
  2         108487  
  2         16  
15             FILTER {
16             my $sno = 0;
17             while(s,^[\s\t]*sub[\t\s]+/(.+)/.*[\t\s]*(\([\$\@\%\\\*;&]*?\))?\{,"sub ${Regprefix}".$sno." ".($2?$2:'')."{",meg
18             ){
19             $Regs{$1} = $sno++;
20             }
21             # print $_;
22             };
23              
24             sub AUTOLOAD{
25 2     2   428 no strict 'refs';
  2         5  
  2         76  
26 2     2   21 use vars '$AUTOLOAD';
  2         7  
  2         492  
27 10     10   2736 $AUTOLOAD =~ /(.+)::/;
28 10         26 my $pkg = $1;
29 10 50       33 if ($' eq 'DESTROY'){
30 0         0 goto &{"$pkg::DESTROY"};
  0         0  
31             }
32             else{
33 10         25 for my $k (keys %Regs){
34 10 50       167 goto &{"$pkg"."::${Regprefix}".$Regs{$k}} if ( $AUTOLOAD =~ /$k/i );
  10         86  
35             }
36 0           die "Can't translate your sub << $AUTOLOAD >>\n";
37             }
38             }
39              
40              
41              
42             1;
43              
44             __END__