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