[Bast-commits] r6203 - in DBIx-Class/0.08/trunk: lib/DBIx/Class/Relationship t

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Sun May 10 19:35:03 GMT 2009


Author: ribasushi
Date: 2009-05-10 19:35:03 +0000 (Sun, 10 May 2009)
New Revision: 6203

Modified:
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/ManyToMany.pm
   DBIx-Class/0.08/trunk/t/103many_to_many_warning.t
Log:
Switch the m2m method warnings from warnings::register to $ENV{DBIC_METHOD_CLOBBER_OK} = 1

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/ManyToMany.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/ManyToMany.pm	2009-05-10 18:17:09 UTC (rev 6202)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Relationship/ManyToMany.pm	2009-05-10 19:35:03 UTC (rev 6203)
@@ -3,7 +3,8 @@
 
 use strict;
 use warnings;
-use warnings::register;
+
+use Carp::Clan qw/^DBIx::Class/;
 use Sub::Name ();
 
 sub many_to_many {
@@ -28,16 +29,20 @@
 
     for ($add_meth, $remove_meth, $set_meth, $rs_meth) {
       if ( $class->can ($_) ) {
-        warnings::warnif(<<"EOW")
+        carp (<<"EOW") unless $ENV{DBIC_METHOD_CLOBBER_OK};
+
 ***************************************************************************
-The many-to-many relationship $meth is trying to create a utility method called
-$_. This will overwrite the existing method on $class. You almost certainly
-want to rename your method or the many-to-many relationship, as your method
-will not be callable (it will use the one from the relationship instead.)
+The many-to-many relationship '$meth' is trying to create a utility method
+called $_.
+This will completely overwrite one such already existing method on class
+$class.
 
-To disable this warning add the following to $class
+You almost certainly want to rename your method or the many-to-many
+relationship, as the functionality of the original method will not be
+accessible anymore.
 
-  no warnings 'DBIx::Class::Relationship::ManyToMany';
+To disable this warning set the environment variable DBIC_METHOD_CLOBBER_OK
+to a true value
 
 ***************************************************************************
 EOW

Modified: DBIx-Class/0.08/trunk/t/103many_to_many_warning.t
===================================================================
--- DBIx-Class/0.08/trunk/t/103many_to_many_warning.t	2009-05-10 18:17:09 UTC (rev 6202)
+++ DBIx-Class/0.08/trunk/t/103many_to_many_warning.t	2009-05-10 19:35:03 UTC (rev 6203)
@@ -5,42 +5,38 @@
 use lib qw(t/lib);
 use Data::Dumper;
 
-plan ( ($] >= 5.009000 and $] < 5.010001)
-  ? (skip_all => 'warnings::register broken under 5.10: http://rt.perl.org/rt3/Public/Bug/Display.html?id=62522')
-  : (tests => 4)
-);
+plan tests => 4;
+my $exp_warn = qr/The many-to-many relationship 'bars' is trying to create/;
 
 {
   my @w; 
-  local $SIG{__WARN__} = sub { push @w, @_ };
+  local $SIG{__WARN__} = sub { $_[0] =~ $exp_warn ? push @w, $_[0] : warn $_[0] };
   my $code = gen_code ( suffix => 1 );
   eval "$code";
   ok (! $@, 'Eval code without warnings suppression')
     || diag $@;
 
-  ok ( (grep { $_ =~ /The many-to-many relationship bars is trying to create/ } @w), "Warning triggered without relevant 'no warnings'");
+  ok (@w, "Warning triggered without DBIC_METHOD_CLOBBER_OK");
 }
 
 {
   my @w; 
-  local $SIG{__WARN__} = sub { push @w, @_ };
+  local $SIG{__WARN__} = sub { $_[0] =~ $exp_warn ? push @w, $_[0] : warn $_[0] };
 
-  my $code = gen_code ( suffix => 2, no_warn => 1 );
+  my $code = gen_code ( suffix => 2 );
+
+  local $ENV{DBIC_METHOD_CLOBBER_OK} = 1;
   eval "$code";
   ok (! $@, 'Eval code with warnings suppression')
     || diag $@;
 
-  ok ( (not grep { $_ =~ /The many-to-many relationship bars is trying to create/ } @w), "No warning triggered with relevant 'no warnings'");
+  ok (! @w, "No warning triggered with DBIC_METHOD_CLOBBER_OK");
 }
 
 sub gen_code {
 
   my $args = { @_ };
   my $suffix = $args->{suffix};
-  my $no_warn = ( $args->{no_warn}
-    ? "no warnings 'DBIx::Class::Relationship::ManyToMany';"
-    : '',
-  );
 
   return <<EOF;
 use strict;
@@ -95,7 +91,6 @@
     },
   );
 
-  ${no_warn}
   __PACKAGE__->set_primary_key('barid');
   __PACKAGE__->has_many('foo_to_bar' => 'DBICTest::Schema::FooToBar${suffix}' => 'foo');
 




More information about the Bast-commits mailing list