Fixed dzil errors and warns...
[cascardo/www-eztv.git] / lib / WWW / EZTV / Episode.pm
1 package WWW::EZTV::Episode;
2
3 use Moose;
4 with 'WWW::EZTV::UA';
5
6 # ABSTRACT: Show episode
7
8 has show     => is => 'ro', isa => 'WWW::EZTV::Show', required => 1;
9 has title    => is => 'ro', isa => 'Str', required => 1;
10 has url      => is => 'ro', isa => 'Mojo::URL', required => 1;
11 has links    => 
12     is      => 'ro',
13     handles => {
14         find_link => 'first',
15         has_links => 'size',
16     };
17
18 has _parsed  => is => 'ro', lazy => 1, builder => '_parse';
19
20 has name     => is => 'ro', lazy => 1, 
21     default  => sub { shift->_parsed->{name} };
22
23 has season     => is => 'ro', lazy => 1, 
24     default  => sub { shift->_parsed->{season} };
25
26 has number     => is => 'ro', lazy => 1, 
27     default  => sub { shift->_parsed->{number} };
28
29 has version     => is => 'ro', lazy => 1, 
30     default  => sub { shift->_parsed->{version} };
31
32 has quality     => is => 'ro', lazy => 1, 
33     default  => sub { shift->_parsed->{quality} || 'standard' };
34
35 has size     => is => 'ro', lazy => 1,
36     default  => sub { shift->_parsed->{size} };
37
38 sub _parse {
39     my $title = shift->title;
40
41     $title =~ /^\s*
42       (?<name>.+?)
43       \s+
44       (?<chapter>
45         S (?<season>\d+) E (?<number>\d+)
46        |(?<season>\d+) x (?<number>\d+)
47        |(?<number>\d+) of (?<total>\d+)
48       )
49       \s+
50       (?<version>
51         ((?<quality>\d+p)\s+)?
52         (?<team>.*?)
53       )
54       (?:
55         \s+
56         \((?<size>
57           \d+
58           [^\)]+
59         )\)
60       )?
61     \s*$/xi;
62
63     return {
64         name    => $+{name} || $title,
65         chapter => $+{chapter},
66         number  => ($+{number}||0) +0,
67         season  => ($+{season}||0) +0,
68         total   => ($+{total}||0) +0,
69         version => $+{version} || '',
70         quality => $+{quality} || 'standard',
71         team    => $+{team},
72         size    => $+{size}
73     };
74 }
75
76 1;
77
78 =attr has_links
79
80 How many episodes has this show.
81
82 =cut
83
84 =method find_link
85
86 Find first L<WWW::EZTV::Link> object matching the given criteria. 
87 This method accept an anon function.
88
89 =cut