File Coverage

blib/lib/App/Presto/Client/ContentHandlers/HTML.pm
Criterion Covered Total %
statement 9 20 45.0
branch 1 4 25.0
condition 0 2 0.0
subroutine 5 7 71.4
pod 0 3 0.0
total 15 36 41.6


line stmt bran cond sub pod time code
1             package App::Presto::Client::ContentHandlers::HTML;
2             BEGIN {
3 1     1   752 $App::Presto::Client::ContentHandlers::HTML::AUTHORITY = 'cpan:BPHILLIPS';
4             }
5             {
6             $App::Presto::Client::ContentHandlers::HTML::VERSION = '0.009';
7             }
8              
9             # ABSTRACT: Handles deserializing of HTML responses
10              
11 1     1   10 use Moo;
  1         1  
  1         6  
12             my $HAS_HTML_FORMATTEXT_WITHLINKS;
13             BEGIN {
14 1     1   346 eval 'use HTML::FormatText::WithLinks; $HAS_HTML_FORMATTEXT_WITHLINKS = 1;'
  1     1   583  
  0         0  
  0         0  
15             }
16              
17             sub can_deserialize {
18 1     1 0 930 my $self = shift;
19 1         2 my $content_type = shift;
20 1 50       8 return unless $HAS_HTML_FORMATTEXT_WITHLINKS;
21 0           return $content_type =~ m{^text/html}i;
22             }
23              
24             sub deserialize {
25 0     0 0   my $self = shift;
26 0           my $content = shift;
27 0           my $text;
28 0 0 0       eval { $text = HTML::FormatText::WithLinks->format_string($content) || 1 } or do {
  0            
29 0           warn "Unable to parse HTML: $@";
30             };
31 0           return $text;
32             }
33              
34 0     0 0   sub can_serialize { 0 }
35              
36             1;
37              
38             __END__