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   107923 use Moo;
  5         11583  
  5         47  
4 5     5   4860 use MooX::ClassAttribute;
  5         50000  
  5         34  
5             extends 'Web::Mention';
6              
7 5     5   3007 use Web::Microformats2::Parser;
  5         1656854  
  5         1723  
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 36052 my ( $class, $source, %options ) = @_;
25              
26 3         78 my $response = $class->ua->get($source);
27              
28 3 50       40719 if ( $response->is_success ) {
29 3         30 my $html;
30 3 100       9 if ( $options{limit_to_content} ) {
31 2         64 my $mf2_doc = $class->mf2_parser->parse( $response->content,
32             ( url_context => $source ) );
33 2         73096 my $entry = $mf2_doc->get_first('entry');
34 2 100       495 my $content = $entry->get_property('content') if $entry;
35 2 100       23 if ($content) {
36 1   50     17 $html = $content->{html} // '';
37             }
38             else {
39 1         35 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         37 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