Index: t/03crosstable_leak.t
===================================================================
--- t/03crosstable_leak.t (revision 0)
+++ t/03crosstable_leak.t (revision 0)
@@ -0,0 +1,46 @@
+#! /usr/bin/perl -w
+
+use strict;
+use warnings;
+use Test::More tests => 6;
+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' );
+
+ok( $objectb->check_conflict( 'bar') , 'Hash-digest validation on encoded fields still works');
+
+END {
+
+ # In the END section so that the test DB file gets closed before we attempt to unlink it
+ DigestTest::clear($schema);
+}
+
+1;
Index: t/lib/DigestTest/Schema/TableA.pm
===================================================================
--- t/lib/DigestTest/Schema/TableA.pm (revision 0)
+++ t/lib/DigestTest/Schema/TableA.pm (revision 0)
@@ -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;
Index: t/lib/DigestTest/Schema/TableB.pm
===================================================================
--- t/lib/DigestTest/Schema/TableB.pm (revision 0)
+++ t/lib/DigestTest/Schema/TableB.pm (revision 0)
@@ -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;
Index: t/lib/DigestTest/Schema.pm
===================================================================
--- t/lib/DigestTest/Schema.pm (revision 7824)
+++ t/lib/DigestTest/Schema.pm (working copy)
@@ -3,6 +3,6 @@
use base qw/DBIx::Class::Schema/;
-__PACKAGE__->load_classes(qw/Test/);
+__PACKAGE__->load_classes(qw/Test TableA TableB/);
1;
Index: lib/DBIx/Class/EncodedColumn/Crypt/Eksblowfish/Bcrypt.pm
===================================================================
--- lib/DBIx/Class/EncodedColumn/Crypt/Eksblowfish/Bcrypt.pm (revision 7824)
+++ lib/DBIx/Class/EncodedColumn/Crypt/Eksblowfish/Bcrypt.pm (working copy)
@@ -41,7 +41,7 @@
#fast fast fast
return eval qq^ sub {
my \$col_v = \$_[0]->get_column('${col}');
- \$_[0]->_column_encoders->{${col}}->(\$_[1], \$col_v) eq \$col_v;
+ \$_[0]->_column_encoders->{ \$_[0]->result_class }->{${col}}->(\$_[1], \$col_v) eq \$col_v;
} ^ || die($@);
}
Index: lib/DBIx/Class/EncodedColumn/Digest.pm
===================================================================
--- lib/DBIx/Class/EncodedColumn/Digest.pm (revision 7824)
+++ lib/DBIx/Class/EncodedColumn/Digest.pm (working copy)
@@ -68,7 +68,7 @@
return eval qq^ sub {
my \$col_v = \$_[0]->get_column('${col}');
my \$salt = substr(\$col_v, ${len});
- \$_[0]->_column_encoders->{${col}}->(\$_[1], \$salt) eq \$col_v;
+ \$_[0]->_column_encoders->{\$_[0]->result_class}->{${col}}->(\$_[1], \$salt) eq \$col_v;
} ^ || die($@);
}
Index: lib/DBIx/Class/EncodedColumn.pm
===================================================================
--- lib/DBIx/Class/EncodedColumn.pm (revision 7824)
+++ lib/DBIx/Class/EncodedColumn.pm (working copy)
@@ -14,8 +14,8 @@
sub register_column {
my $self = shift;
my ($column, $info) = @_;
+
$self->next::method(@_);
-
return unless exists $info->{encode_column} && $info->{encode_column} == 1;
$self->throw_exception("'encode_class' is a required argument.")
unless exists $info->{encode_class} && defined $info->{encode_class};
@@ -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->{ $self->result_class }->{$column} = $encode_sub;
if ( exists $info->{encode_check_method} && $info->{encode_check_method} ){
no strict 'refs';
@@ -44,7 +44,7 @@
sub set_column {
my $self = shift;
- my $encs = $self->_column_encoders;
+ my $encs = $self->_column_encoders->{ $self->result_class };
if(exists $encs->{$_[0]} && defined(my $encoder = $encs->{$_[0]})){
return $self->next::method($_[0], $encoder->($_[1]));
}
@@ -53,7 +53,7 @@
sub new {
my($self, $attr, @rest) = @_;
- my $encoders = $self->_column_encoders;
+ my $encoders = $self->_column_encoders->{ $self->result_class };
for my $col (grep { defined $encoders->{$_} } keys %$encoders ) {
next unless exists $attr->{$col} && defined $attr->{$col};
$attr->{$col} = $encoders->{$col}->( $attr->{$col} );
Index: Changes
===================================================================
--- Changes (revision 7824)
+++ Changes (working copy)
@@ -1,3 +1,4 @@
+ - Fix intra-table digest collisons ( Kent Fredric )
- Fix build_requires version number for SQLA ( fREW )
0.00005 2009-10-11