Web::NewsAPI::Artcle - Object class representing a News API article
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"; }
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.
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.)
my $source = $article->source; say "The source of this article was " . $source->name;
A Web::NewsAPI::Source object.
my $author = $article->author; say "$author wrote this article.";
A string.
my $title = $article->title;
my $description = $article->description;
my $url = $article->url;
A URI object. (Possibly undefined.)
my $image_url = $article->urlToImage;
my $publication_datetime = $article->publishedAt;
A DateTime object.
Jason McIntosh (jmac@jmac.org)
To install Web::NewsAPI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Web::NewsAPI
CPAN shell
perl -MCPAN -e shell install Web::NewsAPI
For more information on module installation, please visit the detailed CPAN module installation guide.