fix some error handler nits
authorMark Wells <mark@freeside.biz>
Wed, 1 Aug 2012 06:21:47 +0000 (23:21 -0700)
committerMark Wells <mark@freeside.biz>
Wed, 1 Aug 2012 06:21:47 +0000 (23:21 -0700)
BatchPayment/Processor.pm

index 2093132..e02259a 100644 (file)
@@ -170,6 +170,30 @@ sub default_transport {
   die blessed($self). " requires a transport or input/output files\n";
 }
 
+has 'on_format_error' => (
+  traits  => ['Code'],
+  is      => 'rw',
+  handles => { format_error => 'execute_method' },
+  default => sub { \&default_on_error },
+);
+
+has 'on_parse_error' => (
+  traits  => ['Code'],
+  is      => 'rw',
+  handles => { parse_error => 'execute_method' },
+  default => sub { \&default_on_error },
+);
+
+sub default_on_error { #re-throw it
+  my ($self, $item, $error) = @_;
+  $DB::single = 1 if defined($DB::single);
+  die $error;
+};
+
+# No error callbacks for other parts of this.  The per-item case 
+# is special in that it might make sense to continue with the 
+# other items.
+
 around BUILDARGS => sub {
   my ($orig, $class, %args) = @_;
   %args = %{ $class->$orig(%args) }; #process as usual
@@ -191,17 +215,20 @@ sub incoming { 0 };
 sub submit {
   my $self = shift;
   my $batch = shift;
-  my @items = @_;
   my $request = $self->format_request($batch);
   warn $request if $self->debug >= 2;
   $self->transport->upload($request);
 }
-
+;
 sub receive {
   my $self = shift;
   my @responses = $self->transport->download;
-  warn join("\n\n",@responses) if $self->debug >= 2 and scalar(@responses);
-  map { $self->parse_response($_) } @responses;
+  warn join("\n\n", @responses) if $self->debug >= 2 and scalar(@responses);
+  my @batches;
+  foreach my $response (@responses) {
+    push @batches, $self->parse_response($response);
+  }
+  @batches;
 }
 
 # next level down
@@ -214,8 +241,8 @@ sub format_request {
     try {
       $output .= $self->format_item($item, $batch);
     } catch {
-      $self->format_error($self, $item, $_);
-    }
+      $self->format_error($item, $_);
+    };
   }
   $output .= $self->format_trailer($batch);
   return $output;
@@ -230,7 +257,7 @@ sub parse_response {
   );
   while ( $input =~ s/(.*)\n//m ) {
     my $row = $1;
-    try {
+    try { 
       $batch->push( $self->parse_item($row) );
     } catch {
       $self->parse_error($row, $_);
@@ -248,27 +275,4 @@ sub format_item { die "format_item unimplemented\n" }
 sub parse_batch_id { '' };
 sub parse_item { die "parse_item unimplemented\n" }
 
-sub default_on_error { #re-throw it
-  my ($self, $item, $error) = @_;
-  die $error;
-};
-
-has 'on_format_error' => (
-  traits  => ['Code'],
-  is      => 'rw',
-  handles => { format_error => 'execute_method' },
-  default => sub { \&default_on_error },
-);
-
-has 'on_parse_error' => (
-  traits  => ['Code'],
-  is      => 'rw',
-  handles => { parse_error => 'execute_method' },
-  default => sub { \&default_on_error },
-);
-
-# No error callbacks for other parts of this.  The per-item case 
-# is special in that it might make sense to continue with the 
-# other items.
-
 1;