The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

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

VERSION

version 0.002002

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.

or

has '+target_model' => (
    default      => 'DB',
    schema_class => 'MyApp::Schema',
);

schema_class

The name of your DBIx::Class schema.

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.