File Coverage

blib/lib/WWW/OReillyMedia/Store.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package WWW::OReillyMedia::Store;
2              
3             $WWW::OReillyMedia::Store::VERSION = '0.07';
4              
5             =head1 NAME
6              
7             WWW::OReillyMedia::Store - Interface to the OReilly Media Store.
8              
9             =head1 VERSION
10              
11             Version 0.07
12              
13             =cut
14              
15 1     1   25113 use 5.006;
  1         4  
  1         42  
16 1     1   1005 use Data::Dumper;
  1         10793  
  1         95  
17              
18 1     1   575 use XML::Simple;
  0            
  0            
19             use LWP::Simple;
20             use WWW::OReillyMedia::Store::Book;
21              
22             use Moo;
23             use namespace::clean;
24              
25             my $NEW_BOOKS = "http://feeds.feedburner.com/oreilly/newbooks?format=xml";
26             my $UPCOMING_BOOKS = "http://feeds.feedburner.com/oreilly/upcomingbooks?format=xml";
27              
28             has 'new_books_url' => (is => 'ro', default => sub { return $NEW_BOOKS; });
29             has 'upcoming_books_url' => (is => 'ro', default => sub { return $UPCOMING_BOOKS; });
30              
31             =head1 SYNOPSIS
32              
33             Objective of this module is to provide an interface to the OReilly online media
34             store. This rely on the RSS feed made public by OReilly.
35              
36             use strict; use warnings;
37             use WWW::OReillyMedia::Store;
38              
39             my $store = WWW::OReillyMedia::Store->new;
40              
41             my $new_books = $store->new_books;
42             my $upcoming_books = $store->upcoming_books;
43              
44             print $new_books->[0]->as_string();
45             print $upcoming_books->[0]->as_string();
46              
47             =head1 METHODS
48              
49             =head2 new_books()
50              
51             Fetches new books details from OReilly online store realtime. It returns the ref
52             to a list of objects of type L.
53              
54             =cut
55              
56             sub new_books {
57             my ($self) = @_;
58              
59             return $self->_fetch($self->new_books_url);
60             }
61              
62             =head2 upcoming_books()
63              
64             Fetches upcoming books details from OReilly online store realtime. It returns the
65             ref to a list of objects of type L.
66              
67             =cut
68              
69             sub upcoming_books {
70             my ($self) = @_;
71              
72             return $self->_fetch($self->upcoming_books_url);
73             }
74              
75             sub _fetch {
76             my ($url) = @_;
77              
78             my $books = [];
79             my $xml = get($url);
80             my $feeds = XMLin($xml);
81             foreach my $catalog (keys %{$feeds->{entry}}) {
82             my $title = $feeds->{entry}->{$catalog}->{title};
83             push @$books, WWW::OReillMedia::Store::Book->new({ title => $title, catalog => $catalog });
84             }
85              
86             return $books;
87             }
88              
89             =head1 AUTHOR
90              
91             Mohammad S Anwar, C<< >>
92              
93             =head1 REPOSITORY
94              
95             L
96              
97             =head1 BUGS
98              
99             Please report any bugs or feature requests to C
100             rt.cpan.org>, or through the web interface at L.
101             I will be notified, and then you'll automatically be notified of progress on your
102             bug as I make changes.
103              
104             =head1 SUPPORT
105              
106             You can find documentation for this module with the perldoc command.
107              
108             perldoc WWW::OReillyMedia::Store
109              
110             You can also look for information at:
111              
112             =over 4
113              
114             =item * RT: CPAN's request tracker
115              
116             L
117              
118             =item * AnnoCPAN: Annotated CPAN documentation
119              
120             L
121              
122             =item * CPAN Ratings
123              
124             L
125              
126             =item * Search CPAN
127              
128             L
129              
130             =back
131              
132             =head1 LICENSE AND COPYRIGHT
133              
134             Copyright (C) 2011 - 2014 Mohammad S Anwar.
135              
136             This program is free software; you can redistribute it and/or modify it under
137             the terms of the the Artistic License (2.0). You may obtain a copy of the full
138             license at:
139              
140             L
141              
142             Any use, modification, and distribution of the Standard or Modified Versions is
143             governed by this Artistic License.By using, modifying or distributing the Package,
144             you accept this license. Do not use, modify, or distribute the Package, if you do
145             not accept this license.
146              
147             If your Modified Version has been derived from a Modified Version made by someone
148             other than you,you are nevertheless required to ensure that your Modified Version
149             complies with the requirements of this license.
150              
151             This license does not grant you the right to use any trademark, service mark,
152             tradename, or logo of the Copyright Holder.
153              
154             This license includes the non-exclusive, worldwide, free-of-charge patent license
155             to make, have made, use, offer to sell, sell, import and otherwise transfer the
156             Package with respect to any patent claims licensable by the Copyright Holder that
157             are necessarily infringed by the Package. If you institute patent litigation
158             (including a cross-claim or counterclaim) against any party alleging that the
159             Package constitutes direct or contributory patent infringement,then this Artistic
160             License to you shall terminate on the date that such litigation is filed.
161              
162             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
163             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
164             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
165             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
166             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
167             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
168             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
169              
170             =cut
171              
172             1; # End of WWW::OReillyMedia::Store