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/Util.pm ↑ Summary lib/Lingy/Main.pm »
1 57 ▶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 57 ▶use Lingy::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 sub new {
7 102094 ▶ my ($class, %args) = @_;
Subroutine new: called CC=10 SCAR=23.1
Pod undocumented
8 my $self = bless {
9 outer => $args{outer},
10 space => $args{space} // {},
11 102094 ▶ }, $class;
Condition50%1/2
$args{"space"} // {}
l!l
0102094
MC/DC0%0/1
$args{"space"} // {}
$args{"space"}
Truth table50%1/2
A
A= $args{"space"}
Aresult
11
00
12 102094 ▶ my $binds = [ @{$args{binds} // []} ];
Condition100%2/2
$args{"binds"} // []
l!l
101418676
MC/DC100%1/1
$args{"binds"} // []
$args{"binds"}
Truth table100%2/2
A
A= $args{"binds"}
Aresult
11
00
13 102094 ▶ my $exprs = $args{exprs} // [];
Condition100%2/2
$args{"exprs"} // []
l!l
101418676
MC/DC100%1/1
$args{"exprs"} // []
$args{"exprs"}
Truth table100%2/2
A
A= $args{"exprs"}
Aresult
11
00
14 102094 ▶ while (@$binds) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$binds) 180146 102094 282240
15 180146 ▶ if ("$binds->[0]" eq '&') {
Branch: 1 branch
BranchTrueFalseTotal
if ("$binds->[0]" eq "&") 25722 154424 180146
16 25722 shift @$binds;
17 25722 $exprs = [list([@$exprs])];
18 }
19 180146 ▶ $self->{space}{shift(@$binds)} = (shift(@$exprs) // nil);
Condition33%1/3
shift @$exprs // nil()
l!l&&r!l&&!r
18014600
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 102094 ▶ if (my $outer = $self->{outer}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $outer = $self->{"outer"}) 102036 58 102094
22 102036 ▶ $self->{LOOP} = $outer->{LOOP} if $outer->{LOOP};
Branch: 1 branch
BranchTrueFalseTotal
if $outer->{"LOOP"} 35 102001 102036
23 102036 ▶ $self->{RECUR} = $outer->{RECUR} if $outer->{RECUR};
Branch: 1 branch
BranchTrueFalseTotal
if $outer->{"RECUR"} 17 102019 102036
24 }
25 102094 return $self;
26 }
27  
28 sub set {
29 1225 ▶ my ($self, $symbol, $value) = @_;
Subroutine set: called CC=2 SCAR=6.9
Pod undocumented
30 1225 my $space = $self->{space};
31 1225 $space->{$symbol} = $value;
32 1225 ▶ return ref($space) eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
ref $space eq 'HASH' ? : 819 406 1225
33 ? $symbol
34 : symbol($space->_name . "/$symbol");
35 }
36  
37 sub get {
38 662608 ▶ my ($self, $symbol, $optional) = @_;
Subroutine get: called CC=8 SCAR=20.8
Pod undocumented
39  
40 # XXX Temporary hack until Vars
41 662608 ▶ if ("$symbol" eq '*ns*') {
Branch: 1 branch
BranchTrueFalseTotal
if ("$symbol" eq "*ns*") 22 662586 662608
42 22 return RT->current_ns;
43 }
44  
45 662586 ▶ return $self->get_qualified($symbol, $optional)
Branch: 1 branch
BranchTrueFalseTotal
if $symbol =~ m[./.] 50176 612410 662586
46 if $symbol =~ m{./.};
47  
48 612410 ▶ while ($self) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self) 992429 109790 1102219
49 992429 my $space = $self->{space};
50 992429 ▶ if (defined(my $value = $space->{$symbol})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $value = $space->{$symbol})) 502620 489809 992429
51 502620 return $value;
52 }
53 489809 $self = $self->{outer};
54 }
55  
56 109790 ▶ if (my $class = RT->current_ns->{"$symbol"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = RT()->current_ns->{"$symbol"}) 0 109790 109790
57 0 return $class;
58 }
59  
60 109790 ▶ return if $optional;
Branch: 1 branch
BranchTrueFalseTotal
if $optional 109780 10 109790
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 sub get_qualified {
69 50176 ▶ my ($self, $symbol, $optional) = @_;
Subroutine get_qualified: called CC=8 SCAR=20.9
Pod undocumented
70  
71 50176 ▶ $symbol =~ m{^(.*)/(.*)$} or die;
Branch: 1 branch
BranchTrueFalseTotal
$symbol =~ m[^(.*)/(.*)$] or die 0 50176 50176
72 50176 my $space_name = $1;
73 50176 my $symbol_name = $2;
74  
75 50176 ▶ if (my $ns = RT->core_ns) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ns = RT()->core_ns) 43450 6726 50176
76 43450 ▶ if (my $class = RT->core_ns->{$space_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = RT()->core_ns->{$space_name}) 43431 19 43450
77 43431 return \&{"${class}::$symbol_name"};
78 }
79 }
80 6745 ▶ if (my $class = RT->current_ns->{$space_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = RT()->current_ns->{$space_name}) 6726 19 6745
81 6726 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}'") 0 19 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 57 1;
« lib/Lingy/Util.pm ↑ Summary lib/Lingy/Main.pm »