| 1 | package WWW::EZTV::Show; | ||||||||||
| 2 | { | ||||||||||
| 3 | 2 | $WWW::EZTV::Show::VERSION = '0.05'; | |||||||||
| 4 | } | ||||||||||
| 5 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | with 'WWW::EZTV::UA'; | |||||||||
| 7 | 2 | ▶ | use WWW::EZTV::Link; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use WWW::EZTV::Episode; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | # ABSTRACT: Show object | ||||||||||
| 11 | |||||||||||
| 12 | 2 | has title => is => 'ro', isa => 'Str', required => 1; | |||||||||
| 13 | 2 | has name => is => 'ro', lazy => 1, default => \&_name; | |||||||||
| 14 | 2 | has year => is => 'ro', lazy => 1, default => \&_year; | |||||||||
| 15 | 2 | has url => is => 'ro', isa => 'Mojo::URL', required => 1; | |||||||||
| 16 | 2 | has status => is => 'ro', isa => 'Str', required => 1; | |||||||||
| 17 | 0 | ▶ | has rating => is => 'ro', isa => 'Int', default => sub {0}; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 18 | 2 | has episodes => | |||||||||
| 19 | is => 'ro', | ||||||||||
| 20 | lazy => 1, | ||||||||||
| 21 | builder => '_build_episodes', | ||||||||||
| 22 | handles => { | ||||||||||
| 23 | find_episode => 'first', | ||||||||||
| 24 | has_episodes => 'size', | ||||||||||
| 25 | }; | ||||||||||
| 26 | |||||||||||
| 27 | sub _build_episodes { | ||||||||||
| 28 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_build_episodes: not called CC=1 SCAR=6.9
| |||||||||||
| 29 | $self->get_response($self->url)->dom->find('table.forum_header_noborder tr[name="hover"]')->map(sub{ | ||||||||||
| 30 | 0 | ▶ | my $tr = shift; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 31 | 0 | my $a = $tr->at('td:nth-child(2) a'); | |||||||||
| 32 | |||||||||||
| 33 | WWW::EZTV::Episode->new( | ||||||||||
| 34 | title => $a->attr('title'), | ||||||||||
| 35 | url => $self->url->clone->path($a->attr('href')), | ||||||||||
| 36 | links => $tr->find('td:nth-child(3) a')->map(sub{ | ||||||||||
| 37 | 0 | ▶ | WWW::EZTV::Link->new( url => shift->attr('href') ) | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 38 | 0 | }), | |||||||||
| 39 | released => $tr->at('td:nth-child(4)')->all_text, | ||||||||||
| 40 | show => $self | ||||||||||
| 41 | ); | ||||||||||
| 42 | 0 | }); | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | sub _name { | ||||||||||
| 46 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_name: not called CC=2 SCAR=17.9
| |||||||||||
| 47 | 0 | my $name = $self->title; | |||||||||
| 48 | |||||||||||
| 49 | # Chasers War on Everything, The | ||||||||||
| 50 | 0 | ▶ | if ( $name =~ /^(.+),\s*([^,]+)$/ ) { $name = "$2 $1" } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | |||||||||||
| 52 | # Remove year: Castle (2009) | ||||||||||
| 53 | 0 | $name =~ s/\s* \(\d{4}\) \s*/ /x; | |||||||||
| 54 | |||||||||||
| 55 | # Trim and cleanup spaces | ||||||||||
| 56 | 0 | $self->_cleanup_str($name); | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | sub _year { | ||||||||||
| 60 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_year: not called CC=2 SCAR=17.9
| |||||||||||
| 61 | 0 | ▶ | if ( $self->title =~ /\((\d{4})\)/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 0 | return $1; | |||||||||
| 63 | } | ||||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | sub _cleanup_str { | ||||||||||
| 67 | 0 | ▶ | my $str = pop; | ||||||||
|
Subroutine
_cleanup_str: not called CC=1 SCAR=6.9
| |||||||||||
| 68 | 0 | $str =~ s/^\s+|\s+$//g; | |||||||||
| 69 | 0 | $str =~ s/\s+/ /g; | |||||||||
| 70 | 0 | $str; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | 2 | 1; | |||||||||
| 74 | |||||||||||
| 75 | |||||||||||
| 76 | |||||||||||
| 77 | |||||||||||
| 78 | |||||||||||
| 79 | |||||||||||
| 80 | |||||||||||
| 81 | |||||||||||
| 82 | |||||||||||
| 83 | |||||||||||
| 84 | |||||||||||
| 85 | __END__ | ||||||||||
| 86 | =pod | ||||||||||
| 87 | |||||||||||
| 88 | =encoding UTF-8 | ||||||||||
| 89 | |||||||||||
| 90 | =head1 NAME | ||||||||||
| 91 | |||||||||||
| 92 | WWW::EZTV::Show - Show object | ||||||||||
| 93 | |||||||||||
| 94 | =head1 VERSION | ||||||||||
| 95 | |||||||||||
| 96 | version 0.05 | ||||||||||
| 97 | |||||||||||
| 98 | =head1 ATTRIBUTES | ||||||||||
| 99 | |||||||||||
| 100 | =head2 title | ||||||||||
| 101 | |||||||||||
| 102 | =head2 name | ||||||||||
| 103 | |||||||||||
| 104 | =head2 year | ||||||||||
| 105 | |||||||||||
| 106 | =head2 url | ||||||||||
| 107 | |||||||||||
| 108 | =head2 status | ||||||||||
| 109 | |||||||||||
| 110 | =head2 rating | ||||||||||
| 111 | |||||||||||
| 112 | =head2 episodes | ||||||||||
| 113 | |||||||||||
| 114 | Collection of episodes fetched for this show. | ||||||||||
| 115 | |||||||||||
| 116 | =head2 has_episodes | ||||||||||
| 117 | |||||||||||
| 118 | How many episodes has this show. | ||||||||||
| 119 | |||||||||||
| 120 | =head1 METHODS | ||||||||||
| 121 | |||||||||||
| 122 | =head2 find_episode | ||||||||||
| 123 | |||||||||||
| 124 | Find first L<WWW::EZTV::Episode> object matching the given criteria. | ||||||||||
| 125 | This method accept an anon function. | ||||||||||
| 126 | |||||||||||
| 127 | =head1 AUTHOR | ||||||||||
| 128 | |||||||||||
| 129 | Diego Kuperman <diego@freekeylabs.com> | ||||||||||
| 130 | |||||||||||
| 131 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 132 | |||||||||||
| 133 | This software is copyright (c) 2012 by Diego Kuperman. | ||||||||||
| 134 | |||||||||||
| 135 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 136 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 137 | |||||||||||
| 138 | =cut | ||||||||||
| 139 | |||||||||||