File Coverage

lib/Web/NewsAPI/Article.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


line stmt bran cond sub pod time code
1             package Web::NewsAPI::Article;
2              
3 1     1   8 use DateTime;
  1         2  
  1         35  
4 1     1   547 use DateTime::Format::ISO8601;
  1         93241  
  1         81  
5              
6 1     1   11 use URI;
  1         2  
  1         27  
7              
8 1     1   6 use Moose;
  1         2  
  1         10  
9              
10 1     1   8138 use Web::NewsAPI::Types;
  1         3  
  1         169  
11              
12             has 'source' => (
13             is => 'ro',
14             isa => 'Web::NewsAPI::Source',
15             required => 1,
16             );
17              
18             has 'author' => (
19             is => 'ro',
20             required => 1,
21             isa => 'Maybe[Str]',
22             );
23              
24             has 'title' => (
25             is => 'ro',
26             required => 1,
27             isa => 'Maybe[Str]',
28             );
29              
30             has 'description' => (
31             is => 'ro',
32             required => 1,
33             isa => 'Maybe[Str]',
34             );
35              
36             has 'content' => (
37             is => 'ro',
38             required => 1,
39             isa => 'Maybe[Str]',
40             );
41              
42             has 'publishedAt' => (
43             is => 'ro',
44             required => 1,
45             coerce => 1,
46             isa => 'NewsDateTime',
47             );
48              
49             has 'url' => (
50             is => 'ro',
51             required => 1,
52             coerce => 1,
53             isa => 'NewsURI',
54             );
55              
56             has 'urlToImage' => (
57             is => 'ro',
58             required => 1,
59             coerce => 1,
60             isa => 'NewsURI',
61             );
62              
63             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 $result = $newsapi->top_headlines(
80             category => 'science', country => 'us',
81             );
82             # $result is now a Web::NewsAPI::Result object.
83             # We can call its 'articles' method to get a list of article objects:
84             for my $article ( $result->articles ) {
85             say $article->title;
86             say $article->description;
87             print "\n";
88             }
89              
90             =head1 DESCRIPTION
91              
92             Objects of this class represent a News API news article. Generally, you
93             won't create these objects yourself; you'll get them as a result of
94             calling methods on a L<Web::NewsAPI> object or a L<Web::NewsAPI::Result>
95             object.
96              
97             =head1 METHODS
98              
99             =head2 Object attributes
100              
101             These are all read-only attributes, based on information provided by
102             News API. (They use camelCase because they just copy the attribute names
103             from News API itself.)
104              
105             =head3 source
106              
107             my $source = $article->source;
108             say "The source of this article was " . $source->name;
109              
110             A L<Web::NewsAPI::Source> object.
111              
112             =head3 author
113              
114             my $author = $article->author;
115             say "$author wrote this article.";
116              
117             A string.
118              
119             =head3 title
120              
121             my $title = $article->title;
122              
123             A string.
124              
125             =head3 description
126              
127             my $description = $article->description;
128              
129             =head3 url
130              
131             my $url = $article->url;
132              
133             A L<URI> object. (Possibly undefined.)
134              
135             =head3 urlToImage
136              
137             my $image_url = $article->urlToImage;
138              
139             A L<URI> object. (Possibly undefined.)
140              
141             =head3 publishedAt
142              
143             my $publication_datetime = $article->publishedAt;
144              
145             A L<DateTime> object.
146              
147             =head1 AUTHOR
148              
149             Jason McIntosh (jmac@jmac.org)