The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Web::NewsAPI::Artcle - Object class representing a News API article

SYNOPSIS

 use v5.10;
 use Web::NewsAPI;

 my $newsapi = Web::NewsAPI->new(
    api_key => $my_secret_api_key,
 );

 say "Here are some top American-news headlines about science...";
 my $result = $newsapi->top_headlines(
    category => 'science', country => 'us',
 );
 # $result is now a Web::NewsAPI::Result object.
 # We can call its 'articles' method to get a list of article objects:
 for my $article ( $result->articles ) {
    say $article->title;
    say $article->description;
    print "\n";
 }

DESCRIPTION

Objects of this class represent a News API news article. Generally, you won't create these objects yourself; you'll get them as a result of calling methods on a Web::NewsAPI object or a Web::NewsAPI::Result object.

METHODS

Object attributes

These are all read-only attributes, based on information provided by News API. (They use camelCase because they just copy the attribute names from News API itself.)

source

 my $source = $article->source;
 say "The source of this article was " . $source->name;

A Web::NewsAPI::Source object.

author

 my $author = $article->author;
 say "$author wrote this article.";

A string.

title

 my $title = $article->title;

A string.

description

 my $description = $article->description;

url

 my $url = $article->url;

A URI object. (Possibly undefined.)

urlToImage

 my $image_url = $article->urlToImage;

A URI object. (Possibly undefined.)

publishedAt

 my $publication_datetime = $article->publishedAt;

A DateTime object.

AUTHOR

Jason McIntosh (jmac@jmac.org)