Data-OpenGraph

 view release on metacpan or  search on metacpan

lib/Data/OpenGraph.pm  view on Meta::CPAN

}

sub parse_uri {
    my ($class, $uri) = @_;
    if (HAVE_LWP) {
        my $ua = LWP::UserAgent->new();
        my $res = $ua->get( $uri );
        if (! $res->is_success) {
            Carp::croak( "Failed to get $uri: " . $res->status_line);
        }
        return $class->parse_string( $res->decoded_content );
    } else {
        Carp::croak( "No applicable UserAgent (such as LWP::UserAgent) found" );
    }
}

sub parse_string {
    my ($class, $string) = @_;
    my $properties = Data::OpenGraph::Parser->new()->parse_string( $string );
    Data::OpenGraph->new( properties => \%$properties );
}

lib/Data/OpenGraph.pm  view on Meta::CPAN

Data::OpenGraph - Parse OpenGraph Contents

=head1 SYNOPSIS

    use Data::OpenGraph;

    my $og = Data::OpenGraph->parse_uri( "http://some.content/with/opengraph.html" );

    my $ua = LWP::UserAgent->new();
    my $res = $ua->get( "http://some.content/with/opengraph.html" );
    my $og = Data::OpenGraph->parse_uri( $res->decoded_content );

    my $title = $og->property( "title" );
    my $type  = $og->property( "type" );

=head1 DESCRIPTION

WARNINGS: ALPHA CODE! Probably very incomplete. Please send pull-reqs if you would like this module to be better

Data::OpenGraph is a simple Opengraph ( http://ogp.me ) parser. It just parses some HTML looking for meta tags with property attribute that looks like "og:.+".



( run in 0.356 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )