DB/Parse/FlatFile.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 50 CC 5 SCAR 30.9
CC
5
Cov
0%
parse_files
30.0
BEGIN
2.0
BEGIN
2.0
CRAP 22.0
1 package Audio::DB::Parse::FlatFile;
2  
3 # Subroutines for parsing a tab-delimited flat file of songs
4  
5 use strict;
6 use vars qw/@ISA/;
7  
8 @ISA = qw/Audio::DB::Build/;
9  
10 sub parse_files {
11 my ($name,$self,$provided_files,$columns) = @_;
12  
13 # provided_files could be a mixture of files and directories.
14 # I need to determine their type first...
15 my @files;
16 foreach my $check_this (@$provided_files) {
17 if (-d $check_this) {
18 $check_this = ($check_this =~ /\/$/) ? $check_this : $check_this . '/';
19 opendir DIR,$check_this;
20 while (my $file = readdir(DIR)) {
21 next if ($file =~ /^\./);
22 push (@files,$check_this . $file);
23 }
24 closedir DIR;
25 } elsif (-e $check_this) {
26 push (@files,$check_this);
27 }
28 }
29
30 foreach my $file (@files) {
31 open IN,$file;
32 while (my $song = <IN>) {
33 chomp $song;
34 my $tag = {};
35 # Fetch the order of the columns.
36 my @fields = split("\t",$song);
37  
38 # Mapped the data into the tag hash reference
39 # to mimic the handling of individual mp3 files.
40 my $i;
41 for ($i = 0; $i < @$columns; $i++) {
42 $tag->{$columns->[$i]} = $fields[$i];
43 }
44  
45 # I need to convert the duration into seconds...
46 $tag->{duration} =~ /(\d+):(\d+)/;
47 my $minutes = $1;
48 my $seconds = $2;
49 $tag->{seconds} = ($minutes * 60) + $seconds;
50  
51 $self->cache_song($tag);
52 }
53 close IN;
54 }
55 }
56  
57 =pod
58  
59 =head1 Audio::DB::Parse::FlatFile.pm
60  
61 Glean information on music files from a flat file of music file data.
62  
63 =head1 DESCRIPTION
64  
65 Audio::DB::Parse::FlatFile.pm is used internally by Audio::DB. It's
66 internal, private methods will be called when trying to create or update
67 a music database using the 'files' option:
68  
69 $mp3->load_database(-files =>'/path/to/music_summary.txt',
70 -columns => [qw/artist album song year/],
71 -verbose => 100);
72  
73 All methods of Audio::DB::Parse::FlatFile are private (for now). You
74 will never need to interact with Audio::DB::Parse::FlatFile objects
75 directly.
76  
77 =head1 REQUIRES
78  
79 =head1 EXPORTS
80  
81 No methods are exported.
82  
83 =head1 METHODS
84  
85 No public methods available.
86  
87 =head1 PRIVATE METHODS
88  
89 =head2 parse_files;
90
91 Title : parse_flatfiles
92 Usage : $mp3->parse_files;
93 Function: Process list of text files containing ID3 information
94 Returns : Nothing
95 Args : none
96 Status : Private
97  
98 Used for loading pre-generated data from flat files into the database.
99 Finds all the text files contained within top level directories
100 provided during calls to the new() method. Processes each file, farming
101 off a line at a time to cache_song.
102  
103 =head1 AUTHOR
104  
105 Copyright 2002-2004, Todd W. Harris <harris@cshl.org>.
106  
107 This module is distributed under the same terms as Perl itself. Feel
108 free to use, modify and redistribute it as long as you retain the
109 correct attribution.
110  
111 =head1 SEE ALSO
112  
113 L<Audio::DB>
114  
115 =cut
116  
117  
118  
119  
120 1;