Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Simplify down the two classes

  • Loading branch information...
commit 1286037754225881e5db2282049c79a48d97403e 1 parent b7745de
@jberger authored
Showing with 22 additions and 41 deletions.
  1. +22 −10 lib/Tie/Array/CSV.pm
  2. +0 −31 lib/Tie/Array/CSV/HoldRow.pm
View
32 lib/Tie/Array/CSV.pm
@@ -97,14 +97,10 @@ sub FETCH {
my $line = $self->{file}[$index];
- $self->{csv}->parse($line)
- or croak "CSV parse error: " . $self->{csv}->error_diag();
- my @fields = $self->{csv}->fields;
-
tie my @line, 'Tie::Array::CSV::Row', {
file => $self->{file},
line_num => $index,
- fields => \@fields,
+ fields => $self->_parse($line),
csv => $self->{csv},
};
@@ -115,11 +111,7 @@ sub STORE {
my $self = shift;
my ($index, $value) = @_;
- $self->{csv}->combine(
- ref $value ? @$value : ($value)
- )
- or croak "CSV combine error: " . $self->{csv}->error_diag();
- $self->{file}[$index] = $self->{csv}->string;
+ $self->{file}[$index] = $self->_combine($value);
}
sub FETCHSIZE {
@@ -150,6 +142,26 @@ sub EXISTS {
return $index < $self->FETCHSIZE;
}
+sub _parse {
+ my $self = shift;
+ my ($line) = @_;
+
+ $self->{csv}->parse($line)
+ or croak "CSV parse error: " . $self->{csv}->error_diag();
+
+ return [$self->{csv}->fields];
+}
+
+sub _combine {
+ my $self = shift;
+ my ($value) = @_;
+
+ $self->{csv}->combine( ref $value ? @$value : ($value) )
+ or croak "CSV combine error: " . $self->{csv}->error_diag();
+
+ return $self->{csv}->string;
+}
+
package Tie::Array::CSV::Row;
use Carp;
View
31 lib/Tie/Array/CSV/HoldRow.pm
@@ -139,17 +139,6 @@ sub POP {
return $val;
}
-sub FETCHSIZE {
- my $self = shift;
- return scalar @{ $self->{file} };
-}
-
-sub STORESIZE {
- my $self = shift;
- my $new_size = shift;
- $#{ $self->{file} } = $new_size - 1;
-}
-
sub CLEAR { shift->STORESIZE(0) }
sub EXISTS {
@@ -167,26 +156,6 @@ sub DELETE {
sub EXTEND { }
-sub _parse {
- my $self = shift;
- my ($line) = @_;
-
- $self->{csv}->parse($line)
- or croak "CSV parse error: " . $self->{csv}->error_diag();
-
- return [$self->{csv}->fields];
-}
-
-sub _combine {
- my $self = shift;
- my ($value) = @_;
-
- $self->{csv}->combine( ref $value ? @$value : ($value) )
- or croak "CSV combine error: " . $self->{csv}->error_diag();
-
- return $self->{csv}->string;
-}
-
package Tie::Array::CSV::HoldRow::Row;
use Carp;
Please sign in to comment.
Something went wrong with that request. Please try again.