]> wagnertech.de Git - mfinanz.git/commitdiff
Csv Errors sind nun Objekte mit entsprechendem Zugriff.
authorSven Schöling <s.schoeling@linet-services.de>
Wed, 2 Mar 2011 11:02:42 +0000 (12:02 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Thu, 16 Jun 2011 06:44:07 +0000 (08:44 +0200)
SL/Helper/Csv.pm
SL/Helper/Csv/Dispatcher.pm
SL/Helper/Csv/Error.pm [new file with mode: 0644]
t/helper/csv.t

index 5aac00b486f421939f3c4149d552cc7c5ad95ee9..945758f5d3c1084df00dc906b539e2a43b018f3f 100644 (file)
@@ -14,6 +14,7 @@ use Rose::Object::MakeMethods::Generic scalar => [ qw(
 ) ];
 
 use SL::Helper::Csv::Dispatcher;
 ) ];
 
 use SL::Helper::Csv::Dispatcher;
+use SL::Helper::Csv::Error;
 
 # public interface
 
 
 # public interface
 
@@ -180,7 +181,7 @@ sub _guess_encoding {
 
 sub _push_error {
   my ($self, @errors) = @_;
 
 sub _push_error {
   my ($self, @errors) = @_;
-  my @new_errors = ($self->errors, @errors);
+  my @new_errors = ($self->errors, map { SL::Helper::Csv::Error->new(@$_) } @errors);
   $self->_errors(\@new_errors);
 }
 
   $self->_errors(\@new_errors);
 }
 
@@ -346,16 +347,13 @@ but deactivated by default.
 =head1 ERROR HANDLING
 
 After parsing a file all errors will be accumulated into C<errors>.
 =head1 ERROR HANDLING
 
 After parsing a file all errors will be accumulated into C<errors>.
+Each entry is an object with the following attributes:
 
 
-Each entry is an arrayref with the following structure:
-
- [
- 0  offending raw input,
- 1  Text::CSV error code if Text:CSV signalled an error, 0 else,
- 2  error diagnostics,
- 3  position in line,
- 4  estimated line in file,
- ]
+ raw_input:  offending raw input,
+ code:   Text::CSV error code if Text:CSV signalled an error, 0 else,
+ diag:   error diagnostics,
+ line:   position in line,
+ col:    estimated line in file,
 
 Note that the last entry can be off, but will give an estimate.
 
 
 Note that the last entry can be off, but will give an estimate.
 
index a8d29fe4538894d1fc7e0ed9bbf2f6d5dddd9772..cbcae0d82d87e192ecc362de02bac5235ff62537 100644 (file)
@@ -9,6 +9,8 @@ use Rose::Object::MakeMethods::Generic scalar => [ qw(
   _specs _errors
 ) ];
 
   _specs _errors
 ) ];
 
+use SL::Helper::Csv::Error;
+
 sub new {
   my ($class, $parent) = @_;
   my $self = bless { }, $class;
 sub new {
   my ($class, $parent) = @_;
   my $self = bless { }, $class;
@@ -137,7 +139,7 @@ sub errors {
 
 sub _push_error {
   my ($self, @errors) = @_;
 
 sub _push_error {
   my ($self, @errors) = @_;
-  my @new_errors = ($self->errors, @errors);
+  my @new_errors = ($self->errors, map { SL::Helper::Csv::Error->new(@$_) } @errors);
   $self->_errors(\@new_errors);
 }
 
   $self->_errors(\@new_errors);
 }
 
diff --git a/SL/Helper/Csv/Error.pm b/SL/Helper/Csv/Error.pm
new file mode 100644 (file)
index 0000000..d3c9144
--- /dev/null
@@ -0,0 +1,16 @@
+package SL::Helper::Csv::Error;
+
+use strict;
+
+sub new {
+  my $class = shift;
+  bless [ @_ ], $class;
+}
+
+sub raw_input { $_->[0] }
+sub code      { $_->[1] }
+sub diag      { $_->[2] }
+sub col       { $_->[3] }
+sub line      { $_->[4] }
+
+1;
index 0721434802c8931c5d5ebcde0fbe4358e02529eb..cc009940d7bf699e91f6aa935d6b6732ed122555 100644 (file)
@@ -125,6 +125,7 @@ EOL
 );
 is $csv->parse, undef, 'broken csv content won\'t get parsed';
 is_deeply $csv->errors, [ '"Kaf"fee";;0.12;1,221.52'."\n", 2023, 'EIQ - QUO character not allowed', 5, 2 ], 'error';
 );
 is $csv->parse, undef, 'broken csv content won\'t get parsed';
 is_deeply $csv->errors, [ '"Kaf"fee";;0.12;1,221.52'."\n", 2023, 'EIQ - QUO character not allowed', 5, 2 ], 'error';
+isa_ok( ($csv->errors)[0], 'SL::Helper::Csv::Error', 'Errors get objectified');
 
 ####
 
 
 ####
 
@@ -222,5 +223,6 @@ EOL
 );
 is $csv->parse, undef, 'wrong profile gets rejected';
 is_deeply $csv->errors, [ 'buchungsgruppen.1.description', undef, "Profile path error. Indexed relationship is not OneToMany around here: 'buchungsgruppen.1'", undef ,0 ], 'error indicates wrong header';
 );
 is $csv->parse, undef, 'wrong profile gets rejected';
 is_deeply $csv->errors, [ 'buchungsgruppen.1.description', undef, "Profile path error. Indexed relationship is not OneToMany around here: 'buchungsgruppen.1'", undef ,0 ], 'error indicates wrong header';
+isa_ok( ($csv->errors)[0], 'SL::Helper::Csv::Error', 'Errors get objectified');
 
 # vim: ft=perl
 
 # vim: ft=perl