File Coverage

blib/lib/WWW/NOS/Open/Document.pm
Criterion Covered Total %
statement 29 29 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod n/a
total 39 39 100.0


line stmt bran cond sub pod time code
1             # -*- cperl; cperl-indent-level: 4 -*-
2             # Copyright (C) 2011-2021, Roland van Ipenburg
3             package WWW::NOS::Open::Document v1.0.5;
4 4     4   29 use strict;
  4         8  
  4         120  
5 4     4   19 use warnings;
  4         8  
  4         107  
6              
7 4     4   18 use utf8;
  4         7  
  4         36  
8 4     4   137 use 5.014000;
  4         14  
9              
10 4     4   23 use Moose qw/has/;
  4         6  
  4         36  
11 4     4   18092 use Moose::Util::TypeConstraints qw/enum/;
  4         9  
  4         32  
12 4     4   1608 use namespace::autoclean '-also' => qr/^__/sxm;
  4         10  
  4         42  
13              
14 4     4   351 use WWW::NOS::Open::TypeDef qw(NOSDateTime NOSURI);
  4         9  
  4         45  
15              
16 4     4   5112 use Readonly;
  4         9  
  4         1372  
17             Readonly::Scalar my $UNDER => q{_};
18             Readonly::Scalar my $GETTER => q{get};
19             Readonly::Array my @CATEGORIES => qw(Nieuws Sport);
20             Readonly::Array my @RESOURCE_TYPES => qw(artikel article video audio);
21              
22             has '_id' => (
23             'is' => 'ro',
24             'isa' => 'Str',
25             'reader' => 'get_id',
26             'init_arg' => 'id',
27             );
28              
29             has '_score' => (
30             'is' => 'ro',
31             'isa' => 'Num',
32             'reader' => 'get_score',
33             'init_arg' => 'score',
34             );
35              
36             has '_type' => (
37             'is' => 'ro',
38             'isa' => enum( [@RESOURCE_TYPES] ),
39             'reader' => $GETTER . $UNDER . 'type',
40             'init_arg' => 'type',
41             );
42              
43             my @strings = qw(title description subcategory);
44             while ( my $string = shift @strings ) {
45             has $UNDER
46             . $string => (
47             'is' => 'ro',
48             'isa' => 'Str',
49             'reader' => $GETTER . $UNDER . $string,
50             'init_arg' => $string,
51             );
52             }
53              
54             my @dates = qw(published last_update);
55             while ( my $date = shift @dates ) {
56             has $UNDER
57             . $date => (
58             'is' => 'ro',
59             'isa' => NOSDateTime,
60             'coerce' => 1,
61             'reader' => $GETTER . $UNDER . $date,
62             'init_arg' => $date,
63             );
64             }
65              
66             my @uris = qw(thumbnail link);
67             while ( my $uri = shift @uris ) {
68             has $UNDER
69             . $uri => (
70             'is' => 'ro',
71             'isa' => NOSURI,
72             'coerce' => 1,
73             'reader' => $GETTER . $UNDER . $uri,
74             'init_arg' => $uri,
75             );
76             }
77              
78             has '_category' => (
79             'is' => 'ro',
80             'isa' => enum( [@CATEGORIES] ),
81             'reader' => 'get_category',
82             'init_arg' => 'category',
83             );
84              
85             has '_keywords' => (
86             'is' => 'ro',
87             'isa' => 'ArrayRef[Str]',
88             'reader' => 'get_keywords',
89             'init_arg' => 'keywords',
90             );
91              
92 4     4   28 no Moose;
  4         8  
  4         20  
93              
94             __PACKAGE__->meta->make_immutable;
95              
96             1;
97              
98             __END__
99              
100             =encoding utf8
101              
102             =for stopwords Bitbucket DateTime URI Readonly Ipenburg MERCHANTABILITY
103              
104             =head1 NAME
105              
106             WWW::NOS::Open::Document - client side document in the Open NOS REST API.
107              
108             =head1 VERSION
109              
110             This document describes WWW::NOS::Open::Document version C<v1.0.5>.
111              
112             =head1 SYNOPSIS
113              
114             use WWW::NOS::Open::Document;
115              
116             =head1 DESCRIPTION
117              
118             This class represents the documents that appear in the search results.
119              
120             =head1 SUBROUTINES/METHODS
121              
122             =head2 C<new>
123              
124             Create a new document object.
125              
126             =over
127              
128             =item 1. A hash containing the properties and their values.
129              
130             =back
131              
132             =head2 C<get_id>
133              
134             Returns the id of the document as string.
135              
136             =head2 C<get_type>
137              
138             Returns the type of the document as string C<article>, C<artikel>, C<audio> or
139             C<video>.
140              
141             =head2 C<get_title>
142              
143             Returns the title of the document as string.
144              
145             =head2 C<get_description>
146              
147             Returns the description of the document as string.
148              
149             =head2 C<get_published>
150              
151             Returns the publishing date of the document as a L<DateTime|DateTime> object.
152              
153             =head2 C<get_last_update>
154              
155             Returns the date of the last update for the document as a L<DateTime|DateTime>
156             object.
157              
158             =head2 C<get_thumbnail>
159              
160             Returns the URL of the thumbnail for the document as an L<URI|URI> object.
161              
162             =head2 C<get_link>
163              
164             Returns the URL of the main document as an L<URI|URI> object.
165              
166             =head2 C<get_keywords>
167              
168             Returns the list of keywords for the document as a reference to an array of
169             strings.
170              
171             =head2 C<get_score>
172              
173             Returns the score of the document as ranked in the results as a number.
174              
175             =head1 CONFIGURATION AND ENVIRONMENT
176              
177             =head1 DEPENDENCIES
178              
179             =over 4
180              
181             =item * L<Moose::Util::TypeConstraints|Moose::Util::TypeConstraints>
182              
183             =item * L<Moose|Moose>
184              
185             =item * L<Readonly|Readonly>
186              
187             =item * L<WWW::NOS::Open::TypeDef|WWW::NOS::Open::TypeDef>
188              
189             =item * L<namespace::autoclean|namespace::autoclean>
190              
191             =back
192              
193             =head1 INCOMPATIBILITIES
194              
195             Until the API settles the resource type supports both C<artikel> and
196             C<article> for an article type resource.
197              
198             =head1 DIAGNOSTICS
199              
200             =head1 BUGS AND LIMITATIONS
201              
202             Please report any bugs or feature requests at
203             L<Bitbucket|https://bitbucket.org/rolandvanipenburg/www-nos-open/issues>.
204              
205             =head1 AUTHOR
206              
207             Roland van Ipenburg, E<lt>roland@rolandvanipenburg.comE<gt>
208              
209             =head1 LICENSE AND COPYRIGHT
210              
211             Copyright 2011-2021 by Roland van Ipenburg
212              
213             This library is free software; you can redistribute it and/or modify
214             it under the same terms as Perl itself, either Perl version 5.14.0 or,
215             at your option, any later version of Perl 5 you may have available.
216              
217             =head1 DISCLAIMER OF WARRANTY
218              
219             BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
220             FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
221             OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
222             PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
223             EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
224             WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
225             ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
226             YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
227             NECESSARY SERVICING, REPAIR, OR CORRECTION.
228              
229             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
230             WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
231             REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE
232             LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
233             OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
234             THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
235             RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
236             FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
237             SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
238             SUCH DAMAGES.
239              
240             =cut