lib/Lingy/Env.pm

filter: Statementstmt 98.2% 57 / 58 Branchbran 90.0% 36 / 40 Conditioncond 66.6% 6 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 4 totaltotal 87.8% 108 / 123 CC 25 SCAR 20.3
CC
25
Cov
93%
new
10.1
get_qualified
8.1
get
8.0
CRAP 7.6
« lib/Lingy/Main.pm ↑ Summary lib/Lingy/HashMap.pm »
1 53 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Lingy::Env;
3  
4 53 ▶use Lingy::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 100572 ▶sub new {
Subroutine new: called CC=10 SCAR=23.1
Pod undocumented
7 100572 my ($class, %args) = @_;
8 my $self = bless {
9 outer => $args{outer},
10 space => $args{space} // {},
11 100572 ▶ }, $class;
Condition50%1/2
$args{"space"} // {}
l!l
0100572
MC/DC0%0/1
$args{"space"} // {}
$args{"space"}
Truth table50%1/2
A
A= $args{"space"}
Aresult
11
00
12 100572 ▶ my $binds = [ @{$args{binds} // []} ];
Condition100%2/2
$args{"binds"} // []
l!l
99900672
MC/DC100%1/1
$args{"binds"} // []
$args{"binds"}
Truth table100%2/2
A
A= $args{"binds"}
Aresult
11
00
13 100572 ▶ my $exprs = $args{exprs} // [];
Condition100%2/2
$args{"exprs"} // []
l!l
99900672
MC/DC100%1/1
$args{"exprs"} // []
$args{"exprs"}
Truth table100%2/2
A
A= $args{"exprs"}
Aresult
11
00
14 100572 ▶ while (@$binds) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$binds) 177623 100572 278195
15 177623 ▶ if ("$binds->[0]" eq '&') {
Branch: 1 branch
BranchTrueFalseTotal
if ("$binds->[0]" eq "&") 24208 153415 177623
16 24208 shift @$binds;
17 24208 $exprs = [list([@$exprs])];
18 }
19 177623 ▶ $self->{space}{shift(@$binds)} = (shift(@$exprs) // nil);
Condition33%1/3
shift @$exprs // nil()
l!l&&r!l&&!r
17762300
MC/DC0%0/2
shift @$exprs // nil()
shift @$exprs nil()
Truth table33%1/3
A // B
A= shift @$exprsB= nil()
ABresult
1X1
011
000
20 }
21 100572 ▶ if (my $outer = $self->{outer}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $outer = $self->{"outer"}) 100518 54 100572
22 100518 ▶ $self->{LOOP} = $outer->{LOOP} if $outer->{LOOP};
Branch: 1 branch
BranchTrueFalseTotal
if $outer->{"LOOP"} 35 100483 100518
23 100518 ▶ $self->{RECUR} = $outer->{RECUR} if $outer->{RECUR};
Branch: 1 branch
BranchTrueFalseTotal
if $outer->{"RECUR"} 17 100501 100518
24 }
25 100572 return $self;
26 }
27  
28 1197 ▶sub set {
Subroutine set: called CC=2 SCAR=6.9
Pod undocumented
29 1197 my ($self, $symbol, $value) = @_;
30 1197 my $space = $self->{space};
31 1197 $space->{$symbol} = $value;
32 1197 ▶ return ref($space) eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
ref $space eq 'HASH' ? : 819 378 1197
33 ? $symbol
34 : symbol($space->_name . "/$symbol");
35 }
36  
37 649410 ▶sub get {
Subroutine get: called CC=8 SCAR=20.8
Pod undocumented
38 649410 my ($self, $symbol, $optional) = @_;
39  
40 # XXX Temporary hack until Vars
41 649410 ▶ if ("$symbol" eq '*ns*') {
Branch: 1 branch
BranchTrueFalseTotal
if ("$symbol" eq "*ns*") 22 649388 649410
42 22 return RT->current_ns;
43 }
44  
45 649388 ▶ return $self->get_qualified($symbol, $optional)
Branch: 1 branch
BranchTrueFalseTotal
if $symbol =~ m[./.] 49701 599687 649388
46 if $symbol =~ m{./.};
47  
48 599687 ▶ while ($self) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self) 971251 106513 1077764
49 971251 my $space = $self->{space};
50 971251 ▶ if (defined(my $value = $space->{$symbol})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $value = $space->{$symbol})) 493174 478077 971251
51 493174 return $value;
52 }
53 478077 $self = $self->{outer};
54 }
55  
56 106513 ▶ if (my $class = RT->current_ns->{"$symbol"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = RT()->current_ns->{"$symbol"}) 0 106513 106513
57 0 return $class;
58 }
59  
60 106513 ▶ return if $optional;
Branch: 1 branch
BranchTrueFalseTotal
if $optional 106503 10 106513
61  
62 10 ▶ err "Class not found: '$symbol'"
Branch: 1 branch
BranchTrueFalseTotal
if $symbol =~ /\w\.\w/ 1 9 10
63 if $symbol =~ /\w\.\w/;
64  
65 9 err "Unable to resolve symbol: '$symbol' in this context";
66 }
67  
68 49701 ▶sub get_qualified {
Subroutine get_qualified: called CC=8 SCAR=20.9
Pod undocumented
69 49701 my ($self, $symbol, $optional) = @_;
70  
71 49701 ▶ $symbol =~ m{^(.*)/(.*)$} or die;
Branch: 1 branch
BranchTrueFalseTotal
$symbol =~ m[^(.*)/(.*)$] or die 49701 0 49701
72 49701 my $space_name = $1;
73 49701 my $symbol_name = $2;
74  
75 49701 ▶ if (my $ns = RT->core_ns) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ns = RT()->core_ns) 43447 6254 49701
76 43447 ▶ if (my $class = RT->core_ns->{$space_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = RT()->core_ns->{$space_name}) 43428 19 43447
77 43428 return \&{"${class}::$symbol_name"};
78 }
79 }
80 6273 ▶ if (my $class = RT->current_ns->{$space_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = RT()->current_ns->{$space_name}) 6254 19 6273
81 6254 return \&{"${class}::$symbol_name"};
82 }
83  
84 19 ▶ my $ns = RT->namespaces->{$space_name}
Branch: 1 branch
BranchTrueFalseTotal
my $ns = RT()->namespaces->{$space_name} or err("No such namespace: '${space_name}'") 19 0 19
85 or err "No such namespace: '$space_name'";
86  
87 19 ▶ if (defined(my $value = $ns->{$symbol_name})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $value = $ns->{$symbol_name})) 18 1 19
88 18 return $value;
89 }
90  
91 1 ▶ return if $optional;
Branch: 1 branch
BranchTrueFalseTotal
if $optional 0 1 1
92  
93 1 err "Unable to resolve symbol: '$symbol' in this context";
94 }
95  
96 53 1;
« lib/Lingy/Main.pm ↑ Summary lib/Lingy/HashMap.pm »