[Bast-commits] r3959 - 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 00:54:45 GMT 2008
Author: edenc
Date: 2008-01-22 00:54:45 +0000 (Tue, 22 Jan 2008)
New Revision: 3959
Added:
DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/ResultSource/Table/Partition.pm
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/01-basic.t
Log:
setting to original result_source on inflate_result/new, fixed tests
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-21 22:58:56 UTC (rev 3958)
+++ DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/Partitioned.pm 2008-01-22 00:54:45 UTC (rev 3959)
@@ -18,27 +18,6 @@
our $VERSION = '1.000';
-=head1 SYNOPSIS
-
- package My::Schema::User;
- use base qw/DBIx::Class/;
-
- __PACKAGE__->load_components(qw/Partitioned Core/);
- __PACKAGE__->table('user');
- __PACKAGE__->partitions(qw/active_user/);
- __PACKAGE__->add_columns(qw/id foo is_expired/);
-
- sub is_active { return 'active_user' if !shift->is_expired; return }
-
- # meanwhile in a nearby piece of code...
-
- my $user_rs = $schema->resultset('User');
- $user_rs->search_partition('active_user');
- my @rows = $user_rs->all; # selects rows from active_user
- $user_rs->create({ foo => 'bar', is_active => 1 }); # inserts to active_user and user
-
-=cut
-
__PACKAGE__->mk_group_accessors( 'simple' => qw/_current_partition/ );
sub table {
@@ -56,7 +35,9 @@
sub in_partition {
my ($self) = @_;
return unless $self->_current_partition;
- my $partition = $self->result_source->partition( $self->_current_partition );
+ my $partition =
+ $self->result_source->original_source->partition(
+ $self->_current_partition );
return $partition->resultset->find( $self->ident_condition ) ? 1 : 0;
}
@@ -64,14 +45,16 @@
my ($self) = @_;
return if !$self->_current_partition or $self->in_partition;
my $partition =
- $self->result_source->partition( $self->_current_partition );
+ $self->result_source->original_source->partition(
+ $self->_current_partition );
$partition->storage->insert( $partition, { $self->get_columns } );
}
sub delete_partitioned {
my ($self) = @_;
return unless $self->in_partition;
- my $partition = $self->result_source->partition( $self->_current_partition );
+ my $partition =
+ $self->result_source->partition( $self->_current_partition );
$partition->storage->delete( $partition, $self->ident_condition );
}
@@ -79,6 +62,9 @@
my $class = shift;
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;
}
@@ -86,6 +72,9 @@
my $class = shift;
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;
}
Added: DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/ResultSource/Table/Partition.pm
===================================================================
--- DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/ResultSource/Table/Partition.pm (rev 0)
+++ DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/ResultSource/Table/Partition.pm 2008-01-22 00:54:45 UTC (rev 3959)
@@ -0,0 +1,15 @@
+package DBIx::Class::ResultSource::Table::Partition;
+
+use warnings;
+use strict;
+
+use Scalar::Util ();
+use base qw/DBIx::Class::ResultSource::Table/;
+
+__PACKAGE__->mk_group_accessors( 'simple' => qw/original_source/ );
+
+sub partition {
+ return shift->original_source->partition(@_);
+}
+
+1;
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-21 22:58:56 UTC (rev 3958)
+++ DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/ResultSource/Table/Partitioned.pm 2008-01-22 00:54:45 UTC (rev 3959)
@@ -3,6 +3,7 @@
use warnings;
use strict;
+use DBIx::Class::ResultSource::Table::Partition;
use base qw/DBIx::Class::ResultSource::Table/;
use Scalar::Util ();
@@ -30,7 +31,10 @@
my ( $self, @parts ) = @_;
$self->_partitions( {} );
foreach my $partition (@parts) {
- my $new_source = DBIx::Class::ResultSource::Table->new($self);
+ my $new_source =
+ DBIx::Class::ResultSource::Table::Partition->new($self);
+ $new_source->original_source($self);
+ Scalar::Util::weaken( $new_source->{original_source} );
my $new_source_name = join '::', map { ucfirst } split '_', $partition;
$new_source->source_name($new_source_name);
$new_source->name($partition);
Modified: DBIx-Class-Partitioned/1.000/trunk/t/01-basic.t
===================================================================
--- DBIx-Class-Partitioned/1.000/trunk/t/01-basic.t 2008-01-21 22:58:56 UTC (rev 3958)
+++ DBIx-Class-Partitioned/1.000/trunk/t/01-basic.t 2008-01-22 00:54:45 UTC (rev 3959)
@@ -24,6 +24,7 @@
is( $user->posts->first->content, 'bar' );
$data->{is_expired} = 1;
+ $user_rs = $user_rs->result_source->partition('active_user')->resultset;
isa_ok( $user = $user_rs->create($data), 'My::Schema::User' );
ok( !$schema->resultset('ActiveUser')->search( { $user->get_columns } )
->count );
@@ -48,7 +49,7 @@
->count );
ok( !$user_rs->result_source->partition('active_user')
->resultset->search( { $user->get_columns } )->count );
- ok( $user_rs->search( { $user->get_columns } )->count );
+ ok( $schema->resultset('User')->search( { $user->get_columns } )->count );
die 'rollback';
};
eval { $schema->txn_do($test) };
More information about the Bast-commits
mailing list