File Coverage

lib/Web/NewsAPI/Source.pm
Criterion Covered Total %
statement 8 8 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 11 11 100.0


line stmt bran cond sub pod time code
1             package Web::NewsAPI::Source;
2              
3 1     1   21 use v5.10;
  1         4  
4 1     1   6 use Moose;
  1         2  
  1         7  
5              
6 1     1   5341 use Web::NewsAPI::Types;
  1         4  
  1         152  
7              
8             has 'id' => (
9             required => 1,
10             isa => 'Maybe[Str]',
11             is => 'ro',
12             );
13              
14             has 'name' => (
15             required => 1,
16             isa => 'Str',
17             is => 'ro',
18             );
19              
20             has 'description' => (
21             isa => 'Str',
22             is => 'ro',
23             );
24              
25             has 'category' => (
26             isa => 'Str',
27             is => 'ro',
28             );
29              
30             has 'language' => (
31             isa => 'Str',
32             is => 'ro',
33             );
34              
35             has 'country' => (
36             isa => 'Str',
37             is => 'ro',
38             );
39              
40             has 'url' => (
41             coerce => 1,
42             isa => 'NewsURI',
43             is => 'ro',
44             );
45              
46             1;
47              
48             =head1 NAME
49              
50             Web::NewsAPI::Source - Object class representing a News API source
51              
52             =head1 SYNOPSIS
53              
54             use v5.10;
55             use Web::NewsAPI;
56              
57             my $newsapi = Web::NewsAPI->new(
58             api_key => $my_secret_api_key,
59             );
60              
61             say "Here are some sources for English-language science news...";
62             my @sources = $newsapi->sources(
63             category => 'science',
64             language => 'en'
65             );
66             for my $source ( @sources ) {
67             say $source->name;
68             if ( defined $source->id ) {
69             say "...it has the NewsAPI ID " . $source->id;
70             }
71             else {
72             say "...but it doesn't have a NewsAPI ID.";
73             }
74             }
75              
76             =head1 DESCRIPTION
77              
78             Objects of this class represent a News API news source. Generally, you
79             won't create these objects yourself; you'll get them as a result of
80             calling L<sources() on a Web::NewsAPI object|Web::NewsAPI/"sources">.
81              
82             =head1 METHODS
83              
84             =head2 Object attributes
85              
86             These are all read-only attributes, based on information provided by
87             News API. They are all strings, except for C<url>, which is a L<URI>
88             object. Any of them might be undefined, except for C<name>.
89              
90             =head3 id
91              
92             my $id = $source->id;
93              
94             =head3 name
95              
96             my $name = $source->name;
97              
98             =head3 description
99              
100             my $desc = $source->description;
101              
102             =head3 url
103              
104             my $url = $source->url;
105              
106             =head3 category
107              
108             my $category = $source->category;
109              
110             =head3 language
111              
112             my $language_code = $source->language;
113              
114             =head3 country
115              
116             my $country_code = $source_country;
117              
118             =head1 AUTHOR
119              
120             Jason McIntosh (jmac@jmac.org)