split out HTML::hCalendar
[HTML5TV.git] / lib / HTML5TV / hCalendar.pm
1 package HTML5TV::hCalendar;
2
3 use warnings;
4 use strict;
5
6 use File::Slurp;
7 use HTML::TreeBuilder;
8 use Data::Dump qw/dump/;
9
10 sub new {
11         my $class = shift;
12         my $path = shift || die "need path to hCalendar";
13
14         my $tree = HTML::TreeBuilder->new;
15         $tree->parse_file($path);
16
17         my $self = {
18                 path => $path,
19                 tree => $tree,
20         };
21         bless $self, $class;
22         return $self;
23 }
24
25 # we don't want DESTROY to fallback into AUTOLOAD
26 sub DESTROY {}
27
28 our $AUTOLOAD;
29 sub AUTOLOAD {
30         my $self = shift;
31
32     my $class = $AUTOLOAD;
33     $class =~ s/.*://;
34
35 warn "XX $class\n";
36
37         if ( my $vevent = $self->{tree}->look_down( class => 'vevent' ) ) {
38                 if ( my $el = $vevent->look_down( class => $class ) ) {
39                         return $el->as_trimmed_text;
40                 } else {
41                         die "can't find vevent.$class in ", $self->{path};
42                 }
43         } else {
44                 die "can't find vevent in ", $self->{path};
45         }
46
47 }
48
49 1;