blib/lib/HTML/Object/DOM/Boolean.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 52 CC 4 SCAR 13.5
CC
4
Cov
0%
init
6.0
toString
6.0
valueOf
6.0
CRAP 3.8
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 use strict;
18 use warnings;
19 warnings::register_categories( 'HTML::Object' );
20 use parent qw( Module::Generic );
21 use vars qw( $VERSION );
22 our $VERSION = 'v0.2.0';
23 };
24  
25 use strict;
26 use warnings;
27  
28 sub init
29 {
30 my $self = shift( @_ );
31 my $bool = shift( @_ );
32 $self->{value} = $bool;
33 $self->{_init_strict_use_sub} = 1;
34 $self->SUPER::init( @_ ) || return( $self->pass_error );
35 $self->{value} = $self->{value} ? 1 : 0;
36 return( $self );
37 }
38  
39 sub toString { return( shift->{value} ? 'true' : 'false' ); }
40  
41 sub valueOf { return( shift->{value} ? 1 : 0 ); }
42  
43 1;
44 # NOTE: POD
45 __END__
46  
47 =encoding utf-8
48  
49 =head1 NAME
50  
51 HTML::Object::DOM::Boolean - HTML Object DOM Boolean
52  
53 =head1 SYNOPSIS
54  
55 use HTML::Object::DOM::Boolean;
56 my $bool = HTML::Object::DOM::Boolean->new(1) ||
57 die( HTML::Object::DOM::Boolean->error, "\n" );
58 say $bool->toString;
59 say $bool->valueOf;
60  
61 =head1 VERSION
62  
63 v0.2.0
64  
65 =head1 DESCRIPTION
66  
67 This implements an object wrapper for a boolean value.
68  
69 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).
70  
71 =head1 METHODS
72  
73 =head2 toString
74  
75 Returns a string of either C<true> or C<false> depending upon the value of the object.
76  
77 =head2 valueOf
78  
79 Returns the primitive value of the Boolean object, i.e. C<0> for false, or C<1> for true.
80  
81 =head1 AUTHOR
82  
83 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
84  
85 =head1 SEE ALSO
86  
87 L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean>
88  
89 =head1 COPYRIGHT & LICENSE
90  
91 Copyright(c) 2021 DEGUEST Pte. Ltd.
92  
93 All rights reserved
94  
95 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
96  
97 =cut