[Bast-commits] r9277 - in trunk/DBIx-Class-EncodedColumn: . lib/DBIx/Class t t/lib/DigestTest t/lib/DigestTest/Schema

groditi at dev.catalyst.perl.org groditi at dev.catalyst.perl.org
Thu Apr 29 23:02:48 GMT 2010


Author: groditi
Date: 2010-04-30 00:02:48 +0100 (Fri, 30 Apr 2010)
New Revision: 9277

Added:
   trunk/DBIx-Class-EncodedColumn/t/03crosstable_leak.t
   trunk/DBIx-Class-EncodedColumn/t/lib/DigestTest/Schema/TableA.pm
   trunk/DBIx-Class-EncodedColumn/t/lib/DigestTest/Schema/TableB.pm
Modified:
   trunk/DBIx-Class-EncodedColumn/Changes
   trunk/DBIx-Class-EncodedColumn/lib/DBIx/Class/EncodedColumn.pm
   trunk/DBIx-Class-EncodedColumn/t/lib/DigestTest/Schema.pm
Log:
fix for leaking encoders accross classes

Modified: trunk/DBIx-Class-EncodedColumn/Changes
===================================================================
--- trunk/DBIx-Class-EncodedColumn/Changes	2010-04-29 15:33:40 UTC (rev 9276)
+++ trunk/DBIx-Class-EncodedColumn/Changes	2010-04-29 23:02:48 UTC (rev 9277)
@@ -1,3 +1,6 @@
+0.00007        2010-04-29
+        - Fix for inter-component leaks because of improper mk_classdata usage
+          (fixes RT #5099 by Kent Fredric) ( groditi )
 0.00006        2010-01-15
         - Fix build_requires version number for SQLA ( Arthur Axel "fREW" Schmidt )
         - Don't encode undef ( osfameron )

Modified: trunk/DBIx-Class-EncodedColumn/lib/DBIx/Class/EncodedColumn.pm
===================================================================
--- trunk/DBIx-Class-EncodedColumn/lib/DBIx/Class/EncodedColumn.pm	2010-04-29 15:33:40 UTC (rev 9276)
+++ trunk/DBIx-Class-EncodedColumn/lib/DBIx/Class/EncodedColumn.pm	2010-04-29 23:02:48 UTC (rev 9277)
@@ -7,7 +7,7 @@
 use Digest;
 use Sub::Name;
 
-__PACKAGE__->mk_classdata( _column_encoders => {} );
+__PACKAGE__->mk_classdata( '_column_encoders' );
 
 our $VERSION = '0.00006';
 
@@ -31,7 +31,7 @@
 
   defined( my $encode_sub = eval{ $class->make_encode_sub($column, $args) }) ||
     $self->throw_exception("Failed to create encoder with class '$class': $@");
-  $self->_column_encoders->{$column} = $encode_sub;
+  $self->_column_encoders({$column => $encode_sub, %{$self->_column_encoders || {}}});
 
   if ( exists $info->{encode_check_method} && $info->{encode_check_method} ){
     no strict 'refs';

Added: trunk/DBIx-Class-EncodedColumn/t/03crosstable_leak.t
===================================================================
--- trunk/DBIx-Class-EncodedColumn/t/03crosstable_leak.t	                        (rev 0)
+++ trunk/DBIx-Class-EncodedColumn/t/03crosstable_leak.t	2010-04-29 23:02:48 UTC (rev 9277)
@@ -0,0 +1,44 @@
+#! /usr/bin/perl -w
+
+use strict;
+use warnings;
+use Test::More tests => 5;
+use Digest;
+
+use File::Spec;
+use FindBin '$Bin';
+use lib File::Spec->catdir( $Bin, 'lib' );
+
+#1
+use_ok("DigestTest");
+
+# ABOUT THIS TEST;
+#
+# TableA is not encoded.
+# TableB is encoded.
+#
+# Both share a field with the same name.
+#
+# This test is to demonstrate, that one is inheriting the encoding options wrongly from the other.
+#
+
+my $schema = DigestTest->init_schema;
+my $tablea = $schema->resultset('TableA');
+my $tableb = $schema->resultset('TableB');
+
+my $objecta = $tablea->create( { conflicting_name => 'foo' } );
+my $objectb = $tableb->create( { conflicting_name => 'bar' } );
+
+is( $objecta->conflicting_name, 'foo', 'Table requested to not be encoded is not encoded' );
+unlike( $objectb->conflicting_name, qr/^(bar|foo)$/, 'Table requested to be encoded is encoded' );
+
+is( $objecta->can('check_conflict'), undef, 'Table that is requested to not be encoded has no check_conflict method' );
+ok( $objectb->can('check_conflict'), 'Table that is requested encoded has check_conflict method' );
+
+END {
+
+  # In the END section so that the test DB file gets closed before we attempt to unlink it
+  DigestTest::clear($schema);
+}
+
+1;

Added: trunk/DBIx-Class-EncodedColumn/t/lib/DigestTest/Schema/TableA.pm
===================================================================
--- trunk/DBIx-Class-EncodedColumn/t/lib/DigestTest/Schema/TableA.pm	                        (rev 0)
+++ trunk/DBIx-Class-EncodedColumn/t/lib/DigestTest/Schema/TableA.pm	2010-04-29 23:02:48 UTC (rev 9277)
@@ -0,0 +1,25 @@
+package # hide from PAUSE
+    DigestTest::Schema::TableA;
+
+use base qw/DBIx::Class/;
+
+__PACKAGE__->load_components(qw/EncodedColumn Core/);
+__PACKAGE__->table('tablea');
+__PACKAGE__->add_columns(
+  id => {
+    data_type => 'int',
+    is_nullable => 0,
+    is_auto_increment => 1
+  },
+  conflicting_name => {
+    data_type => 'char',
+    size      => 43,
+    encode_column => 0,
+    encode_class  => 'Digest',
+    encode_check_method => 'check_conflict',
+  },
+);
+
+__PACKAGE__->set_primary_key('id');
+
+1;

Added: trunk/DBIx-Class-EncodedColumn/t/lib/DigestTest/Schema/TableB.pm
===================================================================
--- trunk/DBIx-Class-EncodedColumn/t/lib/DigestTest/Schema/TableB.pm	                        (rev 0)
+++ trunk/DBIx-Class-EncodedColumn/t/lib/DigestTest/Schema/TableB.pm	2010-04-29 23:02:48 UTC (rev 9277)
@@ -0,0 +1,25 @@
+package # hide from PAUSE
+    DigestTest::Schema::TableB;
+
+use base qw/DBIx::Class/;
+
+__PACKAGE__->load_components(qw/EncodedColumn Core/);
+__PACKAGE__->table('tableb');
+__PACKAGE__->add_columns(
+  id => {
+    data_type => 'int',
+    is_nullable => 0,
+    is_auto_increment => 1
+  },
+  conflicting_name => {
+    data_type => 'char',
+    size      => 43,
+    encode_column => 1,
+    encode_class  => 'Digest',
+    encode_check_method => 'check_conflict',
+  },
+);
+
+__PACKAGE__->set_primary_key('id');
+
+1;

Modified: trunk/DBIx-Class-EncodedColumn/t/lib/DigestTest/Schema.pm
===================================================================
--- trunk/DBIx-Class-EncodedColumn/t/lib/DigestTest/Schema.pm	2010-04-29 15:33:40 UTC (rev 9276)
+++ trunk/DBIx-Class-EncodedColumn/t/lib/DigestTest/Schema.pm	2010-04-29 23:02:48 UTC (rev 9277)
@@ -3,6 +3,6 @@
 
 use base qw/DBIx::Class::Schema/;
 
-__PACKAGE__->load_classes(qw/Test/);
+__PACKAGE__->load_classes(qw/Test TableA TableB/);
 
 1;




More information about the Bast-commits mailing list