From: Peter Rabbitson Date: Tue, 14 Feb 2012 22:05:04 +0000 (+0100) Subject: Fix more $schema leaks in the SQLT DBIC Parser (AUGHHHHH!!!!) X-Git-Tag: v0.08197~97 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=48775dd11096e6a57bde9532f47412c90d87975c;p=dbsrgits%2FDBIx-Class.git Fix more $schema leaks in the SQLT DBIC Parser (AUGHHHHH!!!!) --- diff --git a/Changes b/Changes index fba35ab..d983c85 100644 --- a/Changes +++ b/Changes @@ -21,6 +21,7 @@ Revision history for DBIx::Class - Fix corner case of forked children disconnecting the parents DBI handle - Fix leakage of $schema on in-memory new_related() calls + - Fix more cases of $schema leakage in SQLT::Parser::DBIC - Remove useless vestigial pessimization in Ordered.pm for cases when the position column is part of a unique constraint diff --git a/lib/SQL/Translator/Parser/DBIx/Class.pm b/lib/SQL/Translator/Parser/DBIx/Class.pm index 5a7f7c9..755ac4a 100644 --- a/lib/SQL/Translator/Parser/DBIx/Class.pm +++ b/lib/SQL/Translator/Parser/DBIx/Class.pm @@ -34,16 +34,17 @@ use base qw(Exporter); # We're working with DBIx::Class Schemas, not data streams. # ------------------------------------------------------------------- sub parse { - # this is a hack to prevent schema leaks due to a retarded SQLT implementation - # DO NOT REMOVE (until SQLT2 is out, the all of this will be rewritten anyway) - weaken $_[1] if ref ($_[1]); - my ($tr, $data) = @_; my $args = $tr->parser_args; my $dbicschema = $args->{'DBIx::Class::Schema'} || $args->{"DBIx::Schema"} ||$data; $dbicschema ||= $args->{'package'}; my $limit_sources = $args->{'sources'}; + # this is a hack to prevent schema leaks due to a retarded SQLT implementation + # DO NOT REMOVE (until SQLT2 is out, the all of this will be rewritten anyway) + ref $_ and weaken $_ + for $_[1], $dbicschema, @{$args}{qw/DBIx::Schema DBIx::Class::Schema package/}; + DBIx::Class::Exception->throw('No DBIx::Class::Schema') unless ($dbicschema); if (!ref $dbicschema) { eval "require $dbicschema" diff --git a/t/99dbic_sqlt_parser.t b/t/99dbic_sqlt_parser.t index a9fba8f..b98e7f2 100644 --- a/t/99dbic_sqlt_parser.t +++ b/t/99dbic_sqlt_parser.t @@ -18,12 +18,20 @@ BEGIN { # Test for SQLT-related leaks { my $s = DBICTest::Schema->clone; - my $sqlt_schema = create_schema ({ schema => $s }); + + my @schemas = ( + create_schema ({ schema => $s }), + create_schema ({ args => { parser_args => { 'DBIx::Class::Schema' => $s } } }), + create_schema ({ args => { parser_args => { 'DBIx::Schema' => $s } } }), + create_schema ({ args => { parser_args => { package => $s } } }), + ); + Scalar::Util::weaken ($s); ok (!$s, 'Schema not leaked'); - isa_ok ($sqlt_schema, 'SQL::Translator::Schema', 'SQLT schema object produced'); + isa_ok ($_, 'SQL::Translator::Schema', "SQLT schema object $_ produced") + for @schemas; } # make sure classname-style works