lib/HTML/Object/XPath/Boolean.pm

filter: Statementstmt 72.0% 31 / 43 Branchbran 0.0% 0 / 8 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 64.7% 11 / 17 Podpod 100% 10 / 10 totaltotal 61.3% 54 / 88 CC 7 SCAR 11.1
CC
7
Cov
58%
cmp
6.0
getAttributes
6.0
getChildNodes
6.0
CRAP 3.0
« lib/HTML/Object/DOM/Element/Canvas.pm ↑ Summary blib/lib/HTML/Object/Comment.pm »
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 12 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 12 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 12 ▶ warnings::register_categories( 'HTML::Object' );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 12 ▶ use vars qw( $DEBUG $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 use overload (
22 12 '""' => \&value,
23 '<=>' => \&cmp
24 12 ▶ );
Subroutine BEGIN: called CC=1 SCAR=0.0
25 12 our $DEBUG = 0;
26 12 our $VERSION = 'v0.2.0';
27 };
28  
29 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 sub cmp
33 {
34 0 ▶ my $self = shift( @_ );
Subroutine cmp: not called CC=2 SCAR=17.9
Pod documented
35 0 my( $other, $swap ) = @_;
36 0 ▶ if( $swap )
Branch: 1 branch
BranchTrueFalseTotal
if ($swap) 0 0 0
37 {
38 0 return( $other <=> $$self );
39 }
40 0 return( $$self <=> $other );
41 }
42  
43 sub False
44 {
45 60 ▶ my $this = shift( @_ );
Subroutine False: called CC=2 SCAR=7.6
Pod documented
46 60 my $val = 0;
47 60 ▶ return( bless( \$val => ( ref( $this ) || $this ) ) );
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0600
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
48 }
49  
50 0 ▶sub getAttributes { return( wantarray() ? () : [] ); }
Subroutine getAttributes: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
51  
52 0 ▶sub getChildNodes { return( wantarray() ? () : [] ); }
Subroutine getChildNodes: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
53  
54 0 ▶sub string_value { return( $_[0]->to_literal->value ); }
Subroutine string_value: not called CC=1 SCAR=6.9
Pod documented
55  
56 20 ▶sub to_boolean { return( $_[0] ); }
Subroutine to_boolean: called CC=1 SCAR=0.0
Pod documented
57  
58 sub to_literal
59 {
60 0 ▶ require HTML::Object::XPath::Literal;
Subroutine to_literal: not called CC=2 SCAR=17.9
Pod documented
61 0 ▶ return( HTML::Object::XPath::Literal->new( $_[0]->value ? 'true' : 'false' ) );
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->value ? : 0 0 0
62 }
63  
64 sub to_number
65 {
66 0 ▶ require HTML::Object::XPath::Number;
Subroutine to_number: not called CC=1 SCAR=6.9
Pod documented
67 0 return( HTML::Object::XPath::Number->new( $_[0]->value ) );
68 }
69  
70 sub True
71 {
72 60 ▶ my $this = shift( @_ );
Subroutine True: called CC=2 SCAR=7.6
Pod documented
73 60 my $val = 1;
74 60 ▶ return( bless( \$val => ( ref( $this ) || $this ) ) );
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0600
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
75 }
76  
77 sub value
78 {
79 884 ▶ my $self = shift( @_ );
Subroutine value: called CC=1 SCAR=0.0
Pod documented
80 884 return( $$self );
81 }
82  
83 12 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
« lib/HTML/Object/DOM/Element/Canvas.pm ↑ Summary blib/lib/HTML/Object/Comment.pm »