line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::OpenGraph; |
2
|
1
|
|
|
1
|
|
947
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
45
|
|
3
|
1
|
|
|
1
|
|
6
|
use Carp (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
4
|
1
|
|
|
1
|
|
619
|
use Data::OpenGraph::Parser; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
58
|
|
5
|
|
|
|
|
|
|
use constant +{ |
6
|
1
|
50
|
33
|
|
|
3
|
HAVE_LWP => eval { require LWP::UserAgent } && !$@ ? 1 : 0, |
7
|
1
|
|
|
1
|
|
10
|
}; |
|
1
|
|
|
|
|
2
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
2
|
|
|
2
|
1
|
7
|
my ($class, %args) = @_; |
13
|
2
|
|
|
|
|
17
|
bless { %args }, $class; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub property { |
17
|
2
|
|
|
2
|
0
|
19
|
my ($self, $name) = @_; |
18
|
2
|
|
|
|
|
23
|
return $self->{properties}->{$name}; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub parse_uri { |
22
|
0
|
|
|
0
|
1
|
0
|
my ($class, $uri) = @_; |
23
|
0
|
|
|
|
|
0
|
if (HAVE_LWP) { |
24
|
0
|
|
|
|
|
0
|
my $ua = LWP::UserAgent->new(); |
25
|
0
|
|
|
|
|
0
|
my $res = $ua->get( $uri ); |
26
|
0
|
0
|
|
|
|
0
|
if (! $res->is_success) { |
27
|
0
|
|
|
|
|
0
|
Carp::croak( "Failed to get $uri: " . $res->status_line); |
28
|
|
|
|
|
|
|
} |
29
|
0
|
|
|
|
|
0
|
return $class->parse_string( $res->decoded_content ); |
30
|
|
|
|
|
|
|
} else { |
31
|
|
|
|
|
|
|
Carp::croak( "No applicable UserAgent (such as LWP::UserAgent) found" ); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub parse_string { |
36
|
2
|
|
|
2
|
1
|
9396
|
my ($class, $string) = @_; |
37
|
2
|
|
|
|
|
24
|
my $properties = Data::OpenGraph::Parser->new()->parse_string( $string ); |
38
|
2
|
|
|
|
|
48
|
Data::OpenGraph->new( properties => \%$properties ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__END__ |