File Coverage

blib/lib/Sub/Recursive.pm
Criterion Covered Total %
statement 36 36 100.0
branch n/a
condition n/a
subroutine 9 9 100.0
pod 2 2 100.0
total 47 47 100.0


line stmt bran cond sub pod time code
1             package Sub::Recursive;
2              
3             $VERSION = 0.03;
4             @EXPORT = qw/ recursive $REC /;
5             @EXPORT_OK = (@EXPORT, qw/ mutually_recursive %REC /);
6             $EXPORT_TAGS{ALL} = \@EXPORT_OK;
7              
8             $REC = '$REC is a special variable used by ' . __PACKAGE__;
9             %REC = ($REC, $REC);
10              
11 3     3   72499 use 5.006;
  3         11  
  3         104  
12 3     3   15 use strict;
  3         5  
  3         104  
13 3     3   24 use base 'Exporter';
  3         18  
  3         406  
14              
15             sub recursive (&) {
16 4     4 1 1864 my ($code) = @_;
17              
18 3     3   16 my $rec = do { no strict 'refs'; \*{caller() . '::REC'} };
  3         10  
  3         341  
  4         6  
  4         25  
  4         17  
19             return sub {
20 3     3   332 local *$rec = \$code;
21 3         11 &$code;
22 4         18 };
23             }
24              
25             sub mutually_recursive {
26 1     1 1 550 my @p = @_;
27 1         3 my %p = @_;
28              
29 3     3   15 my $rec = do { no strict 'refs'; \*{caller() . '::REC'} };
  3         5  
  3         447  
  1         2  
  1         2  
  1         4  
30              
31 1         2 my $c = 0;
32 1         1 my @codes;
33 1         3 for my $code (grep { $c++ % 2 } @p) {
  4         8  
34             push @codes => sub {
35 20     20   187 local *$rec = \$code;
36 20         22 local *$rec = \%p;
37 20         32 &$code;
38 2         22 };
39             }
40 1         5 return @codes;
41             }
42              
43             1;
44              
45             __END__