File Coverage

blib/lib/Repl/Core/BasicContext.pm
Criterion Covered Total %
statement 23 25 92.0
branch 2 2 100.0
condition 1 3 33.3
subroutine 8 9 88.8
pod 0 7 0.0
total 34 46 73.9


line stmt bran cond sub pod time code
1             package Repl::Core::BasicContext;
2            
3 1     1   5 use strict;
  1         2  
  1         29  
4 1     1   4 use warnings;
  1         2  
  1         297  
5            
6             sub new
7             {
8 33     33 0 46 my $invocant = shift;
9 33   33     127 my $class = ref($invocant) || $invocant;
10             # Initialize the token instance.
11 33         51 my $self = {};
12 33         74 $self->{CTX} = {};
13 33         171 return bless($self, $class);
14             }
15            
16             sub getBinding
17             {
18 145     145 0 222 my ($self, $name) = @_;
19 145         541 return $self->{CTX}->{$name};
20             }
21            
22             sub setBinding
23             {
24 14     14 0 21 my ($self, $name, $value) = @_;
25 14 100       31 if(exists $self->{CTX}->{$name})
26             {
27 13         35 $self->{CTX}->{$name} = $value
28             }
29             else
30             {
31 1         19 die sprintf("ERROR: There is no binding for '%s' in the context.", $name);
32             }
33             }
34            
35             sub defBinding
36             {
37 53     53 0 92 my ($self, $name, $value) = @_;
38 53         222 $self->{CTX}->{$name} = $value;
39             }
40            
41             sub isBound
42             {
43 164     164 0 201 my ($self, $name) = @_;
44 164         843 return exists $self->{CTX}->{$name};
45             }
46            
47             sub removeBinding
48             {
49 0     0 0 0 my ($self, $name) = @_;
50 0         0 delete $self->{CTX}->{$name};
51             }
52            
53             sub getRootContext
54             {
55 12     12 0 21 my $self = shift;
56 12         40 return $self;
57             }
58            
59             1;