File Coverage

blib/lib/Keyword/TailRecurse.pm
Criterion Covered Total %
statement 90 140 64.2
branch 13 34 38.2
condition 7 21 33.3
subroutine 19 20 95.0
pod n/a
total 129 215 60.0


line stmt bran cond sub pod time code
1             package Keyword::TailRecurse;
2 5     5   293530 use 5.014;
  5         52  
3 5     5   22 use strict;
  5         6  
  5         78  
4 5     5   18 use warnings;
  5         7  
  5         186  
5              
6             our $VERSION = "0.02";
7              
8 5     5   3674 use Keyword::Declare;
  5         525041  
  5         47  
9              
10             my $subCallTailCompatible = 0;
11              
12             my %imported;
13              
14             sub import {
15 6     6   293 my %option = map { $_ => 1 } @_;
  10         33  
16              
17 6 100       32 if( $option{tailrecurse} ) {
  1         2  
18 0 50 50 3   0 keyword tailrecurse (Bareword $function, List? $parameters) {
  0         0  
  0         0  
  0         0  
  1         5  
  3         169239  
  3         7  
  3         7  
  3         4  
19 0         0 return "\@_ = ( $parameters ); goto &$function;";
  1         37  
  3         16  
20 5         33 };
  1         9  
21 1         46 $imported{tailrecurse} = 1;
  1         22  
22 5     5   162307 }
23              
24 6 100       28 if( $option{tail_recurse} ) {
  1         2  
25 0 50 50 3   0 keyword tail_recurse (Bareword $function, List? $parameters) {
  0         0  
  0         0  
  0         0  
  1         5  
  3         170279  
  3         9  
  3         7  
  3         5  
26 0         0 return "\@_ = ( $parameters ); goto &$function;";
  1         34  
  3         17  
27 5         29 };
  1         9  
28 1         44 $imported{tail_recurse} = 1;
  1         21  
29 5     5   158594 }
30              
31 6 100 66     49 if( $option{tailRecurse} || ! keys %imported ) {
  3         5  
32 0 50 50 3   0 keyword tailRecurse (Bareword $function, List? $parameters) {
  0         0  
  0         0  
  0         0  
  3         26  
  3         168595  
  3         8  
  3         6  
  3         6  
33 0         0 return "\@_ = ( $parameters ); goto &$function;";
  3         65  
  3         13  
34 5         32 };
  3         25  
35 3         119 $imported{tailRecurse} = 1;
  3         62  
36 5     5   180291 }
37              
38 6 100       194 if ( $option{subCallTail} ) {
  2         5  
39 0 50 50 3   0 keyword tail (Bareword $function, List? $parameters) {
  0         0  
  0         0  
  0         0  
  2         8  
  3         254471  
  3         8  
  3         6  
  3         7  
40 0         0 return "\@_ = ( $parameters ); goto &$function;";
  2         57  
  3         16  
41 5         33 };
  2         13  
42 2         71  
  2         47  
43 5 50 50 5   156214 keyword tail (/\$[_a-zA-Z0-9]+\s*->\s*[_a-zA-Z0-9]+/ $methodCall, List? $parameters) {
  0     1   0  
  0         0  
  0         0  
  0         0  
  2         6  
  1         85941  
  1         3  
  1         66  
  1         9  
44 0         0 my ($object, $method) = split /\s*->\s*/, $methodCall;
  2         54  
  1         7  
45              
46 0         0 return "\@_ = ( $object, $parameters ); goto &{(ref $object) . '::$method'};";
  1         8  
47 5         34 };
  2         14  
48 2         56  
49 5     5   161806 $imported{subCallTail} = 1;
  2         149  
50             }
51             }
52              
53             sub unimport {
54 0 0   0     if( $imported{tailRecurse} ) {
  0            
  0            
55 0 0 0       unkeyword tailRecurse;
  0            
56 0           }
57 5 0   5   146048 if( $imported{tailrecurse} ) {
  0            
  0            
  0            
58 5 0 0     263 unkeyword tailrecurse;
  0            
  0            
59 0           }
60 5 0   5   145871 if( $imported{tail_recurse} ) {
  0            
  0            
  0            
61 5 0 0     301 unkeyword tail_recurse;
  0            
  0            
62 0           }
63 5 0   5   146764 if( $imported{subCallTail} ) {
  0            
  0            
  0            
64 5 0 0     269 unkeyword tail;
  0            
  0            
65 0           }
66 5     5   140359 }
67 5         794  
68              
69             1;
70             __END__