File Coverage

blib/lib/HTML/MobileJp/Filter/Content.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package HTML::MobileJp::Filter::Content;
2 6     6   822 use Moose;
  6         386260  
  6         37  
3              
4             has _current => (
5             is => 'rw',
6             isa => 'Any',
7             );
8              
9             has html => (
10             is => 'rw',
11             isa => 'Str',
12             trigger => sub {
13             shift->_current('html');
14             },
15             );
16              
17             has xml => (
18             is => 'rw',
19             isa => 'XML::LibXML::Document',
20             trigger => sub {
21             shift->_current('xml');
22             },
23             );
24              
25 6     6   36226 use overload '""' => 'stringfy', fallback => 1;
  6         15  
  6         54  
26              
27             *stringfy = \&as_html;
28              
29 6     6   4655 use XML::LibXML;
  0            
  0            
30              
31             sub update {
32             my ($self, $content) = @_;
33             if (ref($content) and $content->isa(__PACKAGE__)) {
34             $self->{$_} = $content->{$_} for qw( html xml );
35             } elsif (ref($content) and $content->isa('XML::LibXML::Document')) {
36             $self->xml($content);
37             } else {
38             $self->html($content);
39             }
40             }
41              
42             sub as_html {
43             my ($self) = @_;
44             if ($self->_current ne 'html') {
45             $self->html( $self->xml->toString ) if $self->_current ne 'html';
46             }
47             $self->html;
48             }
49              
50             sub as_xml {
51             my ($self) = @_;
52             if ($self->_current ne 'xml') {
53             $self->xml( XML::LibXML->new->parse_string($self->html) );
54             }
55             $self->xml;
56             }
57              
58             1;