From: Tomas Doran Date: Tue, 30 Aug 2011 11:23:26 +0000 (+0100) Subject: Initial trait for doing per request schema X-Git-Tag: v0.56~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=79ac28c61569bbed2746065cc7c933f1d20a11a4;p=catagits%2FCatalyst-Model-DBIC-Schema.git Initial trait for doing per request schema --- diff --git a/lib/Catalyst/TraitFor/Model/DBIC/Schema/PerRequestSchema.pm b/lib/Catalyst/TraitFor/Model/DBIC/Schema/PerRequestSchema.pm new file mode 100644 index 0000000..dcbd61f --- /dev/null +++ b/lib/Catalyst/TraitFor/Model/DBIC/Schema/PerRequestSchema.pm @@ -0,0 +1,26 @@ +package Catalyst::TraitFor::Model::DBIC::Schema::PerRequestSchema; +use Moose; +use namespace::autoclean; + +sub BUILD {} +after BUILD => sub { + my ($self) = @_; + confess("You have not implemented a per_request_schema_attributes method in " . ref($self)) + unless $self->can('per_request_schema_attributes'); +}; + +with 'Catalyst::Component::InstancePerContext'; + +sub build_per_context_instance { + my ( $self, $ctx ) = @_; + return $self unless blessed($ctx); + + my $new = bless {%$self}, ref $self; + + $new->schema( $new->schema->clone($self->per_request_schema_attributes($ctx)) ); + + return $new; +} + +__PACKAGE__->meta->make_immutable; +