[Bast-commits] r3933 - in DBIx-Class-Partitioned/1.000/trunk:
lib/DBIx/Class t
edenc at dev.catalyst.perl.org
edenc at dev.catalyst.perl.org
Sat Jan 12 19:51:38 GMT 2008
Author: edenc
Date: 2008-01-12 19:51:36 +0000 (Sat, 12 Jan 2008)
New Revision: 3933
Modified:
DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/Partitioned.pm
DBIx-Class-Partitioned/1.000/trunk/t/01-basic.t
Log:
delete/insert dance for partitions
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-12 19:27:12 UTC (rev 3932)
+++ DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/Partitioned.pm 2008-01-12 19:51:36 UTC (rev 3933)
@@ -75,14 +75,43 @@
return;
}
-sub insert {
- my $self = shift;
+sub set_partition_source {
+ my ($self) = @_;
my $method = $self->select_partition_via;
my $partition_name = $self->$method;
$self->result_source( $self->partition($partition_name) );
- return $self->next::method(@_);
}
+sub new {
+ my $self = shift->next::method(@_);
+ $self->set_partition_source;
+ return $self;
+}
+
+sub inflate_result {
+ my $self = shift->next::method(@_);
+ $self->set_partition_source;
+ return $self;
+}
+
+sub update {
+ my $self = shift;
+ my $old_partition = $self->result_source;
+ $self->set_partition_source;
+ my $new_partition = $self->result_source;
+ if ( $new_partition->source_name ne $old_partition->source_name )
+ {
+ $self->result_source($old_partition);
+ $self->delete;
+ $self->result_source($new_partition);
+ $self->insert;
+ }
+ else {
+ $self->next::method(@_);
+ }
+ return $self;
+}
+
=head1 AUTHOR
Eden Cardim, C<< <edenc at shadowcatsystems.co.uk> >>
Modified: DBIx-Class-Partitioned/1.000/trunk/t/01-basic.t
===================================================================
--- DBIx-Class-Partitioned/1.000/trunk/t/01-basic.t 2008-01-12 19:27:12 UTC (rev 3932)
+++ DBIx-Class-Partitioned/1.000/trunk/t/01-basic.t 2008-01-12 19:51:36 UTC (rev 3933)
@@ -18,10 +18,16 @@
$data->{is_expired} = 1;
isa_ok( $user_rs->create($data), 'My::Schema::User' );
row_fields_equal(
- $user_rs->search($data)->single,
+ my $user = $user_rs->search($data)->single,
$schema->resultset('InactiveUser')->search($data)->single,
[qw/id foo is_expired/]
);
+ $user->is_expired(0);
+ $user->update;
+ ok( $schema->resultset('ActiveUser')->search( { $user->get_columns } )
+ ->count );
+ ok( !$schema->resultset('InactiveUser')->search( { $user->get_columns } )
+ ->count );
die 'rollback';
};
eval { $schema->txn_do($test) };
More information about the Bast-commits
mailing list