blib/lib/Video/DVDRip/SrtxFile.pm untested

filter: Statementstmt 0.0% 0 / 66 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 23 Podpod 0.0% 0 / 18 totaltotal 0.0% 0 / 125 CC 4 SCAR 15.6
CC
4
Cov
0%
read_entry
20.0
get_filename
2.0
get_fh
2.0
CRAP 4.8
1 # $Id: SrtxFile.pm 2187 2006-08-16 19:34:38Z joern $
2  
3 #-----------------------------------------------------------------------
4 # Copyright (C) 2001-2006 Jörn Reder <joern AT zyn.de>.
5 # All Rights Reserved. See file COPYRIGHT for details.
6 #
7 # This module is part of Video::DVDRip, which is free software; you can
8 # redistribute it and/or modify it under the same terms as Perl itself.
9 #-----------------------------------------------------------------------
10  
11 package Video::DVDRip::SrtxFile;
12 use Locale::TextDomain qw (video.dvdrip);
13  
14 use base Video::DVDRip::Base;
15  
16 use Carp;
17 use strict;
18  
19 use FileHandle;
20  
21 sub get_filename { shift->{filename} }
22 sub get_fh { shift->{fh} }
23  
24 sub set_filename { shift->{filename} = $_[1] }
25 sub set_fh { shift->{fh} = $_[1] }
26  
27 sub new {
28 my $class = shift;
29 my %par = @_;
30 my ($filename) = @par{'filename'};
31  
32 my $self = bless {
33 filename => $filename,
34 fh => FileHandle->new,
35 }, $class;
36  
37 return $self;
38 }
39  
40 sub set_filename_from_dir {
41 my $self = shift;
42 my ($dir) = @_;
43 my $filename = ( glob("$dir/{*.srtx,.*srtx}") )[0];
44 return $self->set_filename($filename);
45 }
46  
47 sub open {
48 my $self = shift;
49  
50 my $fh = $self->get_fh;
51 my $filename = $self->get_filename;
52  
53 open( $fh, $filename ) or die "can't read $filename";
54  
55 1;
56 }
57  
58 sub close {
59 my $self = shift;
60  
61 close( $self->get_fh );
62  
63 1;
64 }
65  
66 sub read_entry {
67 my $self = shift;
68  
69 my $fh = $self->get_fh;
70  
71 chomp( my $nr = <$fh> );
72 chomp( my $time = <$fh> );
73 chomp( my $image_file = <$fh> );
74 <$fh>;
75  
76 return
77 unless defined $nr
78 and defined $time
79 and defined $image_file;
80  
81 $image_file =~ s/\.pgm\.txt$//;
82  
83 if ( -f "$image_file.pgm" ) {
84 $image_file .= ".pgm";
85 }
86 elsif ( -f "$image_file.png" ) {
87 $image_file .= ".png";
88 }
89 else {
90 $image_file = undef;
91 }
92  
93 return Video::DVDRip::SrtxFileEntry->new(
94 nr => $nr,
95 time => $time,
96 image_file => $image_file,
97 );
98 }
99  
100 package Video::DVDRip::SrtxFileEntry;
101  
102 sub get_nr { shift->{nr} }
103 sub get_time { shift->{time} }
104 sub get_time_sec { shift->{time_sec} }
105 sub get_image_file { shift->{image_file} }
106  
107 sub set_nr { shift->{nr} = $_[1] }
108 sub set_time { shift->{time} = $_[1] }
109 sub set_time_sec { shift->{time_sec} = $_[1] }
110 sub set_image_file { shift->{image_file} = $_[1] }
111  
112 sub new {
113 my $class = shift;
114 my %par = @_;
115 my ( $nr, $time, $image_file ) = @par{ 'nr', 'time', 'image_file' };
116  
117 ($time) = $time =~ /^(\d\d:\d\d:\d\d)/;
118 $time =~ /^(\d\d):(\d\d):(\d\d)/;
119  
120 my $time_sec = $3 + $2 * 60 + $1 * 3600;
121  
122 my $self = bless {
123 nr => $nr,
124 time => $time,
125 time_sec => $time_sec,
126 image_file => $image_file,
127 }, $class;
128  
129 return $self;
130 }
131  
132 1;