AnyData/Format/Ini.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 59 CC 4 SCAR 17.6
CC
4
Cov
0%
read_fields
12.0
write_fields
6.0
new
2.0
CRAP 5.8
1 #########################################################
2 package AnyData::Format::Ini;
3 #########################################################
4 # copyright (c) 2000, Jeff Zucker <jeff@vpservices.com>
5 # all rights reserved
6 #########################################################
7  
8 =head1 NAME
9  
10 AnyData::Format::Ini - tiedhash & DBI/SQL access to ini files
11  
12 =head1 SYNOPSIS
13  
14 use AnyData;
15 my $table = adHash( 'Ini', $filename,'r',$flags );
16 while (my $row = each %$table) {
17 print $row->{name},"\n" if $row->{country} =~ /us|mx|ca/;
18 }
19 # ... other tied hash operations
20  
21 OR
22  
23 use DBI
24 my $dbh = DBI->connect('dbi:AnyData:');
25 $dbh->func('table1','Init', $filename,$flags,'ad_catalog');
26 my $hits = $dbh->selectall_arrayref( qq{
27 SELECT name FROM table1 WHERE country = 'us'
28 });
29 # ... other DBI/SQL operations
30  
31 =head1 DESCRIPTION
32  
33 This is a parser for simple name=value style Ini files. Soon it will also handle files with sections.
34  
35 Please refer to the documentation for AnyData.pm and DBD::AnyData.pm
36 for further details.
37  
38 =head1 AUTHOR & COPYRIGHT
39  
40 copyright 2000, Jeff Zucker <jeff@vpservices.com>
41 all rights reserved
42  
43 =cut
44  
45 use AnyData::Format::CSV;
46 use strict;
47 use warnings;
48 use vars qw/@ISA $VERSION/;
49 @ISA = qw(AnyData::Format::CSV);
50  
51 $VERSION = '0.12';
52  
53  
54 sub new {
55 my $class = shift;
56 my $flags = shift || {};
57 $flags->{field_sep} ||= '=';
58 my $self = AnyData::Format::CSV::->new( $flags );
59 return bless $self, $class;
60 }
61  
62 sub write_fields {
63 my($self,$key,$value) = @_;
64 return undef unless $key;
65 $value ||= '';
66 return "$key = $value" . $self->{record_sep};
67 }
68  
69 sub read_fields {
70 my $self = shift;
71 my $str = shift || return undef;
72 $str =~ s/^\s+//;
73 $str =~ s/\s+$//;
74 return undef unless $str;
75 my @fields = $str =~ /^([^=]*?)\s*=\s*(.*)/;
76 die "Couldn't parse line '$str'\n" unless defined $fields[0];
77 return( @fields );
78 }
79  
80