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

filter: Statementstmt 0.0% 0 / 47 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 11 totaltotal 0.0% 0 / 91 CC 5 SCAR 12.2
CC
5
Cov
0%
cmp
6.0
getAttributes
6.0
getChildNodes
6.0
CRAP 3.4
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/XPath/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/05
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::XPath::Boolean;
15 BEGIN
16 {
17 use strict;
18 use warnings;
19 warnings::register_categories( 'HTML::Object' );
20 use vars qw( $DEBUG $VERSION );
21 use overload (
22 '""' => \&value,
23 '<=>' => \&cmp
24 );
25 our $DEBUG = 0;
26 our $VERSION = 'v0.2.0';
27 };
28  
29 use strict;
30 use warnings;
31  
32 sub cmp
33 {
34 my $self = shift( @_ );
35 my( $other, $swap ) = @_;
36 if( $swap )
37 {
38 return( $other <=> $$self );
39 }
40 return( $$self <=> $other );
41 }
42  
43 sub False
44 {
45 my $this = shift( @_ );
46 my $val = 0;
47 return( bless( \$val => ( ref( $this ) || $this ) ) );
48 }
49  
50 sub getAttributes { return( wantarray() ? () : [] ); }
51  
52 sub getChildNodes { return( wantarray() ? () : [] ); }
53  
54 sub string_value { return( $_[0]->to_literal->value ); }
55  
56 sub to_boolean { return( $_[0] ); }
57  
58 sub to_literal
59 {
60 require HTML::Object::XPath::Literal;
61 return( HTML::Object::XPath::Literal->new( $_[0]->value ? 'true' : 'false' ) );
62 }
63  
64 sub to_number
65 {
66 require HTML::Object::XPath::Number;
67 return( HTML::Object::XPath::Number->new( $_[0]->value ) );
68 }
69  
70 sub True
71 {
72 my $this = shift( @_ );
73 my $val = 1;
74 return( bless( \$val => ( ref( $this ) || $this ) ) );
75 }
76  
77 sub value
78 {
79 my $self = shift( @_ );
80 return( $$self );
81 }
82  
83 1;
84 # NOTE: POD
85 __END__
86  
87 =encoding utf-8
88  
89 =head1 NAME
90  
91 HTML::Object::XPath::Boolean - HTML Object
92  
93 =head1 SYNOPSIS
94  
95 use HTML::Object::XPath::Boolean;
96 my $this = HTML::Object::XPath::Boolean->new || die( HTML::Object::XPath::Boolean->error, "\n" );
97  
98 =head1 VERSION
99  
100 v0.2.0
101  
102 =head1 DESCRIPTION
103  
104 This module implements simple boolean true/false objects.
105  
106 =head1 METHODS
107  
108 =head2 cmp
109  
110 This method is called for overloading the comparison operator.
111  
112 It takes another element and it returns true if the two elements are same or false otherwise.
113  
114 =head2 getAttributes
115  
116 Returns an empty list in list context and an empty array reference in scalar context.
117  
118 =head2 getChildNodes
119  
120 Returns an empty list in list context and an empty array reference in scalar context.
121  
122 =head2 string_value
123  
124 Returns the current value as a L<literal|HTML::Object::XPath::Literal>
125  
126 =head2 to_boolean
127  
128 Returns the current object.
129  
130 =head2 to_literal
131  
132 Returns C<true> if true, or C<false> otherwise, as a L<literal object|HTML::Object::XPath::Literal>
133  
134 =head2 to_number
135  
136 Returns the current value as a L<number object|HTML::Object::XPath::Number>
137  
138 =head2 True
139  
140 Creates a new Boolean object with a true value.
141  
142 HTML::Object::XPath::Boolean->True;
143  
144 =head2 False
145  
146 Creates a new Boolean object with a false value.
147  
148 HTML::Object::XPath::Boolean->False;
149  
150 =head2 value
151  
152 Returns true or false.
153  
154 =head1 AUTHOR
155  
156 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
157  
158 =head1 SEE ALSO
159  
160 L<HTML::Object::XPath>, L<HTML::Object::XPath::Boolean>, L<HTML::Object::XPath::Expr>, L<HTML::Object::XPath::Function>, L<HTML::Object::XPath::Literal>, L<HTML::Object::XPath::LocationPath>, L<HTML::Object::XPath::NodeSet>, L<HTML::Object::XPath::Number>, L<HTML::Object::XPath::Root>, L<HTML::Object::XPath::Step>, L<HTML::Object::XPath::Variable>
161  
162 =head1 COPYRIGHT & LICENSE
163  
164 Copyright(c) 2021 DEGUEST Pte. Ltd.
165  
166 All rights reserved
167  
168 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
169  
170 =cut