File Coverage

blib/lib/Rose/HTML/Text.pm
Criterion Covered Total %
statement 31 32 96.8
branch 10 12 83.3
condition n/a
subroutine 14 15 93.3
pod 8 8 100.0
total 63 67 94.0


line stmt bran cond sub pod time code
1              
2             use strict;
3 43     43   85223  
  43         99  
  43         1191  
4             use base 'Rose::HTML::Object';
5 43     43   265  
  43         1123  
  43         18450  
6             use Rose::HTML::Util();
7 43     43   259  
  43         83  
  43         3125  
8             our $VERSION = '0.602';
9              
10             __PACKAGE__->valid_html_attrs([]);
11              
12             use overload
13             (
14             '""' => sub { shift->html },
15 99     99   2727 'bool' => sub { 1 },
16 2636     2636   5511 '0+' => sub { 1 },
17 0     0   0 fallback => 1,
18 43         474 );
19 43     43   239  
  43         77  
20             # XXX: When Class::XSAccessor is installed, the (apparent) combination of
21             # XXX: overload and Rose::Object::MakeMethods::Generic's method creation
22             # XXX: for plain scalar attributes causes things to go awry and tests to
23             # XXX" fail (e.g., t/text.t)
24             # use Rose::Object::MakeMethods::Generic
25             # (
26             # { override_existing => 1 },
27             # scalar =>
28             # [
29             # 'html',
30             # ],
31             # );
32              
33             # XXX: Do it the old-fashioned way (see comments above)
34             {
35             my($self) = shift;
36             return $self->{'html'} = shift if(@_);
37 2813     2813 1 16376 return $self->{'html'};
38 2813 100       6361 }
39 1989         8007  
40              
41              
42 862     862 1 1778 {
43 191     191 1 341 my($self) = shift;
44             @_ = (text => @_) if(@_ == 1);
45 193     193 1 450 $self->SUPER::init(@_);
46             }
47              
48             {
49 610     610 1 862 my($self) = shift;
50 610 100       1168 local $^W = 0; # XXX: Using a sledgehammer here due to possible stringification overloading on $_[0]
51 610         1297 $self->html(defined $_[0] ? Rose::HTML::Util::escape_html(@_) : undef) if(@_);
52             return Rose::HTML::Util::unescape_html($self->html);
53             }
54              
55             {
56 408     408 1 1538 my($self) = shift;
57 408         1061 Carp::croak ref($self), " objects cannot have children()" if(@_ > 1);
58 408 100       1551 return wantarray ? () : [];
    100          
59 408         674 }
60              
61             *unshift_children = \&push_children;
62              
63             1;
64 3     3 1 4  
65 3 50       7  
66 3 50       12 =head1 NAME
67              
68             Rose::HTML::Text - Object representation of HTML-escaped text.
69 5     5 1 1021  
70             =head1 SYNOPSIS
71              
72             $text = Rose::HTML::Text->new('I <3 HTML');
73              
74             print $text->html; # I &lt;3 HTML
75              
76             # Stringification is overloaded
77             print "$text" # I &lt;3 HTML
78              
79             ...
80              
81             =head1 DESCRIPTION
82              
83             L<Rose::HTML::Text> is an object representation of and HTML-escaped text string. Stringification is L<overloaded|overload> to call the L<html|/html> method.
84              
85             This class inherits from, and follows the conventions of, L<Rose::HTML::Object>. Inherited methods that are not overridden will not be documented a second time here. See the L<Rose::HTML::Object> documentation for more information.
86              
87             =head1 HTML ATTRIBUTES
88              
89             Valid attributes: E<lt>noneE<gt>
90              
91             =head1 CONSTRUCTOR
92              
93             =over 4
94              
95             =item B<new [ PARAMS | TEXT ]>
96              
97             This behaves like standard L<Rose::HTML::Object> L<constructor|Rose::HTML::Object/new> except that if a lone argument is passed, it is taken as the value of L<text|/text>.
98              
99             =back
100              
101             =head1 OBJECT METHODS
102              
103             =over 4
104              
105             =item B<html [HTML]>
106              
107             Get or set the HTML version of the L<text|/text>.
108              
109             =item B<text [TEXT]>
110              
111             Get or set the text.
112              
113             =item B<xhtml [XHTML]>
114              
115             This is an alias for the L<html|/html> method.
116              
117             =back
118              
119             =head1 AUTHOR
120              
121             John C. Siracusa (siracusa@gmail.com)
122              
123             =head1 LICENSE
124              
125             Copyright (c) 2010 by John C. Siracusa. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.