line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JE::Object::Boolean; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.065'; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
101
|
|
|
101
|
|
36748
|
use strict; |
|
101
|
|
|
|
|
134
|
|
|
101
|
|
|
|
|
3918
|
|
7
|
101
|
|
|
101
|
|
411
|
use warnings; |
|
101
|
|
|
|
|
115
|
|
|
101
|
|
|
|
|
3808
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = 'JE::Object'; |
10
|
|
|
|
|
|
|
|
11
|
101
|
|
|
101
|
|
1505
|
use Scalar::Util 'blessed'; |
|
101
|
|
|
|
|
118
|
|
|
101
|
|
|
|
|
48737
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
require JE::Code; |
14
|
|
|
|
|
|
|
require JE::Boolean; |
15
|
|
|
|
|
|
|
require JE::Object::Error::TypeError; |
16
|
|
|
|
|
|
|
require JE::Object::Function; |
17
|
|
|
|
|
|
|
require JE::String; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
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 boolean values, while this module implements the I |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 METHODS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
See L 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
|
|
|
|
|
|
|
sub new { |
54
|
26
|
|
|
26
|
1
|
526
|
my($class, $global, $val) = @_; |
55
|
26
|
|
33
|
|
|
106
|
my $self = $class->SUPER::new($global, { |
56
|
|
|
|
|
|
|
prototype => $global->prototype_for('Boolean') |
57
|
|
|
|
|
|
|
|| $global->prop('Boolean')->prop('prototype') |
58
|
|
|
|
|
|
|
}); |
59
|
|
|
|
|
|
|
|
60
|
26
|
100
|
66
|
|
|
256
|
$$$self{value} = defined $val |
|
|
100
|
|
|
|
|
|
61
|
|
|
|
|
|
|
? defined blessed $val |
62
|
|
|
|
|
|
|
&& $val->can('to_boolean') |
63
|
|
|
|
|
|
|
? $val->to_boolean->[0] |
64
|
|
|
|
|
|
|
: !!$val |
65
|
|
|
|
|
|
|
: !1; |
66
|
26
|
|
|
|
|
153
|
$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
|
|
|
16
|
1
|
240
|
sub value { $${$_[0]}{value} } |
|
16
|
|
|
|
|
76
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
38
|
|
|
38
|
1
|
103
|
sub class { 'Boolean' } |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _new_constructor { |
83
|
9
|
|
|
9
|
|
20
|
my $global = shift; |
84
|
|
|
|
|
|
|
my $f = JE::Object::Function->new({ |
85
|
|
|
|
|
|
|
name => 'Boolean', |
86
|
|
|
|
|
|
|
scope => $global, |
87
|
|
|
|
|
|
|
argnames => [qw/value/], |
88
|
|
|
|
|
|
|
function => sub { |
89
|
8
|
100
|
|
8
|
|
44
|
defined $_[0] ? $_[0]->to_boolean : |
90
|
|
|
|
|
|
|
JE::Boolean->new($global, 0); |
91
|
|
|
|
|
|
|
}, |
92
|
|
|
|
|
|
|
function_args => ['args'], |
93
|
|
|
|
|
|
|
constructor => sub { |
94
|
15
|
|
|
15
|
|
34
|
unshift @_, __PACKAGE__; |
95
|
15
|
|
|
|
|
37
|
goto &new; |
96
|
|
|
|
|
|
|
}, |
97
|
9
|
|
|
|
|
173
|
constructor_args => ['scope','args'], |
98
|
|
|
|
|
|
|
}); |
99
|
|
|
|
|
|
|
|
100
|
9
|
|
|
|
|
63
|
my $proto = bless $f->prop({ |
101
|
|
|
|
|
|
|
name => 'prototype', |
102
|
|
|
|
|
|
|
dontenum => 1, |
103
|
|
|
|
|
|
|
readonly => 1, |
104
|
|
|
|
|
|
|
}), __PACKAGE__; |
105
|
9
|
|
|
|
|
36
|
$global->prototype_for('Boolean',$proto); |
106
|
|
|
|
|
|
|
|
107
|
9
|
|
|
|
|
479
|
$$$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
|
|
|
|
|
|
|
function => sub { |
117
|
17
|
|
|
17
|
|
21
|
my $self = shift; |
118
|
17
|
100
|
|
|
|
43
|
die JE::Object::Error::TypeError->new( |
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
|
|
|
|
|
35
|
return JE::String->_new($global, |
127
|
|
|
|
|
|
|
qw/false true/[$self->value]); |
128
|
|
|
|
|
|
|
}, |
129
|
9
|
|
|
|
|
110
|
}), |
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
|
|
|
|
|
|
|
function => sub { |
141
|
26
|
|
|
26
|
|
33
|
my $self = shift; |
142
|
26
|
100
|
|
|
|
55
|
die JE::Object::Error::TypeError->new( |
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
|
23
|
|
|
|
|
85
|
return JE::Boolean->new($global, |
151
|
|
|
|
|
|
|
$$$self{value}); |
152
|
|
|
|
|
|
|
}, |
153
|
9
|
|
|
|
|
112
|
}), |
154
|
|
|
|
|
|
|
dontenum => 1, |
155
|
|
|
|
|
|
|
}); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
158
|
9
|
|
|
|
|
89
|
$f; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|