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 1     1   69716 use strict;
  1         3  
  1         38  
2 1     1   7 use warnings;
  1         3  
  1         51  
3             package WebService::NextEpisode;
4 1     1   382 use LWP::Simple;
  1         55830  
  1         8  
5 1     1   706 use HTML::TreeBuilder::XPath;
  1         50641  
  1         9  
6              
7             # ABSTRACT: Fetches air date from next-episode.net
8             our $VERSION = '0.002'; # VERSION
9              
10 1     1   50 use Carp;
  1         2  
  1         179  
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 76 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     7 my $page = get("http://next-episode.net/$show_minus")
45             // get("http://next-episode.net/site-search-$show.html");
46 1 50       208130 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__