Protect DBIC as best we can from the failure mode in 7cb35852
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Cursor.pm
index 4d15401..d900431 100644 (file)
@@ -5,9 +5,9 @@ use warnings;
 
 use base 'DBIx::Class::Cursor';
 
-use Try::Tiny;
 use Scalar::Util qw(refaddr weaken);
 use List::Util 'shuffle';
+use DBIx::Class::_Util qw( detected_reinvoked_destructor dbic_internal_try );
 use namespace::clean;
 
 __PACKAGE__->mk_group_accessors('simple' =>
@@ -233,6 +233,8 @@ sub reset {
 
 
 sub DESTROY {
+  return if &detected_reinvoked_destructor;
+
   $_[0]->__finish_sth if $_[0]->{sth};
 }
 
@@ -248,9 +250,31 @@ sub __finish_sth {
   my $self = shift;
 
   # No need to care about failures here
-  try { local $SIG{__WARN__} = sub {}; $self->{sth}->finish } if (
-    $self->{sth} and ! try { ! $self->{sth}->FETCH('Active') }
+  dbic_internal_try {
+    local $SIG{__WARN__} = sub {};
+    $self->{sth}->finish
+  } if (
+    $self->{sth}
+      and
+    # weird double-negative to catch the case of ->FETCH throwing
+    # and attempt a finish *anyway*
+    ! dbic_internal_try {
+      ! $self->{sth}->FETCH('Active')
+    }
   );
 }
 
+=head1 FURTHER QUESTIONS?
+
+Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
+
+=head1 COPYRIGHT AND LICENSE
+
+This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
+by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
+redistribute it and/or modify it under the same terms as the
+L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
+
+=cut
+
 1;