1use strict; 2use warnings; 3use Test::More; 4 5use lib qw(t/lib); 6 7plan tests => 4; 8my $exp_warn = qr/The many-to-many relationship 'bars' is trying to create/; 9 10{ 11 my @w; 12 local $SIG{__WARN__} = sub { $_[0] =~ $exp_warn ? push @w, $_[0] : warn $_[0] }; 13 my $code = gen_code ( suffix => 1 ); 14 eval "$code"; 15 ok (! $@, 'Eval code without warnings suppression') 16 || diag $@; 17 18 ok (@w, "Warning triggered without DBIC_OVERWRITE_HELPER_METHODS_OK"); 19} 20 21{ 22 my @w; 23 local $SIG{__WARN__} = sub { $_[0] =~ $exp_warn ? push @w, $_[0] : warn $_[0] }; 24 25 my $code = gen_code ( suffix => 2 ); 26 27 local $ENV{DBIC_OVERWRITE_HELPER_METHODS_OK} = 1; 28 eval "$code"; 29 ok (! $@, 'Eval code with warnings suppression') 30 || diag $@; 31 32 ok (! @w, "No warning triggered with DBIC_OVERWRITE_HELPER_METHODS_OK"); 33} 34 35sub gen_code { 36 37 my $args = { @_ }; 38 my $suffix = $args->{suffix}; 39 40 return <<EOF; 41use strict; 42use warnings; 43 44{ 45 package # 46 DBICTest::Schema::Foo${suffix}; 47 use base 'DBIx::Class::Core'; 48 49 __PACKAGE__->table('foo'); 50 __PACKAGE__->add_columns( 51 'fooid' => { 52 data_type => 'integer', 53 is_auto_increment => 1, 54 }, 55 ); 56 __PACKAGE__->set_primary_key('fooid'); 57 58 59 __PACKAGE__->has_many('foo_to_bar' => 'DBICTest::Schema::FooToBar${suffix}' => 'bar'); 60 __PACKAGE__->many_to_many( foos => foo_to_bar => 'bar' ); 61} 62{ 63 package # 64 DBICTest::Schema::FooToBar${suffix}; 65 66 use base 'DBIx::Class::Core'; 67 __PACKAGE__->table('foo_to_bar'); 68 __PACKAGE__->add_columns( 69 'foo' => { 70 data_type => 'integer', 71 }, 72 'bar' => { 73 data_type => 'integer', 74 }, 75 ); 76 __PACKAGE__->belongs_to('foo' => 'DBICTest::Schema::Foo${suffix}'); 77 __PACKAGE__->belongs_to('bar' => 'DBICTest::Schema::Foo${suffix}'); 78} 79{ 80 package # 81 DBICTest::Schema::Bar${suffix}; 82 83 use base 'DBIx::Class::Core'; 84 85 __PACKAGE__->table('bar'); 86 __PACKAGE__->add_columns( 87 'barid' => { 88 data_type => 'integer', 89 is_auto_increment => 1, 90 }, 91 ); 92 93 __PACKAGE__->set_primary_key('barid'); 94 __PACKAGE__->has_many('foo_to_bar' => 'DBICTest::Schema::FooToBar${suffix}' => 'foo'); 95 96 __PACKAGE__->many_to_many( bars => foo_to_bar => 'foo' ); 97 98 sub add_to_bars {} 99} 100EOF 101 102} 103