AnyData/Format/Paragraph.pm

filter: Statementstmt 100% 37 / 37 Branchbran 50.0% 2 / 4 Conditioncond 50.0% 4 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 3 totaltotal 79.6% 51 / 64 CC 7 SCAR 9.1
CC
7
Cov
88%
read_fields
4.1
new
3.1
write_fields
2.0
CRAP 2.5
« AnyData/Format/Mp3.pm ↑ Summary AnyData/Format/FileSys.pm »
1 #########################################################
2 package AnyData::Format::Paragraph;
3 #########################################################
4 # copyright (c) 2000, Jeff Zucker <jeff@vpservices.com>
5 #########################################################
6  
7 =head1 NAME
8  
9 AnyData::Format::Paragraph - tiedhash & DBI/SQL access to vertical files
10  
11 =head1 SYNOPSIS
12  
13 use AnyData;
14 my $table = adHash( 'Paragraph', $filename,'r',$flags );
15 while (my $row = each %$table) {
16 print $row->{name},"\n" if $row->{country} =~ /us|mx|ca/;
17 }
18 # ... other tied hash operations
19  
20 OR
21  
22 use DBI
23 my $dbh = DBI->connect('dbi:AnyData:');
24 $dbh->func('table1','Paragraph', $filename,$flags,'ad_catalog');
25 my $hits = $dbh->selectall_arrayref( qq{
26 SELECT name FROM table1 WHERE country = 'us'
27 });
28 # ... other DBI/SQL operations
29  
30 =head1 DESCRIPTION
31  
32 This is a plug-in format parser for the AnyData and DBD::AnyData modules.
33  
34 It handles "vertical" files in which the record name occurs on a line by itself followed by records on lines by themselves, e.g.
35  
36 Photoslop
37 /My Photos/
38 .jpg, .gif, .psd
39  
40 Nutscrape
41 /htdocs/
42 .html, .htm
43  
44 Please refer to the documentation for AnyData.pm and DBD::AnyData.pm
45 for further details.
46  
47 =head1 AUTHOR & COPYRIGHT
48  
49 copyright 2000, Jeff Zucker <jeff@vpservices.com>
50 all rights reserved
51  
52 =cut
53  
54 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
56  
57 1 ▶use AnyData;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 1 ▶use AnyData::Format::CSV;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 1 ▶use vars qw/@ISA $VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 1 @ISA = qw(AnyData::Format::CSV);
61  
62 1 $VERSION = '0.12';
63  
64 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.2
Pod undocumented
65 1 my $class = shift;
66 1 ▶ my $flags = shift || {};
Condition50%1/2
shift() || {}
l!l
10
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
67 1 ▶ my $f = $flags->{record_sep} || '';
Condition50%1/2
$flags->{'record_sep'} || ''
l!l
01
MC/DC0%0/1
$flags->{'record_sep'} || ''
$flags->{'record_sep'}
Truth table50%1/2
A
A= $flags->{'record_sep'}
Aresult
11
00
68 #print "<$f>";
69 1 $flags->{field_sep} = "\n";
70 1 $flags->{record_sep} = "\n\n";
71 #print "[",$flags->{record_sep},"]";
72 1 my $self = AnyData::Format::CSV::->new( $flags );
73 1 return bless $self, $class;
74 }
75  
76 6 ▶sub write_fields {
Subroutine write_fields: called CC=2 SCAR=7.0
Pod undocumented
77 6 my($self,@fields) = @_;
78 6 ▶ @fields = map {$_ || ''} @fields;
Condition50%1/2
$_ || ''
l!l
180
MC/DC0%0/1
$_ || ''
$_
Truth table50%1/2
A
A= $_
Aresult
11
00
79 6 return join("\n",@fields) . $self->{record_sep};
80 }
81  
82 6 ▶sub read_fields {
Subroutine read_fields: called CC=4 SCAR=14.2
Pod undocumented
83 6 my $self = shift;
84 6 ▶ my $str = shift || return undef;
Condition50%1/2
shift() || (return undef)
l!l
60
MC/DC0%0/1
shift() || (return undef)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
85 6 ▶ return undef unless $str;
Branch: 1 branch
BranchTrueFalseTotal
unless $str 0 6 6
86 6 my @fields = split /\n/, $str;
87 6 @fields = map{s/\s+$//; $_}@fields;
88 6 ▶ die "Couldn't parse line '$str'\n" unless defined $fields[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fields[0] 0 6 6
89 6 return( @fields );
90 }
91  
92  
93  
« AnyData/Format/Mp3.pm ↑ Summary AnyData/Format/FileSys.pm »