| 1 | package Net::AnimeNewsNetwork::Encyclopedia; | ||
| 2 | 2 | ▶ | use 5.10.0; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 2 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 2 | ▶ | use Data::Validator; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 2 | ▶ | use URI; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 2 | ▶ | use LWP::Simple; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 2 | ▶ | use XML::Simple; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 2 | our $VERSION = "0.02"; | |
| 12 | 2 | our $URL = 'http://cdn.animenewsnetwork.com/encyclopedia'; | |
| 13 | |||
| 14 | 2 | has url => ( | |
| 15 | is => 'ro', | ||
| 16 | default => $URL, | ||
| 17 | ); | ||
| 18 | |||
| 19 | 1 | ▶ | sub get_reports { |
|
Subroutine
get_reports: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 20 | 1 | state $rule = Data::Validator->new( | |
| 21 | id => 'Int', | ||
| 22 | type => 'Str', | ||
| 23 | nskip => { isa => 'Int', optional => 1 }, | ||
| 24 | nlist => { isa => 'Int', optional => 1 }, | ||
| 25 | name => { isa => 'Str', optional => 1 }, | ||
| 26 | )->with('Method'); | ||
| 27 | 1 | my ($self, $args) = $rule->validate(@_); | |
| 28 | |||
| 29 | 1 | my $content = $self->_get("/reports.xml", $args); | |
| 30 | 1 | return XMLin($content); | |
| 31 | } | ||
| 32 | |||
| 33 | 1 | ▶ | sub get_details { |
|
Subroutine
get_details: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 34 | 1 | state $rule = Data::Validator->new( | |
| 35 | anime => { isa => 'Int', xor => [qw/manga title/] }, | ||
| 36 | manga => { isa => 'Int', xor => [qw/anime title/] }, | ||
| 37 | title => { isa => 'Int', xor => [qw/anime manga/] }, | ||
| 38 | )->with('Method'); | ||
| 39 | 1 | my ($self, $args) = $rule->validate(@_); | |
| 40 | |||
| 41 | 1 | my $content = $self->_get("/api.xml", $args); | |
| 42 | 1 | return XMLin($content); | |
| 43 | } | ||
| 44 | |||
| 45 | 2 | ▶ | sub _get { |
|
Subroutine
_get: called CC=1 SCAR=0.0
| |||
| 46 | 2 | my ($self, $path, $query) = @_; | |
| 47 | 2 | my $uri = URI->new($self->url . $path); | |
| 48 | 2 | $uri->query_form($query); | |
| 49 | 2 | return get($uri); | |
| 50 | } | ||
| 51 | |||
| 52 | 2 | 1; | |
| 53 | __END__ | ||