File Coverage

blib/lib/Keyword/TailRecurse.pm
Criterion Covered Total %
statement 120 200 60.0
branch 13 34 38.2
condition 7 21 33.3
subroutine 19 20 95.0
pod n/a
total 159 275 57.8


line stmt bran cond sub pod time code
1             package Keyword::TailRecurse;
2 5     5   350830 use 5.014;
  5         55  
3 5     5   27 use strict;
  5         12  
  5         96  
4 5     5   23 use warnings;
  5         9  
  5         198  
5              
6             our $VERSION = "0.04";
7              
8 5     5   4745 use Keyword::Declare;
  5         564254  
  5         48  
9              
10             my $subCallTailCompatible = 0;
11              
12             my %imported;
13              
14             sub import {
15 6     6   445 my %option = map { $_ => 1 } @_;
  10         60  
16              
17 6 100       45 if( $option{tailrecurse} ) {
  1         1  
18 0 50 50 3   0 keyword tailrecurse (Bareword $function, List? $parameters) {
  0         0  
  0         0  
  1         5  
  3         161388  
  3         8  
  3         7  
19 0         0 return "\@_ = ( $parameters ); goto &$function;";
  1         39  
  3         392  
20 0         0 };
  3         70  
21 1         26 $imported{tailrecurse} = 1;
22 0         0 }
  0         0  
  3         112  
  3         7  
23 0         0  
  3         32  
24 0 100       0 if( $option{tail_recurse} ) {
  3         35  
  6         30  
  1         2  
25 0 50 50 3   0 keyword tail_recurse (Bareword $function, List? $parameters) {
  0         0  
  0         0  
  1         4  
  3         162751  
  3         9  
  3         8  
26 0         0 return "\@_ = ( $parameters ); goto &$function;";
  0         0  
  3         50  
  1         39  
  3         384  
27 0         0 };
  0         0  
  3         46  
  3         71  
28 5         40 $imported{tail_recurse} = 1;
  1         11  
  1         26  
29 0         0 }
  0         0  
  1         53  
  3         138  
  3         10  
30 5     5   161222  
  0         0  
  3         32  
31 0 100 66     0 if( $option{tailRecurse} || ! keys %imported ) {
  3         34  
  6         67  
  3         6  
32 0 50 50 3   0 keyword tailRecurse (Bareword $function, List? $parameters) {
  0         0  
  0         0  
  3         32  
  3         164713  
  3         7  
  3         10  
33 0         0 return "\@_ = ( $parameters ); goto &$function;";
  0         0  
  3         52  
  3         77  
  3         384  
34 0         0 };
  0         0  
  3         51  
  3         72  
35 5         40 $imported{tailRecurse} = 1;
  1         11  
  3         78  
36 0         0 }
  0         0  
  1         52  
  3         105  
  3         8  
37 5     5   159869  
  0         0  
  3         33  
38 0 100       0 if ( $option{subCallTail} ) {
  3         32  
  6         255  
  2         3  
39 0 50 50 3   0 keyword tail (Bareword $function, List? $parameters) {
  0         0  
  0         0  
  2         28  
  3         258315  
  3         9  
  3         9  
40 0         0 return "\@_ = ( $parameters ); goto &$function;";
  0         0  
  3         50  
  2         82  
  3         416  
41 0         0 };
  0         0  
  3         54  
  3         76  
42 5         40  
  3         30  
  2         59  
43 0 50 50 2   0 keyword tail (/\$[_a-zA-Z0-9]+\s*->\s*[_a-zA-Z0-9]+/ $methodCall, List? $parameters) {
  0         0  
  0         0  
  0         0  
  0         0  
  3         150  
  3         124  
  3         8  
  2         9  
  2         162968  
  2         5  
  2         7  
44 5     5   162825 my ($object, $method) = split /\s*->\s*/, $methodCall;
  0         0  
  0         0  
  3         41  
  2         55  
  2         233  
45 0         0  
  0         0  
  3         44  
  2         53  
46             return "\@_ = ( $object, $parameters ); goto( $object->can('$method') );";
47 0         0 };
  0         0  
  0         0  
  3         52  
  2         75  
  2         7  
48 0         0  
  0         0  
  3         56  
  2         6  
49 5         40 $imported{subCallTail} = 1;
  0         0  
  2         19  
  2         30  
  2         186  
50 2         91 }
51 5     5   154103 }
  0         0  
  2         45  
52 0         0  
  2         14  
53             sub unimport {
54 0 0   0   0 if( $imported{tailRecurse} ) {
  2         33  
  0            
  0            
  0            
55 5 0 0     39 unkeyword tailRecurse;
  2         15  
  0            
  0            
56 2         74 }
  0            
57 5 0   5   160557 if( $imported{tailrecurse} ) {
  5     5   137239  
  0            
  0            
  0            
58 5 0 0     351 unkeyword tailrecurse;
  0            
  0            
59 0           }
60 5 0   5   139275 if( $imported{tail_recurse} ) {
  0            
  0            
  0            
61 5 0 0     303 unkeyword tail_recurse;
  0            
  0            
62 0           }
63 5 0   5   135020 if( $imported{subCallTail} ) {
  0            
  0            
  0            
64 5 0 0     283 unkeyword tail;
  0            
  0            
65 0           }
66 5     5   134680 }
67 5         1020  
68              
69             1;
70             __END__