| 1 | package Web::NewsAPI::Article; | ||
| 2 | |||
| 3 | 1 | ▶ | use DateTime; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use DateTime::Format::ISO8601; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | ▶ | use URI; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 1 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 1 | ▶ | use Web::NewsAPI::Types; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | 1 | has 'source' => ( | |
| 13 | is => 'ro', | ||
| 14 | isa => 'Web::NewsAPI::Source', | ||
| 15 | required => 1, | ||
| 16 | ); | ||
| 17 | |||
| 18 | 1 | has 'author' => ( | |
| 19 | is => 'ro', | ||
| 20 | required => 1, | ||
| 21 | isa => 'Maybe[Str]', | ||
| 22 | ); | ||
| 23 | |||
| 24 | 1 | has 'title' => ( | |
| 25 | is => 'ro', | ||
| 26 | required => 1, | ||
| 27 | isa => 'Maybe[Str]', | ||
| 28 | ); | ||
| 29 | |||
| 30 | 1 | has 'description' => ( | |
| 31 | is => 'ro', | ||
| 32 | required => 1, | ||
| 33 | isa => 'Maybe[Str]', | ||
| 34 | ); | ||
| 35 | |||
| 36 | 1 | has 'content' => ( | |
| 37 | is => 'ro', | ||
| 38 | required => 1, | ||
| 39 | isa => 'Maybe[Str]', | ||
| 40 | ); | ||
| 41 | |||
| 42 | 1 | has 'publishedAt' => ( | |
| 43 | is => 'ro', | ||
| 44 | required => 1, | ||
| 45 | coerce => 1, | ||
| 46 | isa => 'NewsDateTime', | ||
| 47 | ); | ||
| 48 | |||
| 49 | 1 | has 'url' => ( | |
| 50 | is => 'ro', | ||
| 51 | required => 1, | ||
| 52 | coerce => 1, | ||
| 53 | isa => 'NewsURI', | ||
| 54 | ); | ||
| 55 | |||
| 56 | 1 | has 'urlToImage' => ( | |
| 57 | is => 'ro', | ||
| 58 | required => 1, | ||
| 59 | coerce => 1, | ||
| 60 | isa => 'NewsURI', | ||
| 61 | ); | ||
| 62 | |||
| 63 | 1 | 1; | |
| 64 | |||
| 65 | =head1 NAME | ||
| 66 | |||
| 67 | Web::NewsAPI::Artcle - Object class representing a News API article | ||
| 68 | |||
| 69 | =head1 SYNOPSIS | ||
| 70 | |||
| 71 | use v5.10; | ||
| 72 | use Web::NewsAPI; | ||
| 73 | |||
| 74 | my $newsapi = Web::NewsAPI->new( | ||
| 75 | api_key => $my_secret_api_key, | ||
| 76 | ); | ||
| 77 | |||
| 78 | say "Here are some top American-news headlines about science..."; | ||
| 79 | my @articles = $newsapi->top_headlines( | ||
| 80 | category => 'science', country => 'us', | ||
| 81 | ); | ||
| 82 | for my $article ( @articles ) { | ||
| 83 | say $article->title; | ||
| 84 | say $article->description; | ||
| 85 | print "\n"; | ||
| 86 | } | ||
| 87 | |||
| 88 | =head1 DESCRIPTION | ||
| 89 | |||
| 90 | Objects of this class represent a News API news article. Generally, you | ||
| 91 | won't create these objects yourself; you'll get them as a result of | ||
| 92 | calling L<methods on a Web::NewsAPI object|Web::NewsAPI/"Object | ||
| 93 | methods">. | ||
| 94 | |||
| 95 | =head1 METHODS | ||
| 96 | |||
| 97 | =head2 Object attributes | ||
| 98 | |||
| 99 | These are all read-only attributes, based on information provided by | ||
| 100 | News API. (They use camelCase because they just copy the attribute names | ||
| 101 | from News API itself.) | ||
| 102 | |||
| 103 | =over | ||
| 104 | |||
| 105 | =item source | ||
| 106 | |||
| 107 | A L<Web::NewsAPI::Source> object. | ||
| 108 | |||
| 109 | =item author | ||
| 110 | |||
| 111 | A string. | ||
| 112 | |||
| 113 | =item title | ||
| 114 | |||
| 115 | A string. | ||
| 116 | |||
| 117 | =item description | ||
| 118 | |||
| 119 | A string. | ||
| 120 | |||
| 121 | =item url | ||
| 122 | |||
| 123 | A L<URI> object. (Possibly undefined.) | ||
| 124 | |||
| 125 | =item urlToImage | ||
| 126 | |||
| 127 | A L<URI> object. (Possibly undefined.) | ||
| 128 | |||
| 129 | =item publishedAt | ||
| 130 | |||
| 131 | A L<DateTime> object. | ||
| 132 | |||
| 133 | |||
| 134 | |||
| 135 | =back | ||
| 136 | |||
| 137 | =head1 AUTHOR | ||
| 138 | |||
| 139 | Jason McIntosh (jmac@jmac.org) | ||