Improve exception text during write operations on uninserted objects
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Schema.pm
index 83d7e09..1bf1965 100644 (file)
@@ -6,12 +6,10 @@ use warnings;
 use base 'DBIx::Class';
 
 use DBIx::Class::Carp;
-use Try::Tiny;
 use Scalar::Util qw( weaken blessed refaddr );
 use DBIx::Class::_Util qw(
-  false emit_loud_diag refdesc
-  refcount quote_sub scope_guard
-  is_exception dbic_internal_try
+  refdesc refcount quote_sub scope_guard
+  is_exception dbic_internal_try dbic_internal_catch
   fail_on_internal_call emit_loud_diag
 );
 use Devel::GlobalDestruction;
@@ -30,7 +28,6 @@ __PACKAGE__->mk_classaccessor('source_registrations' => {});
 
 __PACKAGE__->mk_group_accessors( component_class => 'schema_sanity_checker' );
 __PACKAGE__->schema_sanity_checker(
-  DBIx::Class::_ENV_::OLD_MRO ? false :
   'DBIx::Class::Schema::SanityChecker'
 );
 
@@ -207,7 +204,7 @@ sub _ns_get_rsrc_instance {
 
   return dbic_internal_try {
     $rs_class->result_source
-  } catch {
+  } dbic_internal_catch {
     $me->throw_exception (
       "Attempt to load_namespaces() class $rs_class failed - are you sure this is a real Result Class?: $_"
     );
@@ -244,10 +241,6 @@ sub load_namespaces {
 
   my @to_register;
   {
-    no warnings qw/redefine/;
-    local *Class::C3::reinitialize = sub { } if DBIx::Class::_ENV_::OLD_MRO;
-    use warnings qw/redefine/;
-
     # ensure classes are loaded and attached in inheritance order
     for my $result_class (values %$results_by_source_name) {
       $class->ensure_class_loaded($result_class);
@@ -301,8 +294,6 @@ sub load_namespaces {
         .'with no corresponding Result class';
   }
 
-  Class::C3->reinitialize if DBIx::Class::_ENV_::OLD_MRO;
-
   $class->register_class(@$_) for (@to_register);
 
   return;
@@ -384,10 +375,6 @@ sub load_classes {
 
   my @to_register;
   {
-    no warnings qw/redefine/;
-    local *Class::C3::reinitialize = sub { } if DBIx::Class::_ENV_::OLD_MRO;
-    use warnings qw/redefine/;
-
     foreach my $prefix (keys %comps_for) {
       foreach my $comp (@{$comps_for{$prefix}||[]}) {
         my $comp_class = "${prefix}::${comp}";
@@ -404,7 +391,6 @@ sub load_classes {
       }
     }
   }
-  Class::C3->reinitialize if DBIx::Class::_ENV_::OLD_MRO;
 
   foreach my $to (@to_register) {
     $class->register_class(@$to);
@@ -927,7 +913,7 @@ sub connection {
   dbic_internal_try {
     $self->ensure_class_loaded ($storage_class);
   }
-  catch {
+  dbic_internal_catch {
     $self->throw_exception(
       "Unable to load storage class ${storage_class}: $_"
     );
@@ -937,47 +923,6 @@ sub connection {
   $storage->connect_info(\@info);
   $self->storage($storage);
 
-
-###
-### Begin 5.8 "you have not selected a checker" warning
-###
-  # We can not blanket-enable this on 5.8 - it is just too expensive for
-  # day to day execution. We also can't just go silent - there are genuine
-  # regressions ( due to core changes) for which this is the only line of
-  # defense. So instead we whine on STDERR that folks need to do something
-  #
-  # Beyond suboptimal, but given the constraints the best we can do :(
-  #
-  # This should stay around for at least 3~4 years
-  #
-  DBIx::Class::_ENV_::OLD_MRO
-    and
-  ! $default_off_stderr_blurb_emitted
-    and
-  length ref $self->schema_sanity_checker
-    and
-  length ref __PACKAGE__->schema_sanity_checker
-    and
-  (
-    refaddr( $self->schema_sanity_checker )
-      ==
-    refaddr( __PACKAGE__->schema_sanity_checker )
-  )
-    and
-  emit_loud_diag(
-    msg => sprintf(
-    "Sanity checks for schema %s are disabled on this perl $]: "
-  . '*THIS IS POTENTIALLY VERY DANGEROUS*. You are strongly urged to '
-  . "read http://is.gd/dbic_sancheck_5_008 before proceeding\n",
-    ( defined( blessed $self ) ? refdesc $self : "'$self'" )
-  ))
-    and
-  $default_off_stderr_blurb_emitted = 1;
-###
-### End 5.8 "you have not selected a checker" warning
-###
-
-
   if( my $checker = $self->schema_sanity_checker ) {
     $checker->perform_schema_sanity_checks($self);
   }
@@ -1041,10 +986,6 @@ sub compose_namespace {
   #$schema->class_mappings({});
 
   {
-    no warnings qw/redefine/;
-    local *Class::C3::reinitialize = sub { } if DBIx::Class::_ENV_::OLD_MRO;
-    use warnings qw/redefine/;
-
     foreach my $source_name ($self->sources) {
       my $orig_source = $self->source($source_name);
 
@@ -1064,7 +1005,8 @@ sub compose_namespace {
       for qw(class source resultset);
   }
 
-  Class::C3->reinitialize() if DBIx::Class::_ENV_::OLD_MRO;
+  # needed to cover the newly installed stuff via quote_sub above
+  Class::C3->reinitialize if DBIx::Class::_ENV_::OLD_MRO;
 
   # Give each composed class yet another *schema-less* source copy
   # this is used for the freeze/thaw cycle
@@ -1266,7 +1208,7 @@ This guard was activated starting",
 
       1;
     }
-    catch {
+    dbic_internal_catch {
       # We call this to get the necessary warnings emitted and disregard the RV
       # as it's definitely an exception if we got as far as this catch{} block
       is_exception(
@@ -1731,7 +1673,7 @@ sub compose_connection {
   dbic_internal_try {
     require DBIx::Class::ResultSetProxy;
   }
-  catch {
+  dbic_internal_catch {
     $self->throw_exception
       ("No arguments to load_classes and couldn't load DBIx::Class::ResultSetProxy ($_)")
   };
@@ -1752,6 +1694,9 @@ sub compose_connection {
   my $schema = $self->compose_namespace($target, 'DBIx::Class::ResultSetProxy');
   quote_sub "${target}::schema", '$s', { '$s' => \$schema };
 
+  # needed to cover the newly installed stuff via quote_sub above
+  Class::C3->reinitialize if DBIx::Class::_ENV_::OLD_MRO;
+
   $schema->connection(@info);
   foreach my $source_name ($schema->sources) {
     my $source = $schema->source($source_name);