rm ->make_immutable from PerRequestSchema trait
[catagits/Catalyst-Model-DBIC-Schema.git] / lib / Catalyst / TraitFor / Model / DBIC / Schema / PerRequestSchema.pm
CommitLineData
79ac28c6 1package Catalyst::TraitFor::Model::DBIC::Schema::PerRequestSchema;
63dcfadb 2
2a9509a4 3use Moose::Role;
79ac28c6 4use namespace::autoclean;
5
2a9509a4 6requires 'per_request_schema_attributes';
79ac28c6 7
8with 'Catalyst::Component::InstancePerContext';
9
63dcfadb 10=head1 NAME
11
12Catalyst::TraitFor::Model::DBIC::Schema::PerRequestSchema - Clone the schema
13with attributes for each requests
14
15=head1 SYNOPSIS
16
17 __PACKAGE__->config({
18 traits => ['PerRequestSchema'],
19 });
20
21 method per_request_schema_attributes($c) {
22 return (restricting_object => $c->user->obj);
23 }
24
25=head1 DESCRIPTION
26
27Clones the schema for each new request with the attributes retrieved from your
28C<per_request_schema_attributes> method, which you must implement. This method
29is passed the context.
30
31=cut
32
79ac28c6 33sub build_per_context_instance {
34 my ( $self, $ctx ) = @_;
35 return $self unless blessed($ctx);
36
37 my $new = bless {%$self}, ref $self;
38
34bc1c66 39 $new->schema($new->schema->clone($self->per_request_schema_attributes($ctx)));
79ac28c6 40
41 return $new;
42}
43
63dcfadb 44=head1 SEE ALSO
45
46L<Catalyst::Model::DBIC::Schema>, L<DBIx::Class::Schema>
47
48=head1 AUTHOR
49
50See L<Catalyst::Model::DBIC::Schema/AUTHOR> and
51L<Catalyst::Model::DBIC::Schema/CONTRIBUTORS>.
52
53=head1 COPYRIGHT
54
55See L<Catalyst::Model::DBIC::Schema/COPYRIGHT>.
56
57=head1 LICENSE
58
59This program is free software, you can redistribute it and/or modify it
60under the same terms as Perl itself.
61
62=cut
63
641;