JE/Object/Boolean.pm

filter: Statementstmt 100% 42 / 42 Branchbran 100% 10 / 10 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 11 / 11 Podpod 100% 3 / 3 totaltotal 92.1% 70 / 76 CC 8 SCAR 9.2
CC
8
Cov
95%
new
5.2
__ANON__
2.0
__ANON__
2.0
CRAP 2.5
« JE/Number.pm ↑ Summary JE/Object/Error.pm »
1 package JE::Object::Boolean;
2  
3 101 our $VERSION = '0.066';
4  
5  
6 101 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 101 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 101 our @ISA = 'JE::Object';
10  
11 101 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 101 require JE::Code;
14 101 require JE::Boolean;
15 101 require JE::Object::Error::TypeError;
16 101 require JE::Object::Function;
17 101 require JE::String;
18  
19 101 import JE::Code 'add_line_number';
20 sub add_line_number;
21  
22 =head1 NAME
23  
24 JE::Object::Boolean - JavaScript Boolean object class
25  
26 =head1 SYNOPSIS
27  
28 use JE;
29  
30 $j = new JE;
31  
32 $js_bool_obj = new JE::Object::Boolean $j, 1;
33  
34 $perl_bool = $js_bool_obj->value;
35  
36 "$js_bool_obj"; # true
37  
38 =head1 DESCRIPTION
39  
40 This class implements JavaScript Boolean objects for JE. The difference
41 between this and JE::Boolean is that that module implements
42 I<primitive> boolean values, while this module implements the I<objects.>
43  
44 =head1 METHODS
45  
46 See L<JE::Types> for descriptions of most of the methods. Only what
47 is specific to JE::Object::Boolean is explained here.
48  
49 =over
50  
51 =cut
52  
53 26 ▶sub new {
Subroutine new: called CC=5 SCAR=16.6
Pod documented
54 26 my($class, $global, $val) = @_;
55 26 ▶ my $self = $class->SUPER::new($global, {
Condition33%1/3
$global->prototype_for('Boolean') || $global->prop('Boolean')->prop('prototype')
l!l&&r!l&&!r
2600
MC/DC0%0/2
$global->prototype_for('Boolean') || $global->prop('Boolean')->prop('prototype')
$global->prototype_for('Boolean') $global->prop('Boolean')->prop('prototype')
Truth table33%1/3
A || B
A= $global->prototype_for('Boolean')B= $global->prop('Boolean')->prop('prototype')
ABresult
1X1
011
000
56 prototype => $global->prototype_for('Boolean')
57 || $global->prop('Boolean')->prop('prototype')
58 });
59  
60 26 ▶ $$$self{value} = defined $val
Branch: 2 branches
BranchTrueFalseTotal
defined $val ? : 21 5 26
defined builtin::blessed($val) && $val->can('to_boolean') ? : 19 2 21
Condition66%2/3
defined builtin::blessed($val) and $val->can("to_boolean")
!ll&&!rl&&r
2019
MC/DC50%1/2
defined builtin::blessed($val) and $val->can("to_boolean")
defined builtin::blessed($val) $val->can("to_boolean")
Truth table66%2/3
A and B
A= defined builtin::blessed($val)B= $val->can("to_boolean")
ABresult
0X0
100
111
61 ? defined blessed $val
62 && $val->can('to_boolean')
63 ? $val->to_boolean->[0]
64 : !!$val
65 : !1;
66 26 $self;
67 }
68  
69  
70 =item value
71  
72 Returns a Perl scalar, either 1 or the empty string (well, actually !1).
73  
74 =cut
75  
76 16 ▶sub value { $${$_[0]}{value} }
Subroutine value: called CC=1 SCAR=0.0
Pod documented
77  
78  
79 38 ▶sub class { 'Boolean' }
Subroutine class: called CC=1 SCAR=0.0
Pod documented
80  
81  
82 9 ▶sub _new_constructor {
Subroutine _new_constructor: called CC=1 SCAR=0.0
83 9 my $global = shift;
84 my $f = JE::Object::Function->new({
85 name => 'Boolean',
86 scope => $global,
87 argnames => [qw/value/],
88 8 ▶ function => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
89 8 ▶ defined $_[0] ? $_[0]->to_boolean :
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 7 1 8
90 JE::Boolean->new($global, 0);
91 },
92 function_args => ['args'],
93 15 ▶ constructor => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
94 15 unshift @_, __PACKAGE__;
95 15 goto &new;
96 },
97 9 constructor_args => ['scope','args'],
98 });
99  
100 9 my $proto = bless $f->prop({
101 name => 'prototype',
102 dontenum => 1,
103 readonly => 1,
104 }), __PACKAGE__;
105 9 $global->prototype_for('Boolean',$proto);
106  
107 9 $$$proto{value} = !1;
108
109 $proto->prop({
110 name => 'toString',
111 value => JE::Object::Function->new({
112 scope => $global,
113 name => 'valueOf',
114 no_proto => 1,
115 function_args => ['this'],
116 17 ▶ function => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
117 17 my $self = shift;
118 17 ▶ die JE::Object::Error::TypeError->new(
Branch: 1 branch
BranchTrueFalseTotal
unless $self->class eq "Boolean" 3 14 17
119 $global, add_line_number
120 "Argument to " .
121 "Boolean.prototype.toString is not"
122 . " a " .
123 "Boolean object"
124 ) unless $self->class eq 'Boolean';
125  
126 14 return JE::String->_new($global,
127 qw/false true/[$self->value]);
128 },
129 9 }),
130 dontenum => 1,
131 });
132  
133 $proto->prop({
134 name => 'valueOf',
135 value => JE::Object::Function->new({
136 scope => $global,
137 name => 'valueOf',
138 no_proto => 1,
139 function_args => ['this'],
140 26 ▶ function => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
141 26 my $self = shift;
142 26 ▶ die JE::Object::Error::TypeError->new(
Branch: 1 branch
BranchTrueFalseTotal
unless $self->class eq "Boolean" 3 23 26
143 $global, add_line_number
144 "Argument to " .
145 "Boolean.prototype.valueOf is not"
146 . " a " .
147 "Boolean object"
148 ) unless $self->class eq 'Boolean';
149  
150 return JE::Boolean->new($global,
151 23 $$$self{value});
152 },
153 9 }),
154 dontenum => 1,
155 });
156  
157  
158 9 $f;
159 }
160  
161 101 return "a true value";
162  
163 =back
164  
165 =head1 SEE ALSO
166  
167 =over 4
168  
169 =item JE
170  
171 =item JE::Types
172  
173 =item JE::Object
174  
175 =item JE::Boolean
176  
177 =back
178  
179 =cut
180  
181  
182  
183  
« JE/Number.pm ↑ Summary JE/Object/Error.pm »