File Coverage

blib/lib/Data/OpenGraph/Parser.pm
Criterion Covered Total %
statement 23 23 100.0
branch 3 6 50.0
condition 1 3 33.3
subroutine 5 5 100.0
pod 0 2 0.0
total 32 39 82.0


line stmt bran cond sub pod time code
1             package Data::OpenGraph::Parser;
2 1     1   5 use strict;
  1         2  
  1         39  
3 1     1   2236 use HTML::Parser;
  1         7326  
  1         291  
4              
5             sub new {
6 2     2 0 6 my $class = shift;
7             my $parser = HTML::Parser->new(
8             api_version => 3,
9             start_h => [ sub {
10 2     2   7 my ($self, $tag, $attr) = @_;
11              
12 2 50       14 return unless $tag eq 'meta';
13              
14 2         6 my $prop = $attr->{property};
15 2         6 my $content = $attr->{content};
16 2 50 33     19 return unless $prop && $content;
17 2 50       27 return unless $prop =~ s/^og://;
18              
19 2         19 $self->{properties}->{$prop} = $content;
20 2         35 }, "self, tagname, attr" ],
21             );
22 2         933 return bless { parser => $parser }, $class;
23             }
24              
25             sub parse_string {
26 2     2 0 7 my ($self, $string) = @_;
27              
28 2         4 my %properties;
29 2         16 my $parser = $self->{parser};
30 2         12 local $parser->{properties} = \%properties;
31 2         59 $parser->parse($string);
32 2         12 $parser->eof;
33              
34 2         12 return \%properties;
35             }
36              
37             1;