| 1 | ##---------------------------------------------------------------------------- | ||||||||||
| 2 | ## HTML Object - ~/lib/HTML/Object/Literal.pm | ||||||||||
| 3 | ## Version v0.2.0 | ||||||||||
| 4 | ## Copyright(c) 2021 DEGUEST Pte. Ltd. | ||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||
| 6 | ## Created 2021/04/22 | ||||||||||
| 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::Literal; | ||||||||||
| 15 | BEGIN | ||||||||||
| 16 | { | ||||||||||
| 17 | 11 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 11 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 11 | ▶ | warnings::register_categories( 'HTML::Object' ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 11 | ▶ | use parent qw( Module::Generic::Scalar ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 11 | ▶ | use vars qw( $VERSION ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 11 | our $VERSION = 'v0.2.0'; | |||||||||
| 23 | }; | ||||||||||
| 24 | |||||||||||
| 25 | 11 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 11 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | |||||||||||
| 28 | 0 | ▶ | sub as_number { return( shift->to_number( @_ ) ); } | ||||||||
|
Subroutine
as_number: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 29 | |||||||||||
| 30 | sub as_string | ||||||||||
| 31 | { | ||||||||||
| 32 | 0 | ▶ | my $self = shift( @_ ); | ||||||||
|
Subroutine
as_string: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 33 | 0 | my $txt = $self->SUPER::as_string; | |||||||||
| 34 | # $txt =~ s/'/'/g; | ||||||||||
| 35 | 0 | $txt =~ s/(?<!\\)\'/\\\'/g; | |||||||||
| 36 | 0 | return( "'$txt'" ); | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | sub as_xml | ||||||||||
| 40 | { | ||||||||||
| 41 | 0 | ▶ | my $self = shift( @_ ); | ||||||||
|
Subroutine
as_xml: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 42 | 0 | my $txt = $self->SUPER::as_string; | |||||||||
| 43 | 0 | return( "<Literal>$txt</Literal>\n" ); | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | sub evaluate { return( shift( @_ ) ); } | ||||||||
|
Subroutine
evaluate: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | sub getAttributes { return( shift->error( 'Cannot get attributes of a literal' ) ); } | ||||||||
|
Subroutine
getAttributes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 49 | |||||||||||
| 50 | 0 | ▶ | sub getChildNodes { return( shift->error( 'Cannot get child nodes of a literal' ) ); } | ||||||||
|
Subroutine
getChildNodes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | sub getParentNode { return( shift->error( 'Cannot get parent node of a literal' ) ); } | ||||||||
|
Subroutine
getParentNode: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | sub string_value { return( shift->value ); } | ||||||||
|
Subroutine
string_value: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 55 | |||||||||||
| 56 | # sub to_boolean { return( shift->as_boolean ); } | ||||||||||
| 57 | sub to_boolean | ||||||||||
| 58 | { | ||||||||||
| 59 | 0 | ▶ | require HTML::Object::Boolean; | ||||||||
|
Subroutine
to_boolean: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 60 | 0 | ▶ | return( shift->as_string ? HTML::Object::Boolean->True : HTML::Object::Boolean->False ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 0 | ▶ | sub to_literal { return( shift( @_ ) ); } | ||||||||
|
Subroutine
to_literal: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 64 | |||||||||||
| 65 | # sub to_number { return( shift->as_number ); } | ||||||||||
| 66 | sub to_number | ||||||||||
| 67 | { | ||||||||||
| 68 | 0 | ▶ | require HTML::Object::Number; | ||||||||
|
Subroutine
to_number: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 69 | 0 | return( HTML::Object::Number->new( shift->value ) ); | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 0 | ▶ | sub value { return( shift->SUPER::as_string ); } | ||||||||
|
Subroutine
value: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 73 | |||||||||||
| 74 | 0 | ▶ | sub value_as_number { return( shift->as_number ); } | ||||||||
|
Subroutine
value_as_number: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 75 | |||||||||||
| 76 | 11 | 1; | |||||||||
| 77 | # NOTE: POD | ||||||||||
| 78 | __END__ | ||||||||||
| 79 | |||||||||||
| 80 | =encoding utf-8 | ||||||||||
| 81 | |||||||||||
| 82 | =head1 NAME | ||||||||||
| 83 | |||||||||||
| 84 | HTML::Object::Literal - Simple string values | ||||||||||
| 85 | |||||||||||
| 86 | =head1 SYNOPSIS | ||||||||||
| 87 | |||||||||||
| 88 | use HTML::Object::Literal; | ||||||||||
| 89 | my $this = HTML::Object::Literal->new || die( HTML::Object::Literal->error, "\n" ); | ||||||||||
| 90 | |||||||||||
| 91 | =head1 VERSION | ||||||||||
| 92 | |||||||||||
| 93 | v0.2.0 | ||||||||||
| 94 | |||||||||||
| 95 | =head1 DESCRIPTION | ||||||||||
| 96 | |||||||||||
| 97 | In XPath terms a Literal is what we know as a string. | ||||||||||
| 98 | |||||||||||
| 99 | This module inherits from L<Module::Generic::Scalar> | ||||||||||
| 100 | |||||||||||
| 101 | =head1 METHODS | ||||||||||
| 102 | |||||||||||
| 103 | =head2 new | ||||||||||
| 104 | |||||||||||
| 105 | Provided with a C<string> and this will create a new Literal object with the value in C<string>. Note that " and ' will be converted to " and ' respectively. That is not part of the XPath specification, but I consider it useful. Note though that you have to go to extraordinary lengths in an XML template file (be it XSLT or whatever) to make use of this: | ||||||||||
| 106 | |||||||||||
| 107 | <xsl:value-of select=""I am feeling &quot;sad&quot;""/> | ||||||||||
| 108 | |||||||||||
| 109 | Which produces a Literal of: | ||||||||||
| 110 | |||||||||||
| 111 | I am feeling "sad" | ||||||||||
| 112 | |||||||||||
| 113 | =head2 as_string | ||||||||||
| 114 | |||||||||||
| 115 | Returns a string representation of this literal. | ||||||||||
| 116 | |||||||||||
| 117 | =head2 as_xml | ||||||||||
| 118 | |||||||||||
| 119 | Returns a string representation as xml. | ||||||||||
| 120 | |||||||||||
| 121 | =head2 evaluate | ||||||||||
| 122 | |||||||||||
| 123 | Does nothing. Returns the current object. | ||||||||||
| 124 | |||||||||||
| 125 | =head2 getAttributes | ||||||||||
| 126 | |||||||||||
| 127 | If called, this would return an L<error|Module::Generic/error> | ||||||||||
| 128 | |||||||||||
| 129 | =head2 getChildNodes | ||||||||||
| 130 | |||||||||||
| 131 | If called, this would return an L<error|Module::Generic/error> | ||||||||||
| 132 | |||||||||||
| 133 | =head2 getParentNode | ||||||||||
| 134 | |||||||||||
| 135 | If called, this would return an L<error|Module::Generic/error> | ||||||||||
| 136 | |||||||||||
| 137 | =head2 string_value | ||||||||||
| 138 | |||||||||||
| 139 | Returns the current value as-is. | ||||||||||
| 140 | |||||||||||
| 141 | =head2 to_boolean | ||||||||||
| 142 | |||||||||||
| 143 | Returns the current value as a L<boolean|Module::Generic::Boolean> | ||||||||||
| 144 | |||||||||||
| 145 | =head2 to_literal | ||||||||||
| 146 | |||||||||||
| 147 | Returns the current object. | ||||||||||
| 148 | |||||||||||
| 149 | =head2 to_number | ||||||||||
| 150 | |||||||||||
| 151 | Returns the current value as a L<number|Module::Generic::Number> | ||||||||||
| 152 | |||||||||||
| 153 | =head2 value | ||||||||||
| 154 | |||||||||||
| 155 | Also overloaded as stringification, simply returns the literal string value. | ||||||||||
| 156 | |||||||||||
| 157 | =head2 value_as_number | ||||||||||
| 158 | |||||||||||
| 159 | Returns the current value as a L<number|Module::Generic::Number> | ||||||||||
| 160 | |||||||||||
| 161 | =head1 AUTHOR | ||||||||||
| 162 | |||||||||||
| 163 | Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> | ||||||||||
| 164 | |||||||||||
| 165 | =head1 SEE ALSO | ||||||||||
| 166 | |||||||||||
| 167 | L<HTML::Object>, L<HTML::Object::Attribute>, L<HTML::Object::Boolean>, L<HTML::Object::Closing>, L<HTML::Object::Collection>, L<HTML::Object::Comment>, L<HTML::Object::Declaration>, L<HTML::Object::Document>, L<HTML::Object::Element>, L<HTML::Object::Exception>, L<HTML::Object::Literal>, L<HTML::Object::Number>, L<HTML::Object::Root>, L<HTML::Object::Space>, L<HTML::Object::Text>, L<HTML::Object::XQuery> | ||||||||||
| 168 | |||||||||||
| 169 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 170 | |||||||||||
| 171 | Copyright (c) 2021 DEGUEST Pte. Ltd. | ||||||||||
| 172 | |||||||||||
| 173 | All rights reserved | ||||||||||
| 174 | |||||||||||
| 175 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||
| 176 | |||||||||||
| 177 | =cut | ||||||||||