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   7 use DateTime;
  1         3  
  1         32  
4 1     1   520 use DateTime::Format::ISO8601;
  1         91371  
  1         56  
5              
6 1     1   11 use URI;
  1         2  
  1         23  
7              
8 1     1   23 use Moose;
  1         3  
  1         11  
9              
10 1     1   7778 use Web::NewsAPI::Types;
  1         18  
  1         166  
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 @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)