AnyData/Storage/RAM.pm

filter: Statementstmt 63.5% 117 / 184 Branchbran 50.0% 44 / 88 Conditioncond 35.2% 25 / 71 MC/DCmcdc 11.9% 5 / 42 Subroutinesub 53.3% 16 / 30 Podpod 0.0% 0 / 24 totaltotal 47.1% 207 / 439 CC 73 SCAR 44.5
CC
73
Cov
54%
open_table
175.9
get_remote_data
72.0
export
12.0
CRAP 85.3
« AnyData/Format/HTMLtable.pm ↑ Summary AnyData.pm »
1 #########################################################################
2 package AnyData::Storage::RAM;
3 #########################################################################
4 #
5 # This module is copyright (c), 2000 by Jeff Zucker
6 # All rights reserved.
7 #
8 #########################################################################
9  
10 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 3 ▶use vars qw($VERSION $DEBUG);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 $VERSION = '0.12';
16  
17 3 $DEBUG = 1;
18 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use AnyData::Storage::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 9 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod undocumented
22 9 my $class = shift;
23 9 ▶ my $self = shift || {};
Condition50%1/2
shift() || {}
l!l
90
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
24 9 return bless $self, $class;
25 }
26  
27 ########
28 # MOVE set_col_nums and open_table to Storage/Base.pm
29 #
30 # ALSO make DBD::AnyData::Statement and DBD::Table simple @ISA for AnyData
31  
32 9 ▶sub set_col_nums {
Subroutine set_col_nums: called CC=6 SCAR=18.1
Pod undocumented
33 9 my $self = shift;
34 9 my $col_names = $self->{col_names};
35 9 ▶ return {} unless $col_names ;
Branch: 1 branch
BranchTrueFalseTotal
unless $col_names 2 7 9
36 7 ▶ return {} unless ref $col_names eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $col_names eq "ARRAY" 0 7 7
37 7 ▶ return {} unless scalar @$col_names;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$col_names 0 7 7
38 7 my $col_nums={}; my $i=0;
39 7 ▶ for (@$col_names) { next unless $_; $col_nums->{$_} = $i; $i++; }
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 20 20
40 #use Data::Dumper; die Dumper $col_names;
41 7 $self->{col_nums}=$col_nums;
42 7 return $col_nums;
43 }
44 9 ▶sub open_table {
Subroutine open_table: called CC=45 SCAR=51.7
Pod undocumented
45 9 my( $self, $parser, $file, $read_mode, $data ) = @_;
46 9 ▶ $data = $self->{recs} if $self->{recs};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"recs"} 3 6 9
47 #$data ||= $parser->{recs};
48 #$data = $file if ref $file eq 'ARRAY' and !$data;
49 #use Data::Dumper; print Dumper $data;
50 #print ref $parser;
51  
52 9 my $rec_sep = $parser->{record_sep};# || "\n";
53 9 my $table_ary = [];
54 9 ▶ my $col_names = $parser->{col_names} || $self->{col_names};
Condition66%2/3
$parser->{'col_names'} || $self->{'col_names'}
l!l&&r!l&&!r
702
MC/DC50%1/2
$parser->{'col_names'} || $self->{'col_names'}
$parser->{'col_names'} $self->{'col_names'}
Truth table66%2/3
A || B
A= $parser->{'col_names'}B= $self->{'col_names'}
ABresult
1X1
011
000
55 9 my $cols_supplied = $col_names;
56 9 ▶ my $url = $file if $file =~ m"^http://|^ftp://";
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ m[^http://|^ftp://] 0 9 9
57 9 ▶ $self->{open_mode} = $read_mode || 'r';
Condition50%1/2
$read_mode || 'r'
l!l
90
MC/DC0%0/1
$read_mode || 'r'
$read_mode
Truth table50%1/2
A
A= $read_mode
Aresult
11
00
58  
59 9 my $data_type;
60 9 ▶ $data_type='ARY-ARY' if ref $data eq 'ARRAY' and ref $data->[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $data eq "ARRAY" and ref $data->[0] eq "ARRAY" 0 9 9
Condition66%2/3
ref $data eq "ARRAY" and ref $data->[0] eq "ARRAY"
!ll&&!rl&&r
810
MC/DC0%0/2
ref $data eq "ARRAY" and ref $data->[0] eq "ARRAY"
ref $data eq "ARRAY" ref $data->[0] eq "ARRAY"
Truth table66%2/3
A and B
A= ref $data eq "ARRAY"B= ref $data->[0] eq "ARRAY"
ABresult
0X0
100
111
61 9 ▶ $data_type='ARY-HSH' if ref $data eq 'ARRAY' and ref $data->[0] eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $data eq "ARRAY" and ref $data->[0] eq "HASH" 0 9 9
Condition66%2/3
ref $data eq "ARRAY" and ref $data->[0] eq "HASH"
!ll&&!rl&&r
810
MC/DC0%0/2
ref $data eq "ARRAY" and ref $data->[0] eq "HASH"
ref $data eq "ARRAY" ref $data->[0] eq "HASH"
Truth table66%2/3
A and B
A= ref $data eq "ARRAY"B= ref $data->[0] eq "HASH"
ABresult
0X0
100
111
62 9 ▶ $data_type='ARY-STR' if ref $data eq 'ARRAY' and !$data_type;
Branch: 1 branch
BranchTrueFalseTotal
if ref $data eq "ARRAY" and not $data_type 1 8 9
Condition66%2/3
ref $data eq "ARRAY" and not $data_type
!ll&&!rl&&r
801
MC/DC50%1/2
ref $data eq "ARRAY" and not $data_type
ref $data eq "ARRAY" not $data_type
Truth table66%2/3
A and not(B)
A= ref $data eq "ARRAY"B= not $data_type
ABresult
0X0
100
111
63 9 ▶ $data_type ||= 'STR';
Condition100%2/2
$data_type ||= "STR"
l!l
18
MC/DC100%1/1
$data_type ||= "STR"
$data_type
Truth table100%2/2
A
A= $data_type
Aresult
11
00
64 # print "[$data_type]" . ref $data if $data;
65 # MP3 and ARRAY
66 9 ▶ if ( $self->{records} && !$data ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'records'} and not $data) { } 0 9 9
elsif ($data) { } 3 6 9
Condition33%1/3
$self->{"records"} and not $data
!ll&&!rl&&r
900
MC/DC0%0/2
$self->{"records"} and not $data
$self->{"records"} not $data
Truth table33%1/3
A and not(B)
A= $self->{"records"}B= not $data
ABresult
0X0
100
111
67 0 $table_ary = $self->{records};
68 0 ▶ $col_names ||= shift @$table_ary;
Condition0%0/3
$col_names ||= shift @$table_ary
l!l&&r!l&&!r
000
MC/DC0%0/2
$col_names ||= shift @$table_ary
$col_names shift @$table_ary
Truth table0%0/3
A ||= B
A= $col_namesB= shift @$table_ary
ABresult
1X1
011
000
69 }
70  
71 # REMOTE
72 elsif ( $data ) {
73 3 ▶ if ($parser->{slurp_mode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser->{'slurp_mode'}) { } 0 3 3
74 0 ($table_ary,$col_names) = $parser->import($data,$self);
75 0 ▶ shift @$table_ary if (ref $parser) =~ /HTMLtable/ && $url && $cols_supplied;
Branch: 1 branch
BranchTrueFalseTotal
if ref($parser) =~ /HTMLtable/ and $url and $cols_supplied 0 0 0
Condition0%0/6
ref($parser) =~ /HTMLtable/ and $url and $cols_supplied
!ll&&!rl&&r
000
ref($parser) =~ /HTMLtable/ and $url
!ll&&!rl&&r
000
MC/DC0%0/3
ref($parser) =~ /HTMLtable/ and $url and $cols_supplied
ref($parser) =~ /HTMLtable/ $url $cols_supplied
Truth table0%0/4
A and B and C
A= ref($parser) =~ /HTMLtable/B= $urlC= $cols_supplied
ABCresult
0XX0
10X0
1100
1111
76 }
77 else {
78 3 ▶ if ($data_type eq 'ARY-STR') {
Branch: 1 branch
BranchTrueFalseTotal
if ($data_type eq "ARY-STR") 1 2 3
79 1 $data = join '', @$data;
80 }
81 3 ▶ if ($data_type eq 'ARY-ARY') {
Branch: 2 branches
BranchTrueFalseTotal
if ($data_type eq 'ARY-ARY') { } 0 3 3
elsif ($data_type eq 'ARY-HSH') { } 0 3 3
82 0 $table_ary = $data;
83 }
84 elsif ($data_type eq 'ARY-HSH') {
85 0 print "IMPORT OF HASHES NOT YET IMPLEMENTED!\n"; exit;
86 }
87 else {
88 3 $data =~ s/\015$//gsm; # ^M = CR from DOS
89 #use Data::Dumper; print Dumper $data;
90 3 my @tmp = split /$rec_sep/, $data;
91 #use Data::Dumper; print ref $parser, Dumper \@tmp;
92 3 ▶ if ((ref $parser) =~ /Fixed/ && (!$col_names or !scalar @$col_names)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($parser) =~ /Fixed/ and not $col_names && scalar @$col_names) 0 3 3
Condition16%1/6
ref($parser) =~ /Fixed/ and not $col_names && scalar @$col_names
!ll&&!rl&&r
300
$col_names && scalar @$col_names
!ll&&!rl&&r
000
MC/DC0%0/3
ref($parser) =~ /Fixed/ and not $col_names && scalar @$col_names
ref($parser) =~ /Fixed/ $col_names scalar @$col_names
Truth table25%1/4
A and not(B && C)
A= ref($parser) =~ /Fixed/B= $col_namesC= scalar @$col_names
ABCresult
0XX0
1110
10X1
1101
93 0 my $colstr = shift @tmp;
94 # $colstr =~ s/\015$//g; # ^M = CR from DOS
95 0 @$col_names = split ',',$colstr;
96 }
97 3 ▶ if ((ref $parser) =~ /Paragraph/) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($parser) =~ /Paragraph/) 0 3 3
98 0 my $colstr = shift @tmp;
99 0 @$col_names = $parser->read_fields($colstr);
100 #print "@$col_names";
101 }
102 3 for my $line( @tmp ) {
103 # for (split /$rec_sep/, $data) {
104 # s/\015$//g; # ^M = CR from DOS
105 14 ▶ next if $parser->{skip_pattern} and $line =~ $parser->{skip_pattern};
Branch: 1 branch
BranchTrueFalseTotal
if $parser->{"skip_pattern"} and $line =~ /$parser->{"skip_pattern"}/ 0 14 14
Condition33%1/3
$parser->{"skip_pattern"} and $line =~ /$parser->{"skip_pattern"}/
!ll&&!rl&&r
1400
MC/DC0%0/2
$parser->{"skip_pattern"} and $line =~ /$parser->{"skip_pattern"}/
$parser->{"skip_pattern"} $line =~ /$parser->{"skip_pattern"}/
Truth table33%1/3
A and B
A= $parser->{"skip_pattern"}B= $line =~ /$parser->{"skip_pattern"}/
ABresult
0X0
100
111
106 14 my @row = $parser->read_fields($line);
107 #print $_;
108 #use Data::Dumper; print Dumper \@row;
109 ###z MOD
110 # next unless scalar @row;
111 # push @$table_ary, \@row;
112 14 push @$table_ary, \@row
113 # unless $parser->{skip_mark}
114 # and $row[0] eq $parser->{skip_mark};
115 #
116 }
117 }
118 3 ▶ if ((ref $parser) !~ /Fixed|Paragraph/
Branch: 1 branch
BranchTrueFalseTotal
unless (ref($parser) =~ /Fixed|Paragraph/ or $parser->{"keep_first_line"} or $parser->{"col_names"}) 2 1 3
Condition66%4/6
ref($parser) =~ /Fixed|Paragraph/ or $parser->{"keep_first_line"} or $parser->{"col_names"}
l!l&&r!l&&!r
102
ref($parser) =~ /Fixed|Paragraph/ or $parser->{"keep_first_line"}
l!l&&r!l&&!r
012
MC/DC33%1/3
ref($parser) =~ /Fixed|Paragraph/ or $parser->{"keep_first_line"} or $parser->{"col_names"}
ref($parser) =~ /Fixed|Paragraph/ $parser->{"keep_first_line"} $parser->{"col_names"}
Truth table50%2/4
A or B or C
A= ref($parser) =~ /Fixed|Paragraph/B= $parser->{"keep_first_line"}C= $parser->{"col_names"}
ABCresult
1XX1
01X1
0011
0000
119 && !$parser->{keep_first_line}
120 && !$parser->{col_names}
121 ) {
122 2 $col_names = shift @$table_ary;
123 }
124 #use Data::Dumper; die Dumper $table_ary;
125 }
126 }
127 # if ($file and !(ref $file eq 'ARRAY') and $file !~ m'^http://|ftp://' and !(scalar @$table_ary) ) {
128 9 ▶ if ((ref $parser) !~ /XML/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref($parser) =~ /XML/) 9 0 9
129 9 ▶ my $size = scalar @$table_ary if defined $table_ary;
Branch: 1 branch
BranchTrueFalseTotal
if defined $table_ary 9 0 9
130 9 ▶ if ($file and !(ref $file eq 'ARRAY') and !$size ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file and not ref $file eq "ARRAY" and not $size) 1 8 9
Condition66%4/6
$file and not ref $file eq "ARRAY" and not $size
!ll&&!rl&&r
801
$file and not ref $file eq "ARRAY"
!ll&&!rl&&r
081
MC/DC33%1/3
$file and not ref $file eq "ARRAY" and not $size
$file not ref $file eq "ARRAY" not $size
Truth table50%2/4
A and not(B) and not(C)
A= $fileB= not ref $file eq "ARRAY"C= not $size
ABCresult
0XX0
10X0
1100
1111
131 1 ▶ if ($file =~ m'^http://|ftp://') {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ m[^http://|ftp://]) { } 0 1 1
132 # ($table_ary,$col_names) =
133 # $self->get_remote_data($file,$parser);
134 }
135 else {
136 1 ($table_ary,$col_names) =
137 $self->get_local_data($file,$parser,$read_mode);
138 }
139 }
140 }
141 9 ▶ my @array = @$col_names if ref $col_names eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $col_names eq "ARRAY" 9 0 9
142 #print "@array" if @array;
143 9 ▶ if ($col_names && scalar @array == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col_names and scalar @array == 0) 0 9 9
Condition33%1/3
$col_names and scalar @array == 0
!ll&&!rl&&r
090
MC/DC0%0/2
$col_names and scalar @array == 0
$col_names scalar @array == 0
Truth table33%1/3
A and B
A= $col_namesB= scalar @array == 0
ABresult
0X0
100
111
144 0 ▶ @array = (ref $parser =~ /Fixed/)
Branch: 1 branch
BranchTrueFalseTotal
ref $parser =~ /Fixed/ ? : 0 0 0
145 ? split ',', $col_names
146 : $parser->read_fields($col_names);
147 }
148 9 my $col_nums;
149 9 ▶ $col_nums = $self->set_col_nums() if $col_names;
Branch: 1 branch
BranchTrueFalseTotal
if $col_names 9 0 9
150 9 my %table = (
151 index => 0,
152 file => $file,
153 records => $table_ary,
154 col_nums => $col_nums,
155 col_names => \@array,
156 );
157 9 for my $key(keys %table) {
158 45 $self->{$key}=$table{$key};
159 }
160 #use Data::Dumper; print Dumper $self; exit;
161 #use Data::Dumper; print Dumper $table_ary;
162 #use Data::Dumper; print Dumper $self->{records} if (ref $parser) =~ /Weblog/;
163 }
164 0 ▶sub close { my $s = shift; undef $s }
Subroutine close: not called CC=1 SCAR=6.9
Pod undocumented
165  
166 0 ▶sub get_remote_data {
Subroutine get_remote_data: not called CC=8 SCAR=42.8
Pod undocumented
167 0 my $self = shift;
168 0 my $file = shift;
169 0 my $parser = shift;
170 0 ▶ $ENV = {} unless defined $ENV;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ENV 0 0 0
171 0 $^W = 0;
172 0 undef $@;
173 0 ▶ my $user = $self->{user} || $self->{username};
Condition0%0/3
$self->{'user'} || $self->{'username'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'user'} || $self->{'username'}
$self->{'user'} $self->{'username'}
Truth table0%0/3
A || B
A= $self->{'user'}B= $self->{'username'}
ABresult
1X1
011
000
174 0 ▶ my $pass = $self->{pass} || $self->{password};
Condition0%0/3
$self->{'pass'} || $self->{'password'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'pass'} || $self->{'password'}
$self->{'pass'} $self->{'password'}
Truth table0%0/3
A || B
A= $self->{'pass'}B= $self->{'password'}
ABresult
1X1
011
000
175 0 eval{ require 'LWP/UserAgent.pm'; };
176 # eval{ require 'File/DosGlob.pm'; };
177 0 ▶ die "LWP module not found! $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
178 0 my $ua = LWP::UserAgent->new;
179 0 my $req = HTTP::Request->new(GET => $file);
180 0 ▶ $req->authorization_basic($user, $pass) if $user and $pass;
Branch: 1 branch
BranchTrueFalseTotal
if $user and $pass 0 0 0
Condition0%0/3
$user and $pass
!ll&&!rl&&r
000
MC/DC0%0/2
$user and $pass
$user $pass
Truth table0%0/3
A and B
A= $userB= $pass
ABresult
0X0
100
111
181 0 my $res = $ua->request($req);
182 0 ▶ die "[$file] : " . $res->message if !$res->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->is_success 0 0 0
183 0 $^W = 1;
184 0 return $res->content;
185 # return $parser->get_data($res->content,$self->{col_names});
186 }
187 0 ▶sub export {
Subroutine export: not called CC=3 SCAR=24.8
Pod undocumented
188 0 my $self = shift;
189 0 my $parser = shift;
190 0 print "##";
191 0 ▶ return unless $parser->{export_on_close} && $self->{open_mode} ne 'r';
Branch: 1 branch
BranchTrueFalseTotal
unless $parser->{"export_on_close"} and $self->{"open_mode"} ne "r" 0 0 0
Condition0%0/3
$parser->{"export_on_close"} and $self->{"open_mode"} ne "r"
!ll&&!rl&&r
000
MC/DC0%0/2
$parser->{"export_on_close"} and $self->{"open_mode"} ne "r"
$parser->{"export_on_close"} $self->{"open_mode"} ne "r"
Truth table0%0/3
A and B
A= $parser->{"export_on_close"}B= $self->{"open_mode"} ne "r"
ABresult
0X0
100
111
192 # return $parser->export( $self->{records}, $self->{col_names}, $self->{deleted} );
193 #$self->{file_manager}->str2file($str);
194 }
195  
196 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
197 #shift->export;
198 #print "DESTROY";
199 }
200  
201 1 ▶sub get_local_data {
Subroutine get_local_data: called CC=4 SCAR=16.5
Pod undocumented
202 1 my $self = shift;
203 1 my $file = shift;
204 1 my $parser = shift;
205 1 ▶ my $open_mode = shift || 'r';
Condition50%1/2
shift() || 'r'
l!l
10
MC/DC0%0/1
shift() || 'r'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
206 1 my $adf = AnyData::Storage::File->new;
207 # $adf->open_table($parser,$file,'r');
208 1 my $fh = $adf->open_local_file($file,$open_mode);
209 #print Dumper $file,$adf; exit;
210 1 $self->{file_manager} = $adf;
211 1 $self->{fh} = $fh;
212 #use Data::Dumper; print Dumper $self;
213 # my $fh = $adf->{fh};
214 1 ▶ return([],$self->{col_names}) if 'co' =~ /$open_mode/;
Branch: 1 branch
BranchTrueFalseTotal
if "co" =~ /$open_mode/ 1 0 1
215 # if ((ref $parser) =~ /HTML/) {
216 # print "[[$file]]";
217 # for (<$fh>) { print; }
218 # }
219 0 local $/ = undef;
220 0 my $str = <$fh>;
221 # $fh->close;
222 #print $str if (ref $parser) =~ /HTML/;
223 0 ▶ return $self->{col_names} unless $str;
Branch: 1 branch
BranchTrueFalseTotal
unless $str 0 0 0
224 0 return $parser->get_data($str,$self->{col_names});
225 }
226 0 ▶sub dump {
Subroutine dump: not called CC=1 SCAR=6.9
Pod undocumented
227 0 my $self = shift;
228 print
229 0 "\nTotal Rows = ", scalar @{ $self->{records} },
230 "\nCurrent Row = ", $self->{index},
231 "\nData = ", Dumper $self->{records},
232 0 ;
233 }
234  
235 0 ▶sub col_names { shift->{col_names} }
Subroutine col_names: not called CC=1 SCAR=6.9
Pod undocumented
236 0 ▶sub get_col_names {
Subroutine get_col_names: not called CC=2 SCAR=17.9
Pod undocumented
237 0 my $self=shift;
238 0 my $parser=shift;
239 0 ▶ my $c = $self->{col_names} || $parser->{col_names};
Condition0%0/3
$self->{'col_names'} || $parser->{'col_names'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'col_names'} || $parser->{'col_names'}
$self->{'col_names'} $parser->{'col_names'}
Truth table0%0/3
A || B
A= $self->{'col_names'}B= $parser->{'col_names'}
ABresult
1X1
011
000
240 #print "###@$c";
241 #return $c;
242 # if (!scalar @$c and $self->{data}) {
243 # $c = shift @{$self->{data}};
244 # }
245 # return $c;
246 }
247 0 ▶sub get_file_handle {''}
Subroutine get_file_handle: not called CC=1 SCAR=6.9
Pod undocumented
248 0 ▶sub get_file_name {''}
Subroutine get_file_name: not called CC=1 SCAR=6.9
Pod undocumented
249  
250 46 ▶sub seek_first_record { shift->{index}=0 }
Subroutine seek_first_record: called CC=1 SCAR=0.0
Pod undocumented
251  
252 222 ▶sub get_pos { my $s=shift; $s->{CUR}= $s->{index}}
Subroutine get_pos: called CC=1 SCAR=0.0
Pod undocumented
253 0 ▶sub go_pos {my $s=shift;$s->{index}=$s->{CUR}}
Subroutine go_pos: not called CC=1 SCAR=6.9
Pod undocumented
254  
255 222 ▶sub is_deleted { my $s=shift; return $s->{deleted}->{$s->{index}-1} };
Subroutine is_deleted: called CC=1 SCAR=0.0
Pod undocumented
256  
257 12 ▶sub delete_record {
Subroutine delete_record: called CC=1 SCAR=0.0
Pod undocumented
258 12 my $self = shift;
259 # $self->{records}->[ $self->{index}-1 ]->[-1] = $self->{del_marker};
260 12 $self->{deleted}->{ $self->{index}-1 }++;
261 }
262  
263 ##################################
264 # fetch_row()
265 ##################################
266 256 ▶sub get_record {
Subroutine get_record: called CC=3 SCAR=11.0
Pod undocumented
267 256 my($self,$parser) = @_;
268 256 my $currentRow = $self->{index};
269 256 ▶ return undef unless $self->{records} ;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"records"} 0 256 256
270 256 ▶ return undef if $currentRow >= @{ $self->{records} };
Branch: 1 branch
BranchTrueFalseTotal
if $currentRow >= @{$self->{"records"};} 34 222 256
271 222 $self->{index} = $currentRow+1;
272 222 $self->get_pos($self->{index});
273 #print @{ $self->{records}->[ $currentRow ] };
274 222 return $self->{records}->[ $currentRow ];
275 }
276 3 *file2str = \&get_record;
277  
278  
279 3 *write_fields = \&push_row;
280 ####################################
281 # push_row()
282 ####################################
283 42 ▶sub push_row {
Subroutine push_row: called CC=2 SCAR=6.9
Pod undocumented
284 42 my($self, $fields, $parser) = @_;
285 42 ▶ if (! ref $fields) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $fields) 36 6 42
286 36 $fields =~ s/\012$//;
287 #chomp $fields;
288 36 my @rec = $parser->read_fields($fields);
289 36 $fields = \@rec;
290 }
291  
292 #use Data::Dumper; print Dumper $fields;
293 42 my $currentRow = $self->{index};
294 42 $self->{index} = $currentRow+1;
295 42 $self->{records}->[$currentRow] = $fields;
296 42 return 1;
297 }
298  
299 ##################################
300 # truncate()
301 ##################################
302 0 ▶sub truncate {
Subroutine truncate: not called CC=1 SCAR=6.9
Pod undocumented
303 0 my $self = shift;
304 0 return splice @{$self->{records}}, $self->{index},1;
305 }
306  
307 #####################################
308 # push_names()
309 #####################################
310 0 ▶sub print_col_names {
Subroutine print_col_names: not called CC=2 SCAR=17.9
Pod undocumented
311 0 my($self, $parser, $names) = @_;
312 0 $self->{col_names} = $names;
313 0 $self->{parser}->{col_names} = $names;
314 0 my($col_nums) = {};
315 0 ▶ for (my $i = 0; $i < @$names; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$names) 0 0 0
316 0 $col_nums->{$names->[$i]} = $i;
317 }
318 0 $self->{col_nums} = $col_nums;
319 }
320  
321 0 ▶sub drop {1;}
Subroutine drop: not called CC=1 SCAR=6.9
Pod undocumented
322 0 ▶sub close_table {1;}
Subroutine close_table: not called CC=1 SCAR=6.9
Pod undocumented
323  
324 36 ▶sub seek {
Subroutine seek: called CC=6 SCAR=21.4
Pod undocumented
325 36 my($self, $pos, $whence) = @_;
326 36 ▶ return unless defined $self->{records};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"records"} 0 36 36
327 36 my($currentRow) = $self->{index};
328 36 ▶ if ($whence == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($whence == 0) { } 0 36 36
elsif ($whence == 1) { } 0 36 36
elsif ($whence == 2) { } 36 0 36
329 0 $currentRow = $pos;
330 } elsif ($whence == 1) {
331 0 $currentRow += $pos;
332 } elsif ($whence == 2) {
333 36 $currentRow = @{$self->{records}} + $pos;
334 } else {
335 0 die $self . "->seek: Illegal whence argument ($whence)";
336 }
337 36 ▶ if ($currentRow < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($currentRow < 0) 0 36 36
338 0 die "Illegal row number: $currentRow";
339 }
340 36 $self->{index} = $currentRow;
341 }
342  
343  
344 ############################################################################
345 3 1;
346 __END__
« AnyData/Format/HTMLtable.pm ↑ Summary AnyData.pm »