NAME

Catalyst::Model::DBIC::Schema::PerRequest - Per request clone of a DBIC model with additional parameters

VERSION

version 0.001001

SYNOPSIS

package MyApp::Model::RestrictedDB;

use Moose;
extends 'Catalyst::Model::DBIC::Schema::PerRequest';

__PACKAGE__->config(target_model => 'DB');

sub per_request_schema_attributes {
    my ($self, $c) = @_;
    return (restricting_object => $c->user->obj);
}

In your controller:

$c->model('RestrictedDB')->resultset('...');

DESCRIPTION

Allows you to get a clone of an existing Catalyst::Model::DBIC::Schema model with additional parameters passed to the DBIx::Class::Schema clone.

ATTRIBUTES

target_model

The name of the original model class.

__PACKAGE__->config(target_model => 'DB');

or

has '+target_model' => (default => 'DB');

METHODS

per_request_schema($c, $original_model)

This method is called automatically and will clone your schema with attributes coming from per_request_schema_attributes. You can override this method directly to return a schema you want, but it's probably better to override per_request_schema_attributes.

per_request_schema_attributes($c, $original_model)

Override this method in your child class and return whatever parameters you need for new schema instance.

sub per_request_schema_attributes {
    my ($self, $c, $original_model) = @_;
    return (restricting_object => $c->user->obj);
}

ACKNOWLEDGMENTS

Thanks to mst (Matt S. Trout) for the idea and mentorship during the development.

AUTHOR

Roman F. <romanf@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by Roman F..

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.