File Coverage

blib/lib/Repl/Core/Lambda.pm
Criterion Covered Total %
statement 26 26 100.0
branch 1 2 50.0
condition 1 3 33.3
subroutine 5 5 100.0
pod 0 3 0.0
total 33 39 84.6


line stmt bran cond sub pod time code
1             package Repl::Core::Lambda;
2            
3 1     1   22 use strict;
  1         1  
  1         38  
4 1     1   5 use warnings;
  1         2  
  1         261  
5            
6             # Parameters:
7             # - A parameter list (array of parameter names).
8             # - The body expression.
9             # - The lexical context.
10             sub new
11             {
12 4     4 0 8 my $invocant = shift;
13 4   33     16 my $class = ref($invocant) || $invocant;
14            
15 4         10 my $self= {};
16 4         9 $self->{PARAMS} = shift;
17 4         10 $self->{EXPR} = shift;
18 4         15 $self->{CTX} = shift;
19 4         20 return bless $self, $class;
20             }
21            
22             sub getExpr
23             {
24 25     25 0 28 my $self = shift;
25 25         85 return $self->{EXPR};
26             }
27            
28             sub createContext
29             {
30 25     25 0 28 my $self = shift;
31 25         51 my @args = (@_);
32 25         53 my $params = $self->{PARAMS};
33 25         38 my $lexicalctx = $self->{CTX};
34            
35 25 50       55 die "ERROR: Wrong number of arguments." if scalar(@args) != scalar(@$params);
36 25         79 my $callctx = new Repl::Core::BasicContext();
37 25         34 my $i = 0;
38 25         40 foreach my $param (@$params)
39             {
40 25         76 $callctx->defBinding($param, $args[$i]);
41 25         48 $i = $i + 1;
42             }
43 25         95 return new Repl::Core::CompositeContext($callctx, $lexicalctx);
44             }
45            
46             1;