blib/lib/HTML/Object/Comment.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 71 CC 3 SCAR 11.0
CC
3
Cov
0%
as_string
6.0
as_xml
6.0
BEGIN
2.0
CRAP 3.0
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/Comment.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::Comment;
15 BEGIN
16 {
17 use strict;
18 use warnings;
19 warnings::register_categories( 'HTML::Object' );
20 use parent qw( HTML::Object::Element );
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 $self->{open_seq} = '<!--';
32 $self->{close_seq} = '-->';
33 $self->{tag} = '_comment';
34 $self->{value} = '';
35 $self->{is_empty} = 1;
36 $self->{_init_strict_use_sub} = 1;
37 $self->{_exception_class} = 'HTML::Object::Exception';
38 $self->SUPER::init( @_ ) || return( $self->pass_error );
39 return( $self );
40 }
41  
42 sub as_string
43 {
44 my $self = shift( @_ );
45 # We need to remove the reset flag, otherwise if there are any subsequent change that need to be propagated to this comment parent, HTML::Object::Element::reset will not propagate it
46 $self->_remove_reset;
47 return(
48 $self->value->length
49 ? $self->new_scalar( join( '', '<!--', $self->value->scalar, '-->' ) )
50 : $self->original
51 );
52 }
53  
54 sub as_xml
55 {
56 my $self = shift( @_ );
57 my $txt = $self->value->length
58 ? $self->new_scalar( join( '', '<!--', $self->value->scalar, '-->' ) )
59 : $self->original;
60 # HTML::Element says there cannot be double --'s in XML comments
61 $txt->replace( qr/--/, '-&#45;' );
62 return( $txt );
63 }
64  
65 sub close_seq { return( shift->_set_get_scalar_as_object( 'close_seq', @_ ) ); }
66  
67 sub open_seq { return( shift->_set_get_scalar_as_object( 'open_seq', @_ ) ); }
68  
69 sub set_checksum
70 {
71 my $self = shift( @_ );
72 return( $self->_get_md5_hash( $self->value->scalar ) );
73 }
74  
75 sub value : lvalue { return( shift->_set_get_scalar_as_object( 'value', @_ ) ); }
76  
77 1;
78 # NOTE: POD
79 __END__