Mark forgotten ::Row::id() method as indirect_sugar
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage.pm
index 032b247..dfff9a1 100644 (file)
@@ -6,17 +6,17 @@ use warnings;
 use base qw/DBIx::Class/;
 use mro 'c3';
 
-{
-  package # Hide from PAUSE
-    DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION;
-  use base 'DBIx::Class::Exception';
+BEGIN {
+  no warnings 'once';
+  @DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION::ISA
+    = 'DBIx::Class::Exception';
 }
 
 use DBIx::Class::Carp;
 use DBIx::Class::Storage::BlockRunner;
 use Scalar::Util qw/blessed weaken/;
 use DBIx::Class::Storage::TxnScopeGuard;
-use Try::Tiny;
+use DBIx::Class::_Util qw( dbic_internal_try dbic_internal_catch fail_on_internal_call );
 use namespace::clean;
 
 __PACKAGE__->mk_group_accessors(simple => qw/debug schema transaction_depth auto_savepoint savepoints/);
@@ -24,7 +24,10 @@ __PACKAGE__->mk_group_accessors(component_class => 'cursor_class');
 
 __PACKAGE__->cursor_class('DBIx::Class::Cursor');
 
-sub cursor { shift->cursor_class(@_); }
+sub cursor :DBIC_method_is_indirect_sugar {
+  DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_INDIRECT_CALLS and fail_on_internal_call;
+  shift->cursor_class(@_);
+}
 
 =head1 NAME
 
@@ -148,7 +151,7 @@ For example,
   my $rs;
   try {
     $rs = $schema->txn_do($coderef);
-  } catch {
+  } dbic_internal_catch {
     my $error = shift;
     # Transaction failed
     die "something terrible has happened!"
@@ -253,12 +256,12 @@ sub txn_rollback {
     $self->{transaction_depth}--;
 
     # in case things get really hairy - just disconnect
-    eval { $self->_exec_txn_rollback; 1 } or do {
+    dbic_internal_try { $self->_exec_txn_rollback; 1 } or do {
       my $rollback_error = $@;
 
       # whatever happens, too low down the stack to care
       # FIXME - revisit if stackable exceptions become a thing
-      eval { $self->disconnect };
+      dbic_internal_try { $self->disconnect };
 
       die $rollback_error;
     };
@@ -310,16 +313,19 @@ sub __delicate_rollback {
     return;
   }
 
+  my @args = @_;
   my $rbe;
 
-  local $@; # taking no chances
-  unless( eval { $self->txn_rollback; 1 } ) {
+  dbic_internal_try {
+    $self->txn_rollback; 1
+  }
+  dbic_internal_catch {
 
-    $rbe = $@;
+    $rbe = $_;
 
     # we were passed an existing exception to augment (think DESTROY stacks etc)
-    if (@_) {
-      my $exception = shift;
+    if (@args) {
+      my ($exception) = @args;
 
       # append our text - THIS IS A TEMPORARY FIXUP!
       #
@@ -367,7 +373,7 @@ sub __delicate_rollback {
         ) =~ s/Transaction aborted: (?=Transaction aborted:)//;
       }
     }
-  }
+  };
 
   return $rbe;
 }
@@ -427,12 +433,15 @@ sub svp_release {
 
   if (defined $name) {
     my @stack = @{ $self->savepoints };
-    my $svp;
+    my $svp = '';
 
-    do { $svp = pop @stack } until $svp eq $name;
+    while( $svp ne $name ) {
 
-    $self->throw_exception ("Savepoint '$name' does not exist")
-      unless $svp;
+      $self->throw_exception ("Savepoint '$name' does not exist")
+        unless @stack;
+
+      $svp = pop @stack;
+    }
 
     $self->savepoints(\@stack); # put back what's left
   }
@@ -572,11 +581,15 @@ sub debugobj {
       my @pp_args;
 
       if ($profile =~ /^\.?\//) {
-        require Config::Any;
 
-        my $cfg = try {
+        require DBIx::Class::Optional::Dependencies;
+        if ( my $missing = DBIx::Class::Optional::Dependencies->req_missing_for ('config_file_reader') ) {
+          $self->throw_exception("Unable to parse TRACE_PROFILE config file '$profile' without $missing");
+        }
+
+        my $cfg = dbic_internal_try {
           Config::Any->load_files({ files => [$profile], use_ext => 1 });
-        } catch {
+        } dbic_internal_catch {
           # sanitize the error message a bit
           $_ =~ s/at \s+ .+ Storage\.pm \s line \s \d+ $//x;
           $self->throw_exception("Failure processing \$ENV{DBIC_TRACE_PROFILE}: $_");
@@ -600,9 +613,9 @@ sub debugobj {
       #
       # Yes I am aware this is fragile and TxnScopeGuard needs
       # a better fix. This is another yak to shave... :(
-      try {
+      dbic_internal_try {
         DBIx::Class::Storage::Debug::PrettyPrint->new(@pp_args);
-      } catch {
+      } dbic_internal_catch {
         $self->throw_exception($_);
       }
     }