Initial commit
[cascardo/www-eztv.git] / lib / WWW / EZTV / UA.pm
1 package WWW::EZTV::UA;
2 use Moose::Role;
3 use Mojo::UserAgent;
4
5 has ua  => ( is => 'ro', lazy => 1, default => sub { $EZTV::Global::UA || ($EZTV::Global::UA = Mojo::UserAgent->new) } );
6
7 sub get_response {
8     my ($self, $url) = (shift, shift);
9
10     my $tx = $self->ua->get( $url );
11     if ( my $res = $tx->success ) {
12         return $res;
13     }
14     else {
15         my ($err, $code) = $tx->error;
16         my $message = shift || 'User agent error';
17         die "$message: $err ($code)";
18     }
19 }
20
21 1;