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   85732 use 5.008001;
  2         17  
3 2     2   21 use strict;
  2         4  
  2         42  
4 2     2   18 use warnings;
  2         5  
  2         79  
5              
6             our $VERSION = "0.03";
7              
8 2     2   11 use Exporter 'import';
  2         4  
  2         80  
9 2     2   11 use Carp;
  2         3  
  2         716  
10              
11             our @EXPORT_OK = qw( partiallyApply partiallyApplyRight partiallyApplyN );
12              
13             sub partiallyApply {
14 4     4 1 3179 my ( $sub, @params ) = @_;
15              
16 4 100       40 croak "first parameter needs to be a function ref" unless ref $sub eq "CODE";
17              
18             return sub {
19 4     4   10587 $sub->( @params, @_ );
20 2         10 };
21             }
22              
23             sub partiallyApplyRight {
24 3     3 1 2943 my ( $sub, @params ) = @_;
25              
26 3 100       26 croak "first parameter needs to be a function ref" unless ref $sub eq "CODE";
27              
28             return sub {
29 2     2   1362 $sub->( @_, @params );
30 1         6 };
31             }
32              
33             sub partiallyApplyN {
34 4     4 1 4084 my ( $sub, $bitmap, @partialParams ) = @_;
35              
36 4 100       29 croak "first parameter needs to be a function ref" unless ref $sub eq "CODE";
37              
38             return sub {
39 4     4   2790 my ( @callParams ) = @_;
40            
41 4         9 my @partial = @partialParams;
42              
43 4 100       8 my @params = map { $_ ? shift @partial : shift @callParams } @{ $bitmap };
  18         43  
  4         9  
44            
45 4         10 $sub->( @params, @partial, @callParams );
46             }
47 2         13 }
48              
49             1;
50             __END__