cycle tests and a weaken call
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Schema.pm
index e0cb8cc..9105477 100644 (file)
@@ -4,6 +4,7 @@ use strict;
 use warnings;
 
 use Carp::Clan qw/^DBIx::Class/;
+use Scalar::Util qw/weaken/;
 
 use base qw/DBIx::Class/;
 
@@ -63,7 +64,7 @@ particular which module inherits off which.
 
 =back
 
-Registers a class which isa L<DBIx::Class::ResultSourceProxy>. Equivalent to
+Registers a class which isa DBIx::Class::ResultSourceProxy. Equivalent to
 calling:
 
   $schema->register_source($moniker, $component_class->result_source_instance);
@@ -94,12 +95,13 @@ sub register_source {
   $reg{$moniker} = $source;
   $self->source_registrations(\%reg);
   $source->schema($self);
+  weaken($source->{schema}) if ref($self);
   if ($source->result_class) {
     my %map = %{$self->class_mappings};
     $map{$source->result_class} = $moniker;
     $self->class_mappings(\%map);
   }
-} 
+}
 
 =head2 class
 
@@ -207,7 +209,7 @@ need to add C<no warnings 'qw';> before your load_classes call.
 Example:
 
   My::Schema->load_classes(); # loads My::Schema::CD, My::Schema::Artist,
-                             # etc. (anything under the My::Schema namespace)
+                              # etc. (anything under the My::Schema namespace)
 
   # loads My::Schema::CD, My::Schema::Artist, Other::Namespace::Producer but
   # not Other::Namespace::LinerNotes nor My::Schema::Track
@@ -263,9 +265,9 @@ sub load_classes {
         my $comp_class = "${prefix}::${comp}";
         eval "use $comp_class"; # If it fails, assume the user fixed it
         if ($@) {
-         $comp_class =~ s/::/\//g;
+          $comp_class =~ s/::/\//g;
           die $@ unless $@ =~ /Can't locate.+$comp_class\.pm\sin\s\@INC/;
-         warn $@ if $@;
+          warn $@ if $@;
         }
         push(@to_register, [ $comp, $comp_class ]);
       }
@@ -569,8 +571,8 @@ sub txn_do {
   $self->txn_begin; # If this throws an exception, no rollback is needed
 
   my $wantarray = wantarray; # Need to save this since the context
-                            # inside the eval{} block is independent
-                            # of the context that called txn_do()
+                             # inside the eval{} block is independent
+                             # of the context that called txn_do()
   eval {
 
     # Need to differentiate between scalar/list context to allow for
@@ -599,7 +601,7 @@ sub txn_do {
       my $rollback_error = $@;
       my $exception_class = "DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION";
       $self->throw_exception($error)  # propagate nested rollback
-       if $rollback_error =~ /$exception_class/;
+        if $rollback_error =~ /$exception_class/;
 
       $self->throw_exception(
         "Transaction aborted: $error. Rollback failed: ${rollback_error}"
@@ -674,7 +676,7 @@ sub populate {
 
 =head2 throw_exception
 
-=over 4 
+=over 4
 
 =item Arguments: $message