lib/IMDB/Local/ListFiles.pm untested

filter: Statementstmt 0.0% 0 / 60 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 18 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 106 SCAR 45.0
CC
9
Cov
0%
checkFile
56.0
init
6.0
statFiles
6.0
CRAP 90.0
1 package IMDB::Local::ListFiles;
2  
3 use 5.006;
4 use strict;
5 use warnings;
6  
7 =head1 NAME
8  
9 IMDB::Local::ListFiles - Object to manage IMDB List files.
10  
11 =head1 VERSION
12  
13 Version 0.01
14  
15 =cut
16  
17 our $VERSION = '1.00';
18  
19 =head1 SYNOPSIS
20  
21 Quick summary of what the module does.
22  
23 Perhaps a little code snippet.
24  
25 use IMDB::Local::Download;
26  
27 my $foo = IMDB::Local::ListFiles->new();
28 ...
29  
30 =head1 EXPORT
31  
32 A list of functions that can be exported. You can delete this section
33 if you don't export anything, such as for a purely object-oriented module.
34  
35 =head1 SUBROUTINES/METHODS
36  
37 =head2 new
38  
39 =cut
40  
41 use Class::MethodMaker
42 [
43 scalar => ['listsDir'],
44 scalar => [{-default => 1}, 'movies'],
45 scalar => [{-default => 1}, 'directors'],
46 scalar => [{-default => 1}, 'actors'],
47 scalar => [{-default => 1}, 'actresses'],
48 scalar => [{-default => 1}, 'genres'],
49 scalar => [{-default => 1}, 'ratings'],
50 scalar => [{-default => 1}, 'keywords'],
51 scalar => [{-default => 1}, 'plot'],
52
53 array => ['listFiles'],
54 hash => ['paths'],
55  
56 new => [qw/ -init -hash new /] ,
57 ];
58  
59 sub init
60 {
61 my ($self)=@_;
62  
63 if ( ! -d $self->listsDir() ) {
64 die $self->listsDir().":does not exist";
65 }
66  
67 $self->statFiles();
68 return($self);
69 }
70  
71 sub checkFile
72 {
73 my ($self, $file)=@_;
74
75 my $listsDir=$self->{listsDir};
76
77 my $filename="$listsDir/$file.list";
78 my $filenameGz="$filename.gz";
79 my $filenameExists = -f $filename;
80 my $filenameSize = -s $filename;
81 my $filenameGzExists = -f $filenameGz;
82 my $filenameGzSize = -s $filenameGz;
83
84 if ( $filenameExists and not $filenameSize ) {
85 warn "ignoring zero-length $filename\n";
86 #unlink $filename or die "cannot unlink $filename: $!";
87 $filenameExists = 0;
88 }
89 if ( $filenameGzExists and not $filenameGzSize ) {
90 warn "ignoring zero-length $filenameGz\n";
91 #unlink $filenameGz or die "cannot unlink $filenameGz: $!";
92 $filenameGzExists = 0;
93 }
94
95 $self->listFiles_push($file);
96  
97 if ( not $filenameExists and not $filenameGzExists ) {
98 #warn "$filenameGz does not exist\n";
99 #$self->{missingListFiles}->{$file}=$filenameGz;
100 $self->paths_set($file, $filenameGz);
101 }
102 elsif ( not $filenameExists and $filenameGzExists ) {
103 #$self->{imdbListFiles}->{$file}=$filenameGz;
104 $self->paths_set($file, $filenameGz);
105 }
106 elsif ( $filenameExists and not $filenameGzExists ) {
107 #$self->{imdbListFiles}->{$file}=$filename;
108 $self->paths_set($file, $filename);
109 }
110 elsif ( $filenameExists and $filenameGzExists ) {
111 die "both $filename and $filenameGz exist, remove one of them\n";
112 }
113 else { die }
114 }
115  
116 =head2 new
117  
118 =cut
119  
120 sub types
121 {
122 my ($self)=@_;
123 my @a=(qw/movies directors actors actresses genres ratings keywords plot/);
124 return @a;
125 }
126  
127 sub statFiles
128 {
129 my ($self)=@_;
130  
131 #delete $self->{missingListFiles};
132
133 $self->listFiles_reset();
134 $self->paths_reset();
135  
136 for my $d ($self->types) {
137 if ( $self->$d() ) {
138 $self->checkFile($d);
139 }
140 }
141  
142 }
143  
144 =head1 AUTHOR
145  
146 jerryv, C<< <jerry.veldhuis at gmail.com> >>
147  
148 =head1 BUGS
149  
150 Please report any bugs or feature requests to C<bug-imdb-local at rt.cpan.org>, or through
151 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=IMD-Local>. I will be notified, and then you'll
152 automatically be notified of progress on your bug as I make changes.
153  
154  
155  
156  
157 =head1 SUPPORT
158  
159 You can find documentation for this module with the perldoc command.
160  
161 perldoc IMDB::Local::Download
162  
163  
164 You can also look for information at:
165  
166 =over 4
167  
168 =item * RT: CPAN's request tracker (report bugs here)
169  
170 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=IMDB-Local>
171  
172 =item * AnnoCPAN: Annotated CPAN documentation
173  
174 L<http://annocpan.org/dist/IMDB-Local>
175  
176 =item * CPAN Ratings
177  
178 L<http://cpanratings.perl.org/d/IMDB-Local>
179  
180 =item * Search CPAN
181  
182 L<http://search.cpan.org/dist/IMDB-Local/>
183  
184 =back
185  
186  
187 =head1 ACKNOWLEDGEMENTS
188  
189  
190 =head1 LICENSE AND COPYRIGHT
191  
192 Copyright 2015 jerryv.
193  
194 This program is free software; you can redistribute it and/or modify it
195 under the terms of the the Artistic License (2.0). You may obtain a
196 copy of the full license at:
197  
198 L<http://www.perlfoundation.org/artistic_license_2_0>
199  
200 Any use, modification, and distribution of the Standard or Modified
201 Versions is governed by this Artistic License. By using, modifying or
202 distributing the Package, you accept this license. Do not use, modify,
203 or distribute the Package, if you do not accept this license.
204  
205 If your Modified Version has been derived from a Modified Version made
206 by someone other than you, you are nevertheless required to ensure that
207 your Modified Version complies with the requirements of this license.
208  
209 This license does not grant you the right to use any trademark, service
210 mark, tradename, or logo of the Copyright Holder.
211  
212 This license includes the non-exclusive, worldwide, free-of-charge
213 patent license to make, have made, use, offer to sell, sell, import and
214 otherwise transfer the Package with respect to any patent claims
215 licensable by the Copyright Holder that are necessarily infringed by the
216 Package. If you institute patent litigation (including a cross-claim or
217 counterclaim) against any party alleging that the Package constitutes
218 direct or contributory patent infringement, then this Artistic License
219 to you shall terminate on the date that such litigation is filed.
220  
221 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
222 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
223 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
224 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
225 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
226 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
227 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
228 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
229  
230  
231 =cut
232  
233 1; # End of IMDB::Local::Download