[Bast-commits] r3963 -
DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/ResultSource/Table
matthewt at dev.catalyst.perl.org
matthewt at dev.catalyst.perl.org
Tue Jan 22 04:06:46 GMT 2008
Author: matthewt
Date: 2008-01-22 04:06:46 +0000 (Tue, 22 Jan 2008)
New Revision: 3963
Modified:
DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/ResultSource/Table/Partitioned.pm
Log:
on-demand creation of partition sources
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 04:01:42 UTC (rev 3962)
+++ DBIx-Class-Partitioned/1.000/trunk/lib/DBIx/Class/ResultSource/Table/Partitioned.pm 2008-01-22 04:06:46 UTC (rev 3963)
@@ -11,24 +11,26 @@
sub schema {
my $self = shift;
- my ($schema) = @_;
- # ugh...
- if ( Scalar::Util::blessed($schema) ) {
- my %new_part;
- foreach my $partition ( keys %{ $self->_partitions } ) {
- my $old_source = $self->_partitions->{$partition};
- my $new_source = $old_source->new($old_source);
+ 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,
+ });
+ $new_source->relationship_info($_)->{attrs}{cascade_delete} = 0
+ for $new_source->relationships;
my $new_source_name = $self->source_name.'->partition('.$partition.')';
- $new_source->result_class('');
$schema->register_source(
$new_source_name => $new_source );
- $new_source = $schema->source($new_source->source_name);
- $new_source->original_source_name($self->source_name);
- $new_source->result_class($old_source->result_class);
- $new_part{$partition} = $new_source;
+ $schema->source($new_source->source_name)
+ ->result_class($self->result_class);
}
- $self->_partitions(\%new_part);
}
return $self->next::method(@_);
@@ -36,30 +38,13 @@
sub partitions {
my ( $self, @parts ) = @_;
- $self->_partitions( {} );
- foreach my $partition (@parts) {
- my $new_source =
- DBIx::Class::ResultSource::Table::Partition->new($self);
- $new_source->original_source_name($self->source_name);
- $new_source->name($partition);
- $new_source->_relationships(
- Storable::dclone( $new_source->_relationships ) );
- $new_source->relationship_info($_)->{attrs}{cascade_delete} = 0
- for $new_source->relationships;
- $self->_partitions->{$partition} = $new_source;
- }
+ $self->_partitions( \@parts );
}
sub partition {
- my $self = shift;
- if (@_) {
- my ($moniker) = @_;
- my $partitions = $self->_partitions;
- return unless exists $partitions->{$moniker};
- my $partition_source = $partitions->{$moniker};
- return $partition_source;
- }
- return;
+ my ($self, $partition) = @_;
+ my $schema = $self->schema || die "No schema";
+ return $schema->source($self->source_name.'->partition('.$partition.')');
}
sub original_source { return shift }
More information about the Bast-commits
mailing list