File Coverage

blib/lib/Repl/Core/CompositeContext.pm
Criterion Covered Total %
statement 25 31 80.6
branch 3 8 37.5
condition 3 6 50.0
subroutine 7 9 77.7
pod 0 7 0.0
total 38 61 62.3


line stmt bran cond sub pod time code
1             package Repl::Core::CompositeContext;
2            
3 1     1   5 use strict;
  1         2  
  1         29  
4 1     1   4 use warnings;
  1         2  
  1         380  
5            
6             sub new
7             {
8 32     32 0 63 my ($invocant, $main, $backing) = @_;
9 32   33     114 my $class = ref($invocant) || $invocant;
10            
11             # Initialize the token instance.
12 32         43 my $self = {};
13 32         69 $self->{MAIN} = $main;
14 32         68 $self->{BACKING} = $backing;
15 32         157 return bless($self, $class);
16             }
17            
18             sub getBinding
19             {
20 116     116 0 200 my ($self, $name) = @_;
21 116 100       286 return $self->{MAIN}->getBinding($name) if($self->{MAIN}->isBound($name));
22 42         139 return $self->{BACKING}->getBinding($name);
23             }
24            
25             sub setBinding
26             {
27 2     2 0 4 my ($self, $name, $value) = @_;
28 2         6 my $main = $self->{MAIN};
29 2         4 my $backing = $self->{BACKING};
30            
31 2 50       8 if($main->isBound($name))
    0          
32             {
33 2         9 $main->setBinding($name, $value);
34             }
35             elsif($backing->isBound($name))
36             {
37 0         0 $backing->setBinding($name, $value);
38             }
39             else
40             {
41 0         0 die sprintf("ERROR: There is no binding for '%s' in the context.", $name);
42             }
43             }
44            
45             sub defBinding
46             {
47 16     16 0 29 my ($self, $name, $value) = @_;
48 16         30 my $main = $self->{MAIN};
49 16         46 $main->defBinding($name, $value);
50             }
51            
52             sub isBound
53             {
54 22     22 0 28 my ($self, $name) = @_;
55 22   66     60 return $self->{MAIN}->isBound($name) || $self->{BACKING}->isBound($name);
56             }
57            
58             sub removeBinding
59             {
60 0     0 0   my ($self, $name) = @_;
61 0 0         $self->{MAIN}->removeBinding($name) if($self->{MAIN}->isBound($name));
62             }
63            
64             sub getRootContext
65             {
66 0     0 0   my $self = shift;
67 0           return $self->{BACKING}->getRootContext();
68             }
69            
70             1;