Initial commit
[cascardo/www-eztv.git] / lib / WWW / EZTV.pm
1 package WWW::EZTV;
2 use Moose;
3 with 'WWW::EZTV::UA';
4 use WWW::EZTV::Show;
5
6 has url       => ( is => 'ro', lazy => 1, default => sub { Mojo::URL->new('http://eztv.it/') } );
7 has url_shows => ( is => 'ro', lazy => 1, default => sub { shift->url->clone->path('/showlist/') } );
8 has shows => 
9     is      => 'ro',
10     lazy    => 1,
11     default => \&build_shows,
12     handles => {
13         find_show    => 'first',
14         has_shows    => 'size',
15     };
16
17 sub build_shows {
18     my $self = shift;
19
20     $self->get_response( $self->url_shows )->dom->find('table.forum_header_border tr[name="hover"]')->map(sub {
21         my $tr = shift;
22         my $link = $tr->at('td:nth-child(1) a');
23         WWW::EZTV::Show->new(
24             title  => $link->all_text,
25             url    => $self->url->clone->path($link->attrs('href')),
26             status => lc($tr->at('td:nth-child(2)')->all_text),
27             rating => $tr->at('td:nth-child(3)')->all_text
28         );
29     });
30 }
31
32 1;