File Coverage

lib/HTML/Object/DOM/Boolean.pm
Criterion Covered Total %
statement 19 28 67.8
branch 0 8 0.0
condition n/a
subroutine 7 10 70.0
pod 3 3 100.0
total 29 49 59.1


line stmt bran cond sub pod time code
1             ##----------------------------------------------------------------------------
2             ## HTML Object - ~/lib/HTML/Object/DOM/Boolean.pm
3             ## Version v0.2.0
4             ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5             ## Author: Jacques Deguest <jack@deguest.jp>
6             ## Created 2021/12/13
7             ## Modified 2022/09/18
8             ## All rights reserved
9             ##
10             ##
11             ## This program is free software; you can redistribute it and/or modify it
12             ## under the same terms as Perl itself.
13             ##----------------------------------------------------------------------------
14             package HTML::Object::DOM::Boolean;
15             BEGIN
16             {
17 3     3   1007 use strict;
  3         6  
  3         95  
18 3     3   17 use warnings;
  3         5  
  3         87  
19 3     3   18 use parent qw( Module::Generic );
  3         5  
  3         15  
20 3     3   189 use vars qw( $VERSION );
  3         5  
  3         136  
21 3     3   55 our $VERSION = 'v0.2.0';
22             };
23              
24 3     3   17 use strict;
  3         5  
  3         54  
25 3     3   17 use warnings;
  3         6  
  3         446  
26              
27             sub init
28             {
29 0     0 1   my $self = shift( @_ );
30 0           my $bool = shift( @_ );
31 0           $self->{value} = $bool;
32 0           $self->{_init_strict_use_sub} = 1;
33 0 0         $self->SUPER::init( @_ ) || return( $self->pass_error );
34 0 0         $self->{value} = $self->{value} ? 1 : 0;
35 0           return( $self );
36             }
37              
38 0 0   0 1   sub toString { return( shift->{value} ? 'true' : 'false' ); }
39              
40 0 0   0 1   sub valueOf { return( shift->{value} ? 1 : 0 ); }
41              
42             1;
43             # NOTE: POD
44             __END__
45              
46             =encoding utf-8
47              
48             =head1 NAME
49              
50             HTML::Object::DOM::Boolean - HTML Object DOM Boolean
51              
52             =head1 SYNOPSIS
53              
54             use HTML::Object::DOM::Boolean;
55             my $bool = HTML::Object::DOM::Boolean->new(1) ||
56             die( HTML::Object::DOM::Boolean->error, "\n" );
57             say $bool->toString;
58             say $bool->valueOf;
59              
60             =head1 VERSION
61              
62             v0.2.0
63              
64             =head1 DESCRIPTION
65              
66             This implements an object wrapper for a boolean value.
67              
68             The value passed as the first parameter is converted to a boolean value, if necessary. If the value is omitted or is C<0>, C<-0>, C<undef>, or the empty string (""), the object has an initial value of false (i.e. C<0> in perl). All other values, including any object, an empty array ([]), or the string "false", create an object with an initial value of true (i.e. C<1> in perl).
69              
70             =head1 METHODS
71              
72             =head2 toString
73              
74             Returns a string of either C<true> or C<false> depending upon the value of the object.
75              
76             =head2 valueOf
77              
78             Returns the primitive value of the Boolean object, i.e. C<0> for false, or C<1> for true.
79              
80             =head1 AUTHOR
81              
82             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
83              
84             =head1 SEE ALSO
85              
86             L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean>
87              
88             =head1 COPYRIGHT & LICENSE
89              
90             Copyright(c) 2021 DEGUEST Pte. Ltd.
91              
92             All rights reserved
93              
94             This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
95              
96             =cut