| line | stmt | bran | cond | sub | pod | time | code | 
| 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 |  |  | 3 |  | 16 | use strict; | 
|  | 3 |  |  |  |  | 3 |  | 
|  | 3 |  |  |  |  | 97 |  | 
| 11 | 3 |  |  | 3 |  | 14 | use warnings; | 
|  | 3 |  |  |  |  | 4 |  | 
|  | 3 |  |  |  |  | 98 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 3 |  |  | 3 |  | 21 | use vars qw($VERSION $DEBUG); | 
|  | 3 |  |  |  |  | 4 |  | 
|  | 3 |  |  |  |  | 183 |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | $VERSION = '0.08'; | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | $DEBUG   = 1; | 
| 18 | 3 |  |  | 3 |  | 17 | use Data::Dumper; | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 218 |  | 
| 19 | 3 |  |  | 3 |  | 1255 | use AnyData::Storage::File; | 
|  | 3 |  |  |  |  | 8 |  | 
|  | 3 |  |  |  |  | 5607 |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | sub new { | 
| 22 | 9 |  |  | 9 | 0 | 19 | my $class = shift; | 
| 23 | 9 |  | 50 |  |  | 32 | my $self  = shift || {}; | 
| 24 | 9 |  |  |  |  | 24 | 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 |  |  |  |  |  |  | sub set_col_nums { | 
| 33 | 9 |  |  | 9 | 0 | 10 | my $self = shift; | 
| 34 | 9 |  |  |  |  | 15 | my $col_names = $self->{col_names}; | 
| 35 | 9 | 100 |  |  |  | 21 | return {} unless $col_names ; | 
| 36 | 7 | 50 |  |  |  | 22 | return {} unless ref $col_names eq 'ARRAY'; | 
| 37 | 7 | 50 |  |  |  | 18 | return {} unless scalar @$col_names; | 
| 38 | 7 |  |  |  |  | 18 | my $col_nums={}; my $i=0; | 
|  | 7 |  |  |  |  | 10 |  | 
| 39 | 7 | 50 |  |  |  | 16 | for (@$col_names) { next unless $_; $col_nums->{$_} = $i; $i++; } | 
|  | 20 |  |  |  |  | 36 |  | 
|  | 20 |  |  |  |  | 35 |  | 
|  | 20 |  |  |  |  | 24 |  | 
| 40 |  |  |  |  |  |  | #use Data::Dumper; die Dumper $col_names; | 
| 41 | 7 |  |  |  |  | 13 | $self->{col_nums}=$col_nums; | 
| 42 | 7 |  |  |  |  | 16 | return $col_nums; | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  | sub open_table { | 
| 45 | 9 |  |  | 9 | 0 | 18 | my( $self, $parser, $file, $read_mode, $data ) = @_; | 
| 46 | 9 | 100 |  |  |  | 38 | $data = $self->{recs} if $self->{recs}; | 
| 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 |  |  |  |  | 13 | my $rec_sep = $parser->{record_sep};# || "\n"; | 
| 53 | 9 |  |  |  |  | 13 | my $table_ary = []; | 
| 54 | 9 |  | 66 |  |  | 25 | my $col_names = $parser->{col_names} || $self->{col_names}; | 
| 55 | 9 |  |  |  |  | 12 | my $cols_supplied = $col_names; | 
| 56 | 9 | 50 |  |  |  | 50 | my $url = $file if $file =~ m"^http://|^ftp://"; | 
| 57 | 9 |  | 50 |  |  | 30 | $self->{open_mode} = $read_mode || 'r'; | 
| 58 |  |  |  |  |  |  |  | 
| 59 | 9 |  |  |  |  | 12 | my $data_type; | 
| 60 | 9 | 50 | 66 |  |  | 31 | $data_type='ARY-ARY' if ref $data eq 'ARRAY' and ref $data->[0] eq 'ARRAY'; | 
| 61 | 9 | 50 | 66 |  |  | 26 | $data_type='ARY-HSH' if ref $data eq 'ARRAY' and ref $data->[0] eq 'HASH'; | 
| 62 | 9 | 100 | 66 |  |  | 27 | $data_type='ARY-STR' if ref $data eq 'ARRAY' and !$data_type; | 
| 63 | 9 |  | 100 |  |  | 31 | $data_type ||= 'STR'; | 
| 64 |  |  |  |  |  |  | # print "[$data_type]" . ref $data if $data; | 
| 65 |  |  |  |  |  |  | # MP3 and ARRAY | 
| 66 | 9 | 50 | 33 |  |  | 46 | if ( $self->{records} && !$data )  { | 
|  |  | 100 |  |  |  |  |  | 
| 67 | 0 |  |  |  |  | 0 | $table_ary = $self->{records}; | 
| 68 | 0 |  | 0 |  |  | 0 | $col_names ||= shift @$table_ary; | 
| 69 |  |  |  |  |  |  | } | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | # REMOTE | 
| 72 |  |  |  |  |  |  | elsif ( $data ) { | 
| 73 | 3 | 50 |  |  |  | 6 | if ($parser->{slurp_mode}) { | 
| 74 | 0 |  |  |  |  | 0 | ($table_ary,$col_names) = $parser->import($data,$self); | 
| 75 | 0 | 0 | 0 |  |  | 0 | shift @$table_ary if (ref $parser) =~ /HTMLtable/ && $url && $cols_supplied; | 
|  |  |  | 0 |  |  |  |  | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  | else { | 
| 78 | 3 | 100 |  |  |  | 7 | if ($data_type eq 'ARY-STR') { | 
| 79 | 1 |  |  |  |  | 3 | $data = join '', @$data; | 
| 80 |  |  |  |  |  |  | } | 
| 81 | 3 | 50 |  |  |  | 11 | if ($data_type eq 'ARY-ARY') { | 
|  |  | 50 |  |  |  |  |  | 
| 82 | 0 |  |  |  |  | 0 | $table_ary = $data; | 
| 83 |  |  |  |  |  |  | } | 
| 84 |  |  |  |  |  |  | elsif ($data_type eq 'ARY-HSH') { | 
| 85 | 0 |  |  |  |  | 0 | print "IMPORT OF HASHES NOT YET IMPLEMENTED!\n"; exit; | 
|  | 0 |  |  |  |  | 0 |  | 
| 86 |  |  |  |  |  |  | } | 
| 87 |  |  |  |  |  |  | else { | 
| 88 | 3 |  |  |  |  | 4 | $data =~ s/\015$//gsm;  # ^M = CR from DOS | 
| 89 |  |  |  |  |  |  | #use Data::Dumper; print Dumper $data; | 
| 90 | 3 |  |  |  |  | 38 | my @tmp = split  /$rec_sep/, $data; | 
| 91 |  |  |  |  |  |  | #use Data::Dumper; print ref $parser, Dumper \@tmp; | 
| 92 | 3 | 50 | 0 |  |  | 13 | if ((ref $parser) =~ /Fixed/ && (!$col_names or !scalar @$col_names)) { | 
|  |  |  | 33 |  |  |  |  | 
| 93 | 0 |  |  |  |  | 0 | my $colstr = shift @tmp; | 
| 94 |  |  |  |  |  |  | # $colstr =~ s/\015$//g;  # ^M = CR from DOS | 
| 95 | 0 |  |  |  |  | 0 | @$col_names = split ',',$colstr; | 
| 96 |  |  |  |  |  |  | } | 
| 97 | 3 | 50 |  |  |  | 8 | if ((ref $parser) =~ /Paragraph/) { | 
| 98 | 0 |  |  |  |  | 0 | my $colstr = shift @tmp; | 
| 99 | 0 |  |  |  |  | 0 | @$col_names = $parser->read_fields($colstr); | 
| 100 |  |  |  |  |  |  | #print "@$col_names"; | 
| 101 |  |  |  |  |  |  | } | 
| 102 | 3 |  |  |  |  | 7 | for my $line( @tmp ) { | 
| 103 |  |  |  |  |  |  | #        for (split  /$rec_sep/, $data) { | 
| 104 |  |  |  |  |  |  | #            s/\015$//g;  # ^M = CR from DOS | 
| 105 | 14 | 50 | 33 |  |  | 28 | next if $parser->{skip_pattern} and $line =~ $parser->{skip_pattern}; | 
| 106 | 14 |  |  |  |  | 30 | 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 |  |  |  |  | 25 | push @$table_ary, \@row | 
| 113 |  |  |  |  |  |  | #                    unless $parser->{skip_mark} | 
| 114 |  |  |  |  |  |  | #                       and $row[0] eq $parser->{skip_mark}; | 
| 115 |  |  |  |  |  |  | # | 
| 116 |  |  |  |  |  |  | } | 
| 117 |  |  |  |  |  |  | } | 
| 118 | 3 | 50 | 33 |  |  | 30 | if ((ref $parser) !~ /Fixed|Paragraph/ | 
|  |  |  | 66 |  |  |  |  | 
| 119 |  |  |  |  |  |  | && !$parser->{keep_first_line} | 
| 120 |  |  |  |  |  |  | && !$parser->{col_names} | 
| 121 |  |  |  |  |  |  | ) { | 
| 122 | 2 |  |  |  |  | 3 | $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 | 50 |  |  |  | 30 | if ((ref $parser) !~ /XML/ ) { | 
| 129 | 9 | 50 |  |  |  | 26 | my $size = scalar @$table_ary if defined $table_ary; | 
| 130 | 9 | 100 | 66 |  |  | 60 | if ($file and !(ref $file eq 'ARRAY') and !$size ) { | 
|  |  |  | 66 |  |  |  |  | 
| 131 | 1 | 50 |  |  |  | 6 | if ($file =~ m'^http://|ftp://') { | 
| 132 |  |  |  |  |  |  | # ($table_ary,$col_names) = | 
| 133 |  |  |  |  |  |  | # $self->get_remote_data($file,$parser); | 
| 134 |  |  |  |  |  |  | } | 
| 135 |  |  |  |  |  |  | else { | 
| 136 | 1 |  |  |  |  | 5 | ($table_ary,$col_names) = | 
| 137 |  |  |  |  |  |  | $self->get_local_data($file,$parser,$read_mode); | 
| 138 |  |  |  |  |  |  | } | 
| 139 |  |  |  |  |  |  | } | 
| 140 |  |  |  |  |  |  | } | 
| 141 | 9 | 50 |  |  |  | 39 | my @array = @$col_names if ref $col_names eq 'ARRAY'; | 
| 142 |  |  |  |  |  |  | #print "@array" if @array; | 
| 143 | 9 | 50 | 33 |  |  | 50 | if ($col_names && scalar @array == 0 ) { | 
| 144 | 0 | 0 |  |  |  | 0 | @array = (ref $parser =~ /Fixed/) | 
| 145 |  |  |  |  |  |  | ? split ',', $col_names | 
| 146 |  |  |  |  |  |  | : $parser->read_fields($col_names); | 
| 147 |  |  |  |  |  |  | } | 
| 148 | 9 |  |  |  |  | 15 | my $col_nums; | 
| 149 | 9 | 50 |  |  |  | 57 | $col_nums = $self->set_col_nums() if $col_names; | 
| 150 | 9 |  |  |  |  | 40 | my %table = ( | 
| 151 |  |  |  |  |  |  | index => 0, | 
| 152 |  |  |  |  |  |  | file => $file, | 
| 153 |  |  |  |  |  |  | records => $table_ary, | 
| 154 |  |  |  |  |  |  | col_nums => $col_nums, | 
| 155 |  |  |  |  |  |  | col_names => \@array, | 
| 156 |  |  |  |  |  |  | ); | 
| 157 | 9 |  |  |  |  | 25 | for my $key(keys %table) { | 
| 158 | 45 |  |  |  |  | 86 | $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 |  |  | 0 | 0 | 0 | sub close { my $s = shift; undef $s } | 
|  | 0 |  |  |  |  | 0 |  | 
| 165 |  |  |  |  |  |  |  | 
| 166 |  |  |  |  |  |  | sub get_remote_data { | 
| 167 | 0 |  |  | 0 | 0 | 0 | my $self   = shift; | 
| 168 | 0 |  |  |  |  | 0 | my $file   = shift; | 
| 169 | 0 |  |  |  |  | 0 | my $parser = shift; | 
| 170 | 0 | 0 |  |  |  | 0 | $ENV = {} unless defined $ENV; | 
| 171 | 0 |  |  |  |  | 0 | $^W = 0; | 
| 172 | 0 |  |  |  |  | 0 | undef $@; | 
| 173 | 0 |  | 0 |  |  | 0 | my $user = $self->{user} || $self->{username}; | 
| 174 | 0 |  | 0 |  |  | 0 | my $pass = $self->{pass} || $self->{password}; | 
| 175 | 0 |  |  |  |  | 0 | eval{ require 'LWP/UserAgent.pm'; }; | 
|  | 0 |  |  |  |  | 0 |  | 
| 176 |  |  |  |  |  |  | #    eval{ require 'File/DosGlob.pm'; }; | 
| 177 | 0 | 0 |  |  |  | 0 | die "LWP module not found! $@" if $@; | 
| 178 | 0 |  |  |  |  | 0 | my $ua   = LWP::UserAgent->new; | 
| 179 | 0 |  |  |  |  | 0 | my $req  = HTTP::Request->new(GET => $file); | 
| 180 | 0 | 0 | 0 |  |  | 0 | $req->authorization_basic($user, $pass) if $user and $pass; | 
| 181 | 0 |  |  |  |  | 0 | my $res  = $ua->request($req); | 
| 182 | 0 | 0 |  |  |  | 0 | die "[$file] : " . $res->message if !$res->is_success; | 
| 183 | 0 |  |  |  |  | 0 | $^W = 1; | 
| 184 | 0 |  |  |  |  | 0 | return $res->content; | 
| 185 |  |  |  |  |  |  | #    return $parser->get_data($res->content,$self->{col_names}); | 
| 186 |  |  |  |  |  |  | } | 
| 187 |  |  |  |  |  |  | sub export { | 
| 188 | 0 |  |  | 0 | 0 | 0 | my $self   = shift; | 
| 189 | 0 |  |  |  |  | 0 | my $parser = shift; | 
| 190 | 0 |  |  |  |  | 0 | print "##"; | 
| 191 | 0 | 0 | 0 |  |  | 0 | return unless $parser->{export_on_close} && $self->{open_mode} ne 'r'; | 
| 192 |  |  |  |  |  |  | #    return $parser->export( $self->{records}, $self->{col_names}, $self->{deleted} ); | 
| 193 |  |  |  |  |  |  | #$self->{file_manager}->str2file($str); | 
| 194 |  |  |  |  |  |  | } | 
| 195 |  |  |  |  |  |  |  | 
| 196 |  |  |  | 0 |  |  | sub DESTROY { | 
| 197 |  |  |  |  |  |  | #shift->export; | 
| 198 |  |  |  |  |  |  | #print "DESTROY"; | 
| 199 |  |  |  |  |  |  | } | 
| 200 |  |  |  |  |  |  |  | 
| 201 |  |  |  |  |  |  | sub get_local_data { | 
| 202 | 1 |  |  | 1 | 0 | 1 | my $self      = shift; | 
| 203 | 1 |  |  |  |  | 3 | my $file      = shift; | 
| 204 | 1 |  |  |  |  | 1 | my $parser    = shift; | 
| 205 | 1 |  | 50 |  |  | 4 | my $open_mode = shift || 'r'; | 
| 206 | 1 |  |  |  |  | 11 | my $adf  = AnyData::Storage::File->new; | 
| 207 |  |  |  |  |  |  | #    $adf->open_table($parser,$file,'r'); | 
| 208 | 1 |  |  |  |  | 5 | my $fh   = $adf->open_local_file($file,$open_mode); | 
| 209 |  |  |  |  |  |  | #print Dumper $file,$adf; exit; | 
| 210 | 1 |  |  |  |  | 4 | $self->{file_manager} = $adf; | 
| 211 | 1 |  |  |  |  | 2 | $self->{fh} = $fh; | 
| 212 |  |  |  |  |  |  | #use Data::Dumper; print Dumper $self; | 
| 213 |  |  |  |  |  |  | #    my $fh = $adf->{fh}; | 
| 214 | 1 | 50 |  |  |  | 14 | return([],$self->{col_names}) if 'co' =~ /$open_mode/; | 
| 215 |  |  |  |  |  |  | #    if ((ref $parser) =~ /HTML/) { | 
| 216 |  |  |  |  |  |  | #      print "[[$file]]"; | 
| 217 |  |  |  |  |  |  | #      for (<$fh>) { print;  } | 
| 218 |  |  |  |  |  |  | #    } | 
| 219 | 0 |  |  |  |  | 0 | local $/ = undef; | 
| 220 | 0 |  |  |  |  | 0 | my $str = <$fh>; | 
| 221 |  |  |  |  |  |  | #    $fh->close; | 
| 222 |  |  |  |  |  |  | #print $str if (ref $parser) =~ /HTML/; | 
| 223 | 0 | 0 |  |  |  | 0 | return $self->{col_names} unless $str; | 
| 224 | 0 |  |  |  |  | 0 | return $parser->get_data($str,$self->{col_names}); | 
| 225 |  |  |  |  |  |  | } | 
| 226 |  |  |  |  |  |  | sub dump { | 
| 227 | 0 |  |  | 0 | 0 | 0 | my $self = shift; | 
| 228 |  |  |  |  |  |  | print | 
| 229 | 0 |  |  |  |  | 0 | "\nTotal Rows  = ", scalar @{ $self->{records} }, | 
| 230 |  |  |  |  |  |  | "\nCurrent Row = ", $self->{index}, | 
| 231 |  |  |  |  |  |  | "\nData        = ", Dumper $self->{records}, | 
| 232 | 0 |  |  |  |  | 0 | ; | 
| 233 |  |  |  |  |  |  | } | 
| 234 |  |  |  |  |  |  |  | 
| 235 | 0 |  |  | 0 | 0 | 0 | sub col_names { shift->{col_names} } | 
| 236 |  |  |  |  |  |  | sub get_col_names { | 
| 237 | 0 |  |  | 0 | 0 | 0 | my $self=shift; | 
| 238 | 0 |  |  |  |  | 0 | my $parser=shift; | 
| 239 | 0 |  | 0 |  |  | 0 | my $c = $self->{col_names} || $parser->{col_names}; | 
| 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 |  |  | 0 | 0 | 0 | sub get_file_handle {''} | 
| 248 | 0 |  |  | 0 | 0 | 0 | sub get_file_name {''} | 
| 249 |  |  |  |  |  |  |  | 
| 250 | 46 |  |  | 46 | 0 | 88 | sub seek_first_record { shift->{index}=0 } | 
| 251 |  |  |  |  |  |  |  | 
| 252 | 222 |  |  | 222 | 0 | 179 | sub get_pos { my $s=shift; $s->{CUR}= $s->{index}} | 
|  | 222 |  |  |  |  | 226 |  | 
| 253 | 0 |  |  | 0 | 0 | 0 | sub go_pos {my $s=shift;$s->{index}=$s->{CUR}} | 
|  | 0 |  |  |  |  | 0 |  | 
| 254 |  |  |  |  |  |  |  | 
| 255 | 222 |  |  | 222 | 0 | 182 | sub is_deleted { my $s=shift; return $s->{deleted}->{$s->{index}-1} }; | 
|  | 222 |  |  |  |  | 606 |  | 
| 256 |  |  |  |  |  |  |  | 
| 257 |  |  |  |  |  |  | sub delete_record { | 
| 258 | 12 |  |  | 12 | 0 | 19 | my $self = shift; | 
| 259 |  |  |  |  |  |  | #    $self->{records}->[ $self->{index}-1 ]->[-1] = $self->{del_marker}; | 
| 260 | 12 |  |  |  |  | 42 | $self->{deleted}->{ $self->{index}-1 }++; | 
| 261 |  |  |  |  |  |  | } | 
| 262 |  |  |  |  |  |  |  | 
| 263 |  |  |  |  |  |  | ################################## | 
| 264 |  |  |  |  |  |  | # fetch_row() | 
| 265 |  |  |  |  |  |  | ################################## | 
| 266 |  |  |  |  |  |  | sub get_record { | 
| 267 | 256 |  |  | 256 | 0 | 232 | my($self,$parser) = @_; | 
| 268 | 256 |  |  |  |  | 228 | my $currentRow = $self->{index}; | 
| 269 | 256 | 50 |  |  |  | 393 | return undef unless $self->{records} ; | 
| 270 | 256 | 100 |  |  |  | 203 | return undef if $currentRow >= @{ $self->{records} }; | 
|  | 256 |  |  |  |  | 470 |  | 
| 271 | 222 |  |  |  |  | 216 | $self->{index} = $currentRow+1; | 
| 272 | 222 |  |  |  |  | 269 | $self->get_pos($self->{index}); | 
| 273 |  |  |  |  |  |  | #print  @{ $self->{records}->[ $currentRow ] }; | 
| 274 | 222 |  |  |  |  | 392 | return $self->{records}->[ $currentRow ]; | 
| 275 |  |  |  |  |  |  | } | 
| 276 |  |  |  |  |  |  | *file2str = \&get_record; | 
| 277 |  |  |  |  |  |  |  | 
| 278 |  |  |  |  |  |  |  | 
| 279 |  |  |  |  |  |  | *write_fields = \&push_row; | 
| 280 |  |  |  |  |  |  | #################################### | 
| 281 |  |  |  |  |  |  | # push_row() | 
| 282 |  |  |  |  |  |  | #################################### | 
| 283 |  |  |  |  |  |  | sub push_row { | 
| 284 | 42 |  |  | 42 | 0 | 52 | my($self, $fields, $parser) = @_; | 
| 285 | 42 | 100 |  |  |  | 73 | if (! ref $fields) { | 
| 286 | 36 |  |  |  |  | 98 | $fields =~ s/\012$//; | 
| 287 |  |  |  |  |  |  | #chomp $fields; | 
| 288 | 36 |  |  |  |  | 96 | my @rec = $parser->read_fields($fields); | 
| 289 | 36 |  |  |  |  | 77 | $fields = \@rec; | 
| 290 |  |  |  |  |  |  | } | 
| 291 |  |  |  |  |  |  |  | 
| 292 |  |  |  |  |  |  | #use Data::Dumper; print Dumper $fields; | 
| 293 | 42 |  |  |  |  | 48 | my $currentRow = $self->{index}; | 
| 294 | 42 |  |  |  |  | 46 | $self->{index} = $currentRow+1; | 
| 295 | 42 |  |  |  |  | 113 | $self->{records}->[$currentRow] = $fields; | 
| 296 | 42 |  |  |  |  | 144 | return 1; | 
| 297 |  |  |  |  |  |  | } | 
| 298 |  |  |  |  |  |  |  | 
| 299 |  |  |  |  |  |  | ################################## | 
| 300 |  |  |  |  |  |  | # truncate() | 
| 301 |  |  |  |  |  |  | ################################## | 
| 302 |  |  |  |  |  |  | sub truncate { | 
| 303 | 0 |  |  | 0 | 0 | 0 | my $self = shift; | 
| 304 | 0 |  |  |  |  | 0 | return splice @{$self->{records}}, $self->{index},1; | 
|  | 0 |  |  |  |  | 0 |  | 
| 305 |  |  |  |  |  |  | } | 
| 306 |  |  |  |  |  |  |  | 
| 307 |  |  |  |  |  |  | ##################################### | 
| 308 |  |  |  |  |  |  | # push_names() | 
| 309 |  |  |  |  |  |  | ##################################### | 
| 310 |  |  |  |  |  |  | sub print_col_names { | 
| 311 | 0 |  |  | 0 | 0 | 0 | my($self, $parser, $names) = @_; | 
| 312 | 0 |  |  |  |  | 0 | $self->{col_names} = $names; | 
| 313 | 0 |  |  |  |  | 0 | $self->{parser}->{col_names} = $names; | 
| 314 | 0 |  |  |  |  | 0 | my($col_nums) = {}; | 
| 315 | 0 |  |  |  |  | 0 | for (my $i = 0;  $i < @$names;  $i++) { | 
| 316 | 0 |  |  |  |  | 0 | $col_nums->{$names->[$i]} = $i; | 
| 317 |  |  |  |  |  |  | } | 
| 318 | 0 |  |  |  |  | 0 | $self->{col_nums} = $col_nums; | 
| 319 |  |  |  |  |  |  | } | 
| 320 |  |  |  |  |  |  |  | 
| 321 | 0 |  |  | 0 | 0 | 0 | sub drop  {1;} | 
| 322 | 0 |  |  | 0 | 0 | 0 | sub close_table {1;} | 
| 323 |  |  |  |  |  |  |  | 
| 324 |  |  |  |  |  |  | sub seek { | 
| 325 | 36 |  |  | 36 | 0 | 39 | my($self, $pos, $whence) = @_; | 
| 326 | 36 | 50 |  |  |  | 71 | return unless defined $self->{records}; | 
| 327 | 36 |  |  |  |  | 38 | my($currentRow) = $self->{index}; | 
| 328 | 36 | 50 |  |  |  | 96 | if ($whence == 0) { | 
|  |  | 50 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
| 329 | 0 |  |  |  |  | 0 | $currentRow = $pos; | 
| 330 |  |  |  |  |  |  | } elsif ($whence == 1) { | 
| 331 | 0 |  |  |  |  | 0 | $currentRow += $pos; | 
| 332 |  |  |  |  |  |  | } elsif ($whence == 2) { | 
| 333 | 36 |  |  |  |  | 20 | $currentRow = @{$self->{records}} + $pos; | 
|  | 36 |  |  |  |  | 40 |  | 
| 334 |  |  |  |  |  |  | } else { | 
| 335 | 0 |  |  |  |  | 0 | die $self . "->seek: Illegal whence argument ($whence)"; | 
| 336 |  |  |  |  |  |  | } | 
| 337 | 36 | 50 |  |  |  | 65 | if ($currentRow < 0) { | 
| 338 | 0 |  |  |  |  | 0 | die "Illegal row number: $currentRow"; | 
| 339 |  |  |  |  |  |  | } | 
| 340 | 36 |  |  |  |  | 72 | $self->{index} = $currentRow; | 
| 341 |  |  |  |  |  |  | } | 
| 342 |  |  |  |  |  |  |  | 
| 343 |  |  |  |  |  |  |  | 
| 344 |  |  |  |  |  |  | ############################################################################ | 
| 345 |  |  |  |  |  |  | 1; | 
| 346 |  |  |  |  |  |  | __END__ |