[Bast-commits] r3966 - in DBIx-Class-Partitioned/1.000/trunk:
lib/DBIx/Class lib/DBIx/Class/ResultSource/Table t
edenc at dev.catalyst.perl.org
edenc at dev.catalyst.perl.org
Tue Jan 22 19:31:36 GMT 2008
Author: edenc
Date: 2008-01-22 19:31:36 +0000 (Tue, 22 Jan 2008)
New Revision: 3966
Modified:
DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/Partitioned.pm
DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/ResultSource/Table/Partitioned.pm
DBIx-Class-Partitioned/1.000/trunk/t/02-restrict_schema.t
Log:
disabling restrictions temporarily so original source is obtainable
Modified: DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/Partitioned.pm
===================================================================
--- DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/Partitioned.pm 2008-01-22 15:13:11 UTC (rev 3965)
+++ DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/Partitioned.pm 2008-01-22 19:31:36 UTC (rev 3966)
@@ -36,21 +36,16 @@
my ($self) = @_;
return unless $self->_current_partition;
my $partition =
- $self->result_source->partition(
- $self->_current_partition );
+ $self->result_source->partition( $self->_current_partition );
return $partition->resultset->find( $self->ident_condition ) ? 1 : 0;
}
sub insert_partitioned {
my ($self) = @_;
return if !$self->_current_partition or $self->in_partition;
- $self->result_source(
- $self->result_source
- ->original_source
- );
+ $self->result_source( $self->result_source->original_source );
my $partition =
- $self->result_source->partition(
- $self->_current_partition );
+ $self->result_source->partition( $self->_current_partition );
$partition->storage->insert( $partition, { $self->get_columns } );
}
@@ -75,7 +70,7 @@
my $class = shift;
my $self = $class->next::method(@_);
$self->_current_partition( $self->_partition_name || '' );
- if (my $source = $self->result_source) {
+ if ( my $source = $self->result_source ) {
my $original = $source->original_source;
$self->result_source($original);
}
@@ -87,13 +82,13 @@
my $self = $class->next::method(@_);
$self->_current_partition( $self->_partition_name || '' );
my $original = $self->result_source->original_source;
-# $original->schema( $self->result_source->schema );
$self->result_source($original);
return $self;
}
sub insert {
my $self = shift;
+ local $self->result_source->schema->{restricting_object};
$self->_current_partition( $self->_partition_name || '' );
$self->insert_partitioned;
return $self->next::method(@_);
@@ -101,6 +96,8 @@
sub update {
my $self = shift;
+
+ local $self->result_source->schema->{restricting_object};
my %to_update = $self->get_dirty_columns;
$self->next::method(@_);
my $old_part = $self->_current_partition;
@@ -113,7 +110,7 @@
}
else {
if ( $self->in_partition ) {
- $self->update_partitioned(\%to_update);
+ $self->update_partitioned( \%to_update );
}
else {
$self->insert_partitioned;
@@ -133,6 +130,7 @@
sub delete {
my $self = shift;
+ local $self->result_source->schema->{restricting_object};
if ( my $part = $self->_current_partition ) {
$self->delete_partitioned;
$self->_current_partition('');
Modified: DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/ResultSource/Table/Partitioned.pm
===================================================================
--- DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/ResultSource/Table/Partitioned.pm 2008-01-22 15:13:11 UTC (rev 3965)
+++ DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/ResultSource/Table/Partitioned.pm 2008-01-22 19:31:36 UTC (rev 3966)
@@ -12,24 +12,26 @@
sub schema {
my $self = shift;
- if ( @_ && !$self->schema ) { # only fire if we're getting schema set for first time
+ if ( @_ && !$self->schema )
+ { # only fire if we're getting schema set for first time
my ($schema) = @_;
- foreach my $partition ( @{$self->_partitions} ) {
- my $new_source =
- DBIx::Class::ResultSource::Table::Partition->new({
- %$self,
- name => $partition,
- _relationships => Storable::dclone( $self->_relationships ),
- result_class => '',
- original_source_name => $self->source_name,
- });
+ foreach my $partition ( @{ $self->_partitions } ) {
+ my $new_source = DBIx::Class::ResultSource::Table::Partition->new(
+ {
+ %$self,
+ name => $partition,
+ _relationships => Storable::dclone( $self->_relationships ),
+ result_class => '',
+ original_source_name => $self->source_name,
+ }
+ );
$new_source->relationship_info($_)->{attrs}{cascade_delete} = 0
for $new_source->relationships;
- my $new_source_name = $self->source_name.'->partition('.$partition.')';
- $schema->register_source(
- $new_source_name => $new_source );
- $schema->source($new_source->source_name)
- ->result_class($self->result_class);
+ my $new_source_name =
+ $self->source_name . '->partition(' . $partition . ')';
+ $schema->register_source( $new_source_name => $new_source );
+ $schema->source( $new_source->source_name )
+ ->result_class( $self->result_class );
}
}
@@ -42,9 +44,11 @@
}
sub partition {
- my ($self, $partition) = @_;
+ my ( $self, $partition ) = @_;
my $schema = $self->schema || die "No schema";
- return $schema->source($self->source_name.'->partition('.$partition.')');
+ $partition =
+ $schema->source( $self->source_name . '->partition(' . $partition . ')' );
+ return $partition;
}
sub original_source { return shift }
Modified: DBIx-Class-Partitioned/1.000/trunk/t/02-restrict_schema.t
===================================================================
--- DBIx-Class-Partitioned/1.000/trunk/t/02-restrict_schema.t 2008-01-22 15:13:11 UTC (rev 3965)
+++ DBIx-Class-Partitioned/1.000/trunk/t/02-restrict_schema.t 2008-01-22 19:31:36 UTC (rev 3966)
@@ -13,6 +13,27 @@
);
is( $restricted->source('User')->from, 'active_user' );
is( $restricted->source('Affiliation')->from, 'affiliation' );
+my $test = sub {
+ isa_ok(
+ my $row =
+ $restricted->resultset('User')
+ ->create( { foo => 'bar', is_expired => 0 } ),
+ 'My::Schema::User'
+ );
+ ok( $restricted->resultset('ActiveUser')->search( { $row->get_columns } ) );
+ $row->foo('foo');
+ $row->update;
+ ok( $restricted->resultset('ActiveUser')->search( { $row->get_columns } ) );
+ isa_ok( $restricted->source('User'),
+ 'DBIx::Class::ResultSource::Table::Partition' );
+ my $user_rs = $restricted->resultset('User');
+ isa_ok( $user_rs->result_source,
+ 'DBIx::Class::ResultSource::Table::Partition' );
+ ok( $schema->resultset('User')->search( { $row->get_columns } ) );
+ die 'rollback';
+};
+eval { $schema->txn_do($test) };
+die $@ if $@ !~ 'rollback';
package Test::RestrictingObject;
More information about the Bast-commits
mailing list