TiVo/Folder.pm

filter: Statementstmt 89.8% 222 / 247 Branchbran 75.3% 98 / 130 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 41 / 41 Podpod 16.6% 1 / 6 totaltotal 84.6% 363 / 429 CC 71 SCAR 11.4
CC
71
Cov
84%
__ANON__
5.9
new
5.0
walk_hash_ref
4.0
CRAP 3.1
« TiVo.pm ↑ Summary TiVo/Show.pm »
1 # $Id: Folder.pm 57 2007-01-12 19:26:09Z boumenot $
2 # Author: Christopher Boumenot <boumenot@gmail.com>
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::Folder;
12  
13 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 4 ▶use Text::Wrap;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use Log::Log4perl qw(:easy get_logger);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # Should be read as a poor man's XPath
20 4 our %DEFAULT_ATTRIBUTES_XPATH = (
21 content_type => [qw(Details ContentType)],
22 format => [qw(Details SourceFormat)],
23 change_date => [qw(Details LastChangeDate)],
24 name => [qw(Details Title)],
25 total_items => [qw(Details TotalItems)],
26 # Is this the same thing as total_items()?
27 item_count => [qw(ItemCount)],
28 # What value is this?
29 item_start => [qw(ItemStart)],
30 global_sort => [qw(GlobalSort)],
31 sort_order => [qw(SortOrder)],
32 # Due to the way folders are created it is difficult
33 # to get the url of the folder. I could add it easily
34 # enough, but it would be a hack, and I'm not sure
35 # that you really need the url of the folder. I need
36 # to fix the code.
37 #url
38 );
39  
40 4 __PACKAGE__->make_accessor($_) for keys %DEFAULT_ATTRIBUTES_XPATH;
41 4 __PACKAGE__->make_accessor($_) for qw(size);
42 4 __PACKAGE__->make_array_accessor($_) for qw(shows);
43  
44 8 ▶sub TIVO_MIME_TYPES { qw(video/x-tivo-mpeg video/x-tivo-raw-pes video/x-tivo-raw-tts) }
Subroutine TIVO_MIME_TYPES: called CC=1 SCAR=0.0
Pod undocumented
45  
46 3 ▶sub new {
Subroutine new: called CC=5 SCAR=16.2
Pod undocumented
47 3 my ($class, %options) = @_;
48
49 3 ▶ unless ($options{xmlref}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($options{"xmlref"}) 0 3 3
50 0 die __PACKAGE__ . ": Mandatory param xmlref missing\n";
51 }
52  
53 3 my $self = {
54 %options,
55 };
56  
57 3 bless $self, $class;
58  
59 3 for my $attr (keys %DEFAULT_ATTRIBUTES_XPATH) {
60 27 my $value = __PACKAGE__->walk_hash_ref($options{xmlref}, $DEFAULT_ATTRIBUTES_XPATH{$attr});
61 27 $self->$attr($value);
62 }
63  
64 3 $self->change_date(hex($self->change_date()));
65  
66 # DEBUG(sub { Data::Dumper::Dumper($options{xmlref}) });
67  
68 3 my ($size, @shows);
69 3 for my $show (@{$options{xmlref}->{Item}}) {
70 8 ▶ if (grep {$show->{Links}->{Content}->{ContentType} eq $_} TIVO_MIME_TYPES) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$show->{"Links"}{"Content"}{"ContentType"} eq $_;} TIVO_MIME_TYPES()) 8 0 8
71 8 push @shows, Net::TiVo::Show->new(xmlref => $show);
72 8 INFO("added the show " . $shows[-1]->name());
73 8 $size += $shows[-1]->size();
74 }
75 }
76  
77 3 $self->size($size);
78 3 $self->shows(\@shows);
79
80 3 return $self;
81 }
82  
83 1 ▶sub _commify {
Subroutine _commify: called CC=1 SCAR=0.0
84 1 my ($self, $num) = @_;
85 1 $num = reverse $num;
86 1 $num =~ s<(\d\d\d)(?=\d)(?!\d*\.)><$1,>g;
87 1 $num = reverse $num;
88 1 return $num;
89 }
90  
91 1 ▶sub as_string {
Subroutine as_string: called CC=2 SCAR=7.0
Pod documented
92 1 my $self = shift;
93  
94 1 $Text::Wrap::columns = 72;
95  
96 1 my @a;
97 1 push @a, $self->name();
98 1 ▶ push @a, sprintf("%d %s", $self->total_items(), (($self->total_items() > 1) ? "episodes" : "episode"));
Branch: 1 branch
BranchTrueFalseTotal
$self->total_items > 1 ? : 1 0 1
99 1 push @a, sprintf("%s bytes", $self->_commify($self->size()));
100 1 my $s = wrap("", " ", join(", ", @a));
101 1 return $s;
102 }
103  
104 # cmb - taken from the excellent Net::Amazon!
105 108 ▶sub make_accessor {
Subroutine make_accessor: called CC=3 SCAR=11.1
Pod undocumented
106 108 my($package, $name) = @_;
107  
108 4 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
109  
110 108 my $code = <<EOT;
111 *{"$package\\::$name"} = sub {
112 my(\$self, \$value) = \@_;
113  
114 if(defined \$value) {
115 \$self->{$name} = \$value;
116 }
117 if(exists \$self->{$name}) {
118 return (\$self->{$name});
119 } else {
120 return "";
121 }
122 }
123 EOT
124 108 ▶ if(! defined *{"$package\::$name"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined *{"${package}::$name";}) 108 0 108
125 0 ▶ eval $code or die "$@";
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Subroutine __ANON__: called CC=3 SCAR=11.1
Branch: 55 branches
BranchTrueFalseTotal
eval $code or die "$@" 108 0 108
if (defined $value) 3 4 7
if (exists $self->{'global_sort'}) { } 7 0 7
if (defined $value) 4 4 8
if (exists $self->{'change_date'}) { } 8 0 8
if (defined $value) 5 3 8
if (exists $self->{'sort_order'}) { } 8 0 8
if (defined $value) 3 1 4
if (exists $self->{'name'}) { } 4 0 4
if (defined $value) 3 3 6
if (exists $self->{'format'}) { } 6 0 6
if (defined $value) 3 1 4
if (exists $self->{'item_start'}) { } 4 0 4
if (defined $value) 3 1 4
if (exists $self->{'total_items'}) { } 4 0 4
if (defined $value) 3 1 4
if (exists $self->{'content_type'}) { } 4 0 4
if (defined $value) 3 3 6
if (exists $self->{'item_count'}) { } 6 0 6
if (defined $value) 3 2 5
if (exists $self->{'size'}) { } 5 0 5
if (defined $value) 7 8 15
if (exists $self->{'program_id'}) { } 14 1 15
if (defined $value) 8 3 11
if (exists $self->{'content_type'}) { } 11 0 11
if (defined $value) 1 14 15
if (exists $self->{'high_definition'}) { } 3 12 15
if (defined $value) 15 17 32
if (exists $self->{'format'}) { } 32 0 32
if (defined $value) 6 4 10
if (exists $self->{'size'}) { } 8 2 10
if (defined $value) 8 9 17
if (exists $self->{'episode'}) { } 17 0 17
if (defined $value) 8 8 16
if (exists $self->{'channel'}) { } 16 0 16
if (defined $value) 8 2 10
if (exists $self->{'series_id'}) { } 10 0 10
if (defined $value) 7 8 15
if (exists $self->{'in_progress'}) { } 14 1 15
if (defined $value) 16 9 25
if (exists $self->{'episode_num'}) { } 25 0 25
if (defined $value) 8 1 9
if (exists $self->{'url'}) { } 9 0 9
if (defined $value) 8 15 23
if (exists $self->{'station'}) { } 23 0 23
if (defined $value) 8 2 10
if (exists $self->{'name'}) { } 10 0 10
if (defined $value) 4 9 13
if (exists $self->{'description'}) { } 8 5 13
if (defined $value) 8 1 9
if (exists $self->{'duration'}) { } 9 0 9
if (defined $value) 8 8 16
if (exists $self->{'capture_date'}) { } 16 0 16
if (defined $value) 8 8 16
if (exists $self->{'tuner'}) { } 16 0 16
126 }
127 }
128  
129 # cmb - taken from the excellent Net::Amazon!
130 4 ▶sub make_array_accessor {
Subroutine make_array_accessor: called CC=3 SCAR=11.5
Pod undocumented
131 4 my($package, $name) = @_;
132  
133 4 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
134  
135 4 my $code = <<EOT;
136 *{"$package\\::$name"} = sub {
137 my(\$self, \$nameref) = \@_;
138 if(defined \$nameref) {
139 if(ref \$nameref eq "ARRAY") {
140 \$self->{$name} = \$nameref;
141 } else {
142 \$self->{$name} = [\$nameref];
143 }
144 }
145 # Return a list
146 if(exists \$self->{$name} and
147 ref \$self->{$name} eq "ARRAY") {
148 return \@{\$self->{$name}};
149 }
150  
151 return undef;
152 }
153 EOT
154  
155 4 ▶ if(! defined *{"$package\::$name"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined *{"${package}::$name";}) 4 0 4
156 0 ▶ eval $code or die "$@";
Subroutine __ANON__: called CC=5 SCAR=17.8
Branch: 4 branches
BranchTrueFalseTotal
eval $code or die "$@" 4 0 4
if (defined $nameref) 3 3 6
if (ref $nameref eq 'ARRAY') { } 3 0 3
if (exists $self->{"shows"} and ref $self->{"shows"} eq "ARRAY") 6 0 6
Condition33%1/3
exists $self->{"shows"} and ref $self->{"shows"} eq "ARRAY"
!ll&&!rl&&r
006
MC/DC0%0/2
exists $self->{"shows"} and ref $self->{"shows"} eq "ARRAY"
exists $self->{"shows"} ref $self->{"shows"} eq "ARRAY"
Truth table33%1/3
A and B
A= exists $self->{"shows"}B= ref $self->{"shows"} eq "ARRAY"
ABresult
0X0
100
111
157 }
158 }
159  
160 155 ▶sub walk_hash_ref {
Subroutine walk_hash_ref: called CC=4 SCAR=13.9
Pod undocumented
161 155 my ($package, $href, $aref) = @_;
162  
163 155 ▶ return $href if scalar(@$aref) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$aref == 0 0 155 155
164  
165 155 my @a;
166 155 push @a, $_ for @$aref;
167  
168 155 my $tail = pop @a;
169 155 my $ref = $href;
170  
171 155 for my $part (@a) {
172 151 $ref = $ref->{$part};
173 }
174
175 155 return $ref->{$tail};
176 }
177  
178 4 1;
179  
180 __END__
« TiVo.pm ↑ Summary TiVo/Show.pm »