File Coverage

blib/lib/WebService/NextEpisode.pm
Criterion Covered Total %
statement 20 25 80.0
branch 1 2 50.0
condition 1 3 33.3
subroutine 6 6 100.0
pod 1 1 100.0
total 29 37 78.3


line stmt bran cond sub pod time code
1 2     2   159135 use strict;
  2         6  
  2         63  
2 2     2   12 use warnings;
  2         5  
  2         86  
3             package WebService::NextEpisode;
4 2     2   630 use LWP::Simple;
  2         127904  
  2         44  
5 2     2   1528 use HTML::TreeBuilder::XPath;
  2         117725  
  2         20  
6              
7             # ABSTRACT: Fetches air date from next-episode.net
8             our $VERSION = '0.003'; # VERSION
9              
10 2     2   121 use Carp;
  2         5  
  2         448  
11              
12             =pod
13              
14             =encoding utf8
15              
16             =head1 NAME
17              
18             WebService::NextEpisode - Fetch air date from next-episode.net
19              
20              
21             =head1 SYNOPSIS
22              
23             $ perl -MWebService::NextEpisode -e 'print WebService::NextEpisode::of "Better Call Saul"'
24             Mon Jun 05, 2017
25              
26              
27             =head1 METHODS AND ARGUMENTS
28              
29              
30             =over 4
31              
32             =item of($show)
33              
34             Retrieves air date of next epsiode of $show
35              
36             =cut
37              
38             sub of {
39 1     1 1 1259 my ($show_minus, $show) = (shift) x 2;
40              
41 1         5 $show =~ s/ /+/g;
42 1         4 $show_minus =~ s/ /-/g;
43              
44 1   33     8 my $page = get("http://next-episode.net/$show_minus")
45             // get("http://next-episode.net/site-search-$show.html");
46 1 50       213874 defined $page or die "Couldn't get it!";
47              
48 0           my $tree = HTML::TreeBuilder::XPath->new;
49 0           $tree->parse($page);
50              
51 0           my $next = $tree->findvalue( '/html/body//div[@id="next_episode"]');
52              
53 0           $next =~ s/.*Date:(.*)Season.*/$1/;
54              
55 0           return $next;
56             }
57              
58              
59              
60             1;
61             __END__