blib/lib/Language/Farnsworth/Variables.pm

filter: Statementstmt 69.8% 44 / 63 Branchbran 54.1% 13 / 24 Conditioncond 33.3% 3 / 9 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 83.3% 10 / 12 Podpod 0.0% 0 / 7 totaltotal 59.5% 72 / 121 CC 16 SCAR 21.7
CC
16
Cov
62%
setvar
30.0
getref
12.0
getvar
5.0
CRAP 8.8
« blib/lib/Language/Farnsworth/FunctionDispatch.pm ↑ Summary blib/lib/Language/Farnsworth/Value.pm »
1 package Language::Farnsworth::Variables;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Language::Farnsworth::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 #this is very simple right now but i'll need to make a way to inherit
11 #variables from an old Language::Farnsworth::Variables class so that i can do
12 #functions with "scoping"
13  
14 sub new
15 314 ▶{
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
16 314 my $class = shift;
17 314 my $state = shift;
18 314 my $self = {parent => undef, vars => {}};
19 314 ▶ $self->{parent} = $state if (ref($state) eq "Language::Farnsworth::Variables");
Branch: 1 branch
BranchTrueFalseTotal
if ref $state eq "Language::Farnsworth::Variables" 310 4 314
20 314 bless $self;
21 }
22  
23 sub DESTROY
24 181 ▶{
Subroutine DESTROY: called CC=1 SCAR=0.0
25 181 debug 2,"VARIABLES DIE: $_[0]";
26 }
27  
28 sub setvar
29 0 ▶{
Subroutine setvar: not called CC=5 SCAR=34.0
Pod undocumented
30 0 my $self = shift;
31 0 my $name = shift;
32 0 my $value = shift;
33  
34 0 ▶ if ((exists($self->{vars}{$name})) || !defined($self->{parent}))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'vars'}{$name} or not defined $self->{'parent'}) { } 0 0 0
Condition0%0/3
exists $self->{"vars"}{$name} or not defined $self->{"parent"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $self->{"vars"}{$name} or not defined $self->{"parent"}
exists $self->{"vars"}{$name} not defined $self->{"parent"}
Truth table0%0/3
A or not(B)
A= exists $self->{"vars"}{$name}B= not defined $self->{"parent"}
ABresult
1X1
011
000
35 {
36 0 ▶ if (exists($self->{vars}{$name}) && ref($self->{vars}{$name}) eq "REF")
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'vars'}{$name} and ref $self->{'vars'}{$name} eq 'REF') { } 0 0 0
Condition0%0/3
exists $self->{"vars"}{$name} and ref $self->{"vars"}{$name} eq "REF"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"vars"}{$name} and ref $self->{"vars"}{$name} eq "REF"
exists $self->{"vars"}{$name} ref $self->{"vars"}{$name} eq "REF"
Truth table0%0/3
A and B
A= exists $self->{"vars"}{$name}B= ref $self->{"vars"}{$name} eq "REF"
ABresult
0X0
100
111
37 {
38 #we've got a reference
39 0 ${$self->{vars}{$name}} = $value;
40 }
41 else
42 {
43 0 $self->{vars}{$name} = $value;
44 }
45 }
46 else
47 {
48 0 $self->{parent}->setvar($name, $value); #set it in the previous scope
49 }
50 }
51  
52 sub declare
53 260 ▶{
Subroutine declare: called CC=2 SCAR=7.2
Pod undocumented
54 260 my $self = shift;
55 260 my $name = shift;
56 260 my $value = shift;
57  
58 260 ▶ if (!defined($name))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 0 260 260
59 {
60 0 error "NAME UNDEFINED!\n".Dumper([$self, $name, $value, @_]);
61 }
62  
63 #really all we need to do is just set it in this scope to see it
64 260 $self->{vars}{$name} = $value;
65 }
66  
67 sub setref
68 24 ▶{
Subroutine setref: called CC=2 SCAR=7.4
Pod undocumented
69 24 my $self = shift;
70 24 my $name = shift;
71  
72 24 ▶ if (!defined($name))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 0 24 24
73 {
74 0 error "NAME UNDEFINED!\n".Dumper([$self, $name, @_]);
75 }
76  
77 #really all we need to do is just set it in this scope to see it
78 24 $self->{vars}{$name} = $_[0]; #can't set things myself with shift, HAVE to use @_ directly
79 }
80  
81 sub getref
82 0 ▶{
Subroutine getref: not called CC=3 SCAR=24.8
Pod undocumented
83 0 my $self = shift;
84 0 my $name = shift;
85 0 my $val;
86  
87 0 error "DEPRECIATED CALL TO Variables->getref()";
88  
89 0 ▶ if (exists($self->{vars}{$name}))
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'vars'}{$name}) { } 0 0 0
elsif (defined $self->{'parent'}) { } 0 0 0
90 {
91 0 $val = \$self->{vars}{$name};
92 }
93 elsif (defined($self->{parent}))
94 {
95 0 $val = $self->{parent}->getref($name);
96 }
97  
98 0 return $val;
99 }
100  
101 sub getvar
102 456 ▶{
Subroutine getvar: called CC=5 SCAR=16.1
Pod undocumented
103 456 my $self = shift;
104 456 my $name = shift;
105 456 my $val;
106  
107 456 ▶ if (exists($self->{vars}{$name}))
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'vars'}{$name}) { } 454 2 456
elsif (defined $self->{'parent'}) { } 2 0 2
108 {
109 454 $val = $self->{vars}{$name};
110 454 ▶ $val->setref(\$self->{vars}{$name}) unless (ref($val) eq "REF");
Branch: 1 branch
BranchTrueFalseTotal
unless ref $val eq "REF" 418 36 454
111 #$val->sethomescope($self);
112 }
113 elsif (defined($self->{parent}))
114 {
115 2 $val = $self->{parent}->getvar($name);
116 }
117  
118 456 ▶ if (ref $val eq "REF")
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val eq "REF") 36 420 456
119 { #we've got one set by reference
120 36 $val = $$val; #deref it for getting its value
121 }
122  
123 456 return $val;
124 }
125  
126 sub isvar
127 11958 ▶{
Subroutine isvar: called CC=3 SCAR=11.0
Pod undocumented
128 11958 my $self = shift;
129 11958 my $name = shift;
130  
131 11958 my $r = exists($self->{vars}{$name});
132  
133 11958 ▶ if (!exists($self->{vars}{$name}) && defined($self->{parent}))
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $self->{"vars"}{$name} and defined $self->{"parent"}) 8 11950 11958
Condition100%3/3
not exists $self->{"vars"}{$name} and defined $self->{"parent"}
!ll&&!rl&&r
416115348
MC/DC100%2/2
not exists $self->{"vars"}{$name} and defined $self->{"parent"}
not exists $self->{"vars"}{$name} defined $self->{"parent"}
Truth table100%3/3
not(A) and B
A= not exists $self->{"vars"}{$name}B= defined $self->{"parent"}
ABresult
0X0
100
111
134 {
135 8 $r = $self->{parent}->isvar($name);
136 }
137  
138 11958 return $r;
139 }
140 4 1;
« blib/lib/Language/Farnsworth/FunctionDispatch.pm ↑ Summary blib/lib/Language/Farnsworth/Value.pm »