/usr/share/perl5/JE/Object/Boolean.pm is in libje-perl 0.066-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | package JE::Object::Boolean;
our $VERSION = '0.066';
use strict;
use warnings;
our @ISA = 'JE::Object';
use Scalar::Util 'blessed';
require JE::Code;
require JE::Boolean;
require JE::Object::Error::TypeError;
require JE::Object::Function;
require JE::String;
import JE::Code 'add_line_number';
sub add_line_number;
=head1 NAME
JE::Object::Boolean - JavaScript Boolean object class
=head1 SYNOPSIS
use JE;
$j = new JE;
$js_bool_obj = new JE::Object::Boolean $j, 1;
$perl_bool = $js_bool_obj->value;
"$js_bool_obj"; # true
=head1 DESCRIPTION
This class implements JavaScript Boolean objects for JE. The difference
between this and JE::Boolean is that that module implements
I<primitive> boolean values, while this module implements the I<objects.>
=head1 METHODS
See L<JE::Types> for descriptions of most of the methods. Only what
is specific to JE::Object::Boolean is explained here.
=over
=cut
sub new {
my($class, $global, $val) = @_;
my $self = $class->SUPER::new($global, {
prototype => $global->prototype_for('Boolean')
|| $global->prop('Boolean')->prop('prototype')
});
$$$self{value} = defined $val
? defined blessed $val
&& $val->can('to_boolean')
? $val->to_boolean->[0]
: !!$val
: !1;
$self;
}
=item value
Returns a Perl scalar, either 1 or the empty string (well, actually !1).
=cut
sub value { $${$_[0]}{value} }
sub class { 'Boolean' }
sub _new_constructor {
my $global = shift;
my $f = JE::Object::Function->new({
name => 'Boolean',
scope => $global,
argnames => [qw/value/],
function => sub {
defined $_[0] ? $_[0]->to_boolean :
JE::Boolean->new($global, 0);
},
function_args => ['args'],
constructor => sub {
unshift @_, __PACKAGE__;
goto &new;
},
constructor_args => ['scope','args'],
});
my $proto = bless $f->prop({
name => 'prototype',
dontenum => 1,
readonly => 1,
}), __PACKAGE__;
$global->prototype_for('Boolean',$proto);
$$$proto{value} = !1;
$proto->prop({
name => 'toString',
value => JE::Object::Function->new({
scope => $global,
name => 'valueOf',
no_proto => 1,
function_args => ['this'],
function => sub {
my $self = shift;
die JE::Object::Error::TypeError->new(
$global, add_line_number
"Argument to " .
"Boolean.prototype.toString is not"
. " a " .
"Boolean object"
) unless $self->class eq 'Boolean';
return JE::String->_new($global,
qw/false true/[$self->value]);
},
}),
dontenum => 1,
});
$proto->prop({
name => 'valueOf',
value => JE::Object::Function->new({
scope => $global,
name => 'valueOf',
no_proto => 1,
function_args => ['this'],
function => sub {
my $self = shift;
die JE::Object::Error::TypeError->new(
$global, add_line_number
"Argument to " .
"Boolean.prototype.valueOf is not"
. " a " .
"Boolean object"
) unless $self->class eq 'Boolean';
return JE::Boolean->new($global,
$$$self{value});
},
}),
dontenum => 1,
});
$f;
}
return "a true value";
=back
=head1 SEE ALSO
=over 4
=item JE
=item JE::Types
=item JE::Object
=item JE::Boolean
=back
=cut
|