AnyData/Format/Text.pm untested

filter: Statementstmt 0.0% 0 / 45 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 73 CC 4 SCAR 13.9
CC
4
Cov
0%
new
6.0
write_fields
6.0
read_fields
6.0
CRAP 4.0
1 #########################################################
2 package AnyData::Format::Text;
3 #########################################################
4 # AnyData driver for plain text files
5 # copyright (c) 2000, Jeff Zucker <jeff@vpservices.com>
6 #########################################################
7 use strict;
8 use warnings;
9 use AnyData::Format::Base;
10 use AnyData::Storage::FileSys;
11 use vars qw( @ISA $DEBUG );
12 @AnyData::Format::Text::ISA = qw( AnyData::Format::Base );
13 $DEBUG = 0;
14  
15 sub new {
16 my $class = shift;
17 my $self = shift || {};
18 #use Data::Dumper; die Dumper $self;
19 $self->{rec_sep} ||= "\n";
20 if ($self->{dirs}) {
21 $self->{storage} = 'FileSys';
22 $self->{col_names} = 'fullpath,path,name,ext,size,content';
23 $self->{records} = get_data( {},$self->{dirs} );
24 }
25 else {
26 $self->{col_names} = 'text';
27 $self->{key} = 'text';
28 }
29 $self->{keep_first_line} = 1;
30 return bless $self, $class;
31 }
32 sub write_fields {
33 my $self = shift;
34 return $self->{dirs}
35 ? pop @_
36 : join '', @_;
37 }
38 sub read_fields {
39 my $self = shift;
40 my $str = shift || return undef;
41 if (!$self->{dirs}) {
42 my @row = ($str);
43 return @row
44 }
45 }
46 sub get_data {
47 my $self = shift;
48 my $dirs = shift;
49 # my @col_names = @{ $self->{col_names} };
50 my $table = [];
51 my @files = AnyData::Storage::FileSys::get_filename_parts(
52 dirs => $dirs
53 );
54 for my $file_info(@files) {
55 my $file = $file_info->[0];
56 # my $cols = get_mp3_tag($file) || next;
57 #my $filesize = -s $file;
58 #my @row = (@$file_info,$filesize);
59 my @row = ( $file_info->[0],
60 $file_info->[2],
61 $file_info->[1],
62 $file_info->[3],
63 );
64 push @$table, \@row;
65 # 'fullpath,path,name,ext,size,content';
66 # 'fullpath,file_name,path,ext,size,'
67 # 'name,artist,album,year,comment,genre';
68 }
69 return $table;
70 }
71  
72 1;
73