File Coverage

blib/lib/PartialApplication.pm
Criterion Covered Total %
statement 31 31 100.0
branch 8 8 100.0
condition n/a
subroutine 11 11 100.0
pod 3 3 100.0
total 53 53 100.0


line stmt bran cond sub pod time code
1             package PartialApplication;
2 2     2   75870 use 5.008001;
  2         17  
3 2     2   10 use strict;
  2         3  
  2         36  
4 2     2   9 use warnings;
  2         3  
  2         78  
5              
6             our $VERSION = "0.04";
7              
8 2     2   10 use Exporter 'import';
  2         10  
  2         71  
9 2     2   9 use Carp;
  2         4  
  2         706  
10              
11             our @EXPORT_OK = qw( partiallyApply partiallyApplyRight partiallyApplyN );
12              
13             sub partiallyApply {
14 4     4 1 2725 my ( $sub, @params ) = @_;
15              
16 4 100       35 croak "first parameter needs to be a function ref" unless ref $sub eq "CODE";
17              
18             return sub {
19 4     4   9115 $sub->( @params, @_ );
20 2         23 };
21             }
22              
23             sub partiallyApplyRight {
24 3     3 1 2309 my ( $sub, @params ) = @_;
25              
26 3 100       23 croak "first parameter needs to be a function ref" unless ref $sub eq "CODE";
27              
28             return sub {
29 2     2   1082 $sub->( @_, @params );
30 1         6 };
31             }
32              
33             sub partiallyApplyN {
34 4     4 1 3327 my ( $sub, $bitmap, @partialParams ) = @_;
35              
36 4 100       25 croak "first parameter needs to be a function ref" unless ref $sub eq "CODE";
37              
38             return sub {
39 4     4   2365 my ( @callParams ) = @_;
40            
41 4         7 my @partial = @partialParams;
42              
43 4 100       7 my @params = map { $_ ? shift @partial : shift @callParams } @{ $bitmap };
  18         35  
  4         7  
44            
45 4         9 $sub->( @params, @partial, @callParams );
46             }
47 2         11 }
48              
49             1;
50             __END__