File Coverage

lib/Whim/Mention.pm
Criterion Covered Total %
statement 22 23 95.6
branch 7 8 87.5
condition 1 2 50.0
subroutine 4 4 100.0
pod 0 1 0.0
total 34 38 89.4


line stmt bran cond sub pod time code
1             package Whim::Mention;
2              
3 5     5   110619 use Moo;
  5         11907  
  5         48  
4 5     5   5364 use MooX::ClassAttribute;
  5         51862  
  5         43  
5             extends 'Web::Mention';
6              
7 5     5   3445 use Web::Microformats2::Parser;
  5         1711661  
  5         1730  
8              
9             has 'author_photo_hash' => (
10             is => 'rw',
11             isa => sub {
12             if ( defined $_[0] ) {
13             die "Not a SHA256 hash" unless length $_[0] == 64;
14             }
15             },
16             );
17              
18             class_has 'mf2_parser' => (
19             is => 'ro',
20             default => sub { Web::Microformats2::Parser->new },
21             );
22              
23             sub new_from_source {
24 3     3 0 38583 my ( $class, $source, %options ) = @_;
25              
26 3         87 my $response = $class->ua->get($source);
27              
28 3 50       42924 if ( $response->is_success ) {
29 3         34 my $html;
30 3 100       11 if ( $options{limit_to_content} ) {
31 2         64 my $mf2_doc = $class->mf2_parser->parse( $response->content,
32             ( url_context => $source ) );
33 2         72797 my $entry = $mf2_doc->get_first('entry');
34 2 100       486 my $content = $entry->get_property('content') if $entry;
35 2 100       20 if ($content) {
36 1   50     17 $html = $content->{html} // '';
37             }
38             else {
39 1         25 die "Content at $source lacks an h-entry microformat "
40             . "with an e-content property.\n";
41             }
42             }
43             else {
44 1         8 $html = $response->content;
45             }
46 2         43 return $class->new_from_html(
47             source => $source,
48             html => $html,
49             );
50             }
51             else {
52 0           die "Could not fetch content from $source: "
53             . $response->status_line . "\n";
54             }
55             }
56              
57             1;
58              
59             =head1 NAME
60              
61             Whim::Mention - A code library used by the Whim webmention multitool
62              
63             =head1 DESCRIPTION
64              
65             This is a code library used by the C<whim> executable. It doesn't have a
66             public interface!
67              
68             =head1 SEE ALSO
69              
70             L<whim>
71              
72             =head1 AUTHOR
73              
74             Jason McIntosh E<lt>jmac@jmac.orgE<gt>
75