File Coverage

blib/lib/Feed/Data/Parser/Meta.pm
Criterion Covered Total %
statement 13 13 100.0
branch n/a
condition 2 2 100.0
subroutine 5 5 100.0
pod 0 1 0.0
total 20 21 95.2


line stmt bran cond sub pod time code
1             package Feed::Data::Parser::Meta;
2              
3 2     2   1484 use Moo;
  2         6  
  2         45  
4             extends 'Feed::Data::Parser::Base';
5 2     2   871 use Compiled::Params::OO qw/cpo/;
  2         6  
  2         32  
6 2     2   281 use Types::Standard qw/Object HashRef Str/;
  2         4  
  2         28  
7              
8             our $validate;
9             BEGIN {
10 2     2   2258 $validate = cpo(
11             get_value => [Object, HashRef, Str],
12             );
13             }
14              
15             has '+parser' => (
16             default => sub {
17             my $self = shift;
18             my $content = $self->content_ref;
19             my %match;
20             while ($$content =~ s/\<meta(.*)\/\>//) {
21             my $match = $1;
22             $match =~ m/(name|property)\=\"([^"]+)/xms;
23             my $name = [split ":", $2]->[1];
24             $match =~ m/content\=\"([^"]+)/xms;
25             my $value = $1;
26             $match{$name} = $value unless $match{$name};
27             }
28             $match{link} = $match{url};
29             $match{author} = $match{site_name} || $match{site};
30             return { items => [\%match] };
31             },
32             );
33              
34             sub get_value {
35 20     20 0 65 my ($self, $item, $action) = $validate->get_value->(@_);
36 20         196 my $value = $item->{$action};
37 20   100     91 return $value // '';
38             }
39              
40             1; # End of Feed::Data