File Coverage

blib/lib/Net/TiVo/Show.pm
Criterion Covered Total %
statement 12 36 33.3
branch 0 4 0.0
condition n/a
subroutine 4 6 66.6
pod 1 2 50.0
total 17 48 35.4


line stmt bran cond sub pod time code
1             # $Id: Show.pm 57 2007-01-12 19:26:09Z boumenot $
2             # Author: Christopher Boumenot
3             ######################################################################
4             #
5             # Copyright 2006-2007 by Christopher Boumenot. This program is free
6             # software; you can redistribute it and/or modify it under the same
7             # terms as Perl itself.
8             #
9             ######################################################################
10              
11             package Net::TiVo::Show;
12              
13 1     1   1531 use strict;
  1         2  
  1         39  
14 1     1   25 use warnings;
  1         2  
  1         38  
15 1     1   6 use base qw(Net::TiVo::Folder);
  1         1  
  1         103  
16              
17 1     1   6 use Text::Wrap;
  1         2  
  1         660  
18              
19             # Should be read as a poor man's XPath
20             our %DEFAULT_ATTRIBUTES_XPATH = (
21             station => [qw(Details SourceStation)],
22             name => [qw(Details Title)],
23             episode => [qw(Details EpisodeTitle)],
24             episode_num => [qw(Details EpisodeNumber)],
25             content_type => [qw(Details ContentType)],
26             capture_date => [qw(Details CaptureDate)],
27             format => [qw(Details SourceFormat)],
28             high_definition => [qw(Details HighDefinition)],
29             in_progress => [qw(Details InProgress)],
30             size => [qw(Details SourceSize)],
31             channel => [qw(Details SourceChannel)],
32             duration => [qw(Details Duration)],
33             description => [qw(Details Description)],
34             series_id => [qw(Details SeriesId)],
35             program_id => [qw(Details ProgramId)],
36             url => [qw(Links Content Url)],
37             );
38              
39             __PACKAGE__->make_accessor($_) for keys %DEFAULT_ATTRIBUTES_XPATH;
40             __PACKAGE__->make_accessor($_) for qw(tuner);
41              
42             sub new {
43 0     0 0   my ($class, %options) = @_;
44            
45 0 0         unless ($options{xmlref}) {
46 0           die __PACKAGE__ . ": Mandatory param xmlref missing\n";
47             }
48              
49 0           my $self = {
50             %options,
51             };
52              
53 0           bless $self, $class;
54              
55 0           for my $attr (keys %DEFAULT_ATTRIBUTES_XPATH) {
56 0           my $value = __PACKAGE__->walk_hash_ref($options{xmlref}, $DEFAULT_ATTRIBUTES_XPATH{$attr});
57 0           $self->$attr($value);
58             }
59              
60             # do a little post processing
61 0           $self->capture_date(hex($self->capture_date()));
62              
63 0           my ($channel, $tuner) = split(/\-/, $self->channel());
64 0 0         $tuner = 0 unless defined $tuner;
65 0           $self->channel($channel);
66 0           $self->tuner($tuner);
67              
68 0           return $self;
69             }
70              
71             sub as_string {
72 0     0 1   my $self = shift;
73              
74 0           $Text::Wrap::columns = 72;
75              
76 0           my @a;
77 0           push @a, $self->name();
78 0           push @a, $self->episode();
79 0           push @a, $self->description();
80 0           push @a, int(($self->duration() / (60 * 1000)) + 0.5) . " min";
81              
82 0           my $s = wrap("", " ", join(", ", @a));
83 0           $s .= "\n ".$self->url();
84              
85 0           return $s;
86             }
87              
88             1;
89              
90             __END__