File Coverage

lib/HTML/Object/Declaration.pm
Criterion Covered Total %
statement 31 41 75.6
branch 2 10 20.0
condition 1 6 16.6
subroutine 11 14 78.5
pod 6 6 100.0
total 51 77 66.2


line stmt bran cond sub pod time code
1             ##----------------------------------------------------------------------------
2             ## HTML Object - ~/lib/HTML/Object/Declaration.pm
3             ## Version v0.2.0
4             ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5             ## Author: Jacques Deguest <jack@deguest.jp>
6             ## Created 2021/04/19
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::Declaration;
15             BEGIN
16             {
17 29     29   204 use strict;
  29         56  
  29         849  
18 29     29   153 use warnings;
  29         78  
  29         690  
19 29     29   142 use warnings::register;
  29         59  
  29         2664  
20 29     29   156 use parent qw( HTML::Object::Element );
  29         63  
  29         148  
21 29     29   1656 use vars qw( $VERSION );
  29         51  
  29         1139  
22 29     29   462 our $VERSION = 'v0.2.0';
23             };
24              
25 29     29   148 use strict;
  29         46  
  29         531  
26 29     29   117 use warnings;
  29         52  
  29         8902  
27              
28             sub init
29             {
30 18     18 1 57 my $self = shift( @_ );
31 18         55 $self->{is_empty} = 1;
32 18 50 33     184 $self->{name} = 'html' unless( CORE::exists( $self->{name} ) && CORE::length( $self->{name} ) );
33 18         69 $self->{_init_strict_use_sub} = 1;
34 18         65 $self->{_exception_class} = 'HTML::Object::Exception';
35 18 50       177 $self->SUPER::init( @_ ) || return( $self->pass_error );
36 18         78 $self->{tag} = '_declaration';
37 18         206 return( $self );
38             }
39              
40             sub as_string
41             {
42 0     0 1 0 my $self = shift( @_ );
43 0 0       0 if( !$self->original->is_empty )
44             {
45 0         0 return( $self->original );
46             }
47             else
48             {
49 0         0 my $name = $self->name;
50 0 0 0     0 return( $self->new_scalar( "<!DOCTYPE" . ( ( defined( $name ) && CORE::length( "$name" ) ) ? " ${name}" : '' ) . '>' ) );
51             }
52             }
53              
54 0     0 1 0 sub as_xml { return( shift->as_string( @_ ) ); }
55              
56 18     18 1 58 sub checksum { return( '' ); }
57              
58             sub name
59             {
60 0     0 1   my $self = shift( @_ );
61 0 0         if( my $rv = $self->original->match( qr/^<!DOCTYPE[[:blank:]\h]+(\w+)/ ) )
62             {
63 0           return( lc( $rv->capture->first ) );
64             }
65 0           return( '' );
66             }
67              
68       18 1   sub set_checksum {}
69              
70             1;
71             # NOTE: POD
72             __END__
73              
74             =encoding utf-8
75              
76             =head1 NAME
77              
78             HTML::Object::Declaration - HTML Object
79              
80             =head1 SYNOPSIS
81              
82             use HTML::Object::Declaration;
83             my $this = HTML::Object::Declaration->new || die( HTML::Object::Declaration->error, "\n" );
84              
85             =head1 VERSION
86              
87             v0.2.0
88              
89             =head1 DESCRIPTION
90              
91             This module represents a document declaration element.
92              
93             =head1 INHERITANCE
94              
95             +-----------------------+ +---------------------------+
96             | HTML::Object::Element | --> | HTML::Object::Declaration |
97             +-----------------------+ +---------------------------+
98              
99             =head1 PROPERTIES
100              
101             =head2 internalSubset
102              
103             Read-only.
104              
105             Returns an empty L<string object|Module::Generic::Scalar>
106              
107             =head2 name
108              
109             Read-only.
110              
111             A DOMString, eg C<html> for <!DOCTYPE HTML>.
112              
113             =head2 notations
114              
115             Read-only.
116              
117             A NamedNodeMap with notations declared in the DTD.
118              
119             =head2 publicId
120              
121             Read-only.
122              
123             A DOMString, eg "-//W3C//DTD HTML 4.01//EN", empty string for HTML5.
124              
125             For example, with a doctype such as:
126              
127             <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
128             "http://www.w3.org/TR/html4/strict.dtd">
129              
130             or
131              
132             <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
133             "http://www.w3.org/TR/html4/loose.dtd">
134              
135             =head2 systemId
136              
137             Read-only.
138              
139             A DOMString, eg "http://www.w3.org/TR/html4/strict.dtd", empty string for HTML5.
140              
141             =head1 METHODS
142              
143             =head2 after
144              
145             This method is listed here for standard compliance, but actually does nothing.
146              
147             Normally, in JavaScript, it would insert a set of Node or DOMString objects in the children list of the DocumentType's parent, just after the DocumentType object.
148              
149             =head2 as_string
150              
151             Returns a string representation of this element.
152              
153             =head2 as_xml
154              
155             Returns a xml representation of this element. This is actually an alias for L</as_string>
156              
157             =head2 before
158              
159             This method is listed here for standard compliance, but actually does nothing.
160              
161             Normally, in JavaScript, it would insert a set of Node or DOMString objects in the children list of the DocumentType's parent, just before the DocumentType object.
162              
163             =head2 checksum
164              
165             Returns an empty string.
166              
167             =head2 set_checksum
168              
169             Returns nothing.
170              
171             =head1 AUTHOR
172              
173             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
174              
175             =head1 SEE ALSO
176              
177             L<https://html.spec.whatwg.org/multipage/syntax.html#the-doctype>
178              
179             L<https://developer.mozilla.org/en-US/docs/Web/HTML/Quirks_Mode_and_Standards_Mode>
180              
181             L<https://developer.mozilla.org/en-US/docs/Web/API/DocumentType>
182              
183             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>
184              
185             =head1 COPYRIGHT & LICENSE
186              
187             Copyright (c) 2021 DEGUEST Pte. Ltd.
188              
189             All rights reserved
190              
191             This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
192              
193             =cut