Cataly...aProxy(3pm)
β¨ NAME β¨
Catalyst::TraitFor::Model::DBIC::Schema::SchemaProxy β Proxy Schema Methods and Options from Model. Also known as Cataly...aProxy(3pm), from the User Contributed Perl Documentation. π
π DESCRIPTION π
Okay so bestie, this trait lets you call your DBIx::Class::Schema methods directly on the Model instance, and it passes config options to your DBIx::Class::Schema and DBIx::Class::ResultSet attributes at "BUILD" time. β¨
Methods and attributes local to your "Model" take precedence over DBIx::Class::Schema or DBIx::Class::ResultSet methods and attributes. No cap. π«Ά
π CREATING SCHEMA CONFIG ATTRIBUTES π
To create attributes in your Schema.pm, use either Moose or Class::Accessor::Grouped, which is inherited from by all DBIx::Class classes automatically. E.g.:
__PACKAGE__->mk_group_accessors(simple => qw/
config_key1
config_key2
...
/);
Or with Moose:
use Moose;
has config_key1 => (is => 'rw', default => 'default_value');
This code can be added after the md5sum on DBIx::Class::Schema::Loader generated schemas.
At app startup, any non-local options will be passed to these accessors, and can be accessed as usual via $schema->config_key1.
These config values go into your Model::DB block, along with normal config values. πΈ
π¦ CREATING RESULTSET CONFIG ATTRIBUTES π¦
You can create classdata on DBIx::Class::ResultSet classes to hold values from Catalyst config.
The code for this looks something like this:
package MySchema::ResultSet::Foo;
use base 'DBIx::Class::ResultSet';
__PACKAGE__->mk_group_accessors(inherited => qw/
rs_config_key1
rs_config_key2
...
/);
__PACKAGE__->rs_config_key1('default_value');
Or, if you prefer Moose:
package MySchema::ResultSet::Foo;
use Moose;
use MooseX::NonMoose;
use MooseX::ClassAttribute;
extends 'DBIx::Class::ResultSet';
sub BUILDARGS { $_[2] } # important
class_has rs_config_key1 => (is => 'rw', default => 'default_value');
...
__PACKAGE__->meta->make_immutable;
1;
In your catalyst config, use the generated Model name as the config key, e.g.:
<Model::DB::Users>
strict_passwords 1
</Model::DB::Users>
πΈ SEE ALSO πΈ
Catalyst::Model::DBIC::SchemaDBIx::Class::Schema
π AUTHOR π
See "AUTHOR" in Catalyst::Model::DBIC::Schema and "CONTRIBUTORS" in Catalyst::Model::DBIC::Schema.
π COPYRIGHT π
See "COPYRIGHT" in Catalyst::Model::DBIC::Schema.
π LICENSE π
This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
Sending you good vibes from perl v5.36.0, dated 2023-10-26, and this lil page is Cataly...aProxy(3pm). Stay slaying! π
β¨
π¦ where this page comes from
- debian trixie: libcatalyst-model-dbic-schema-perl 0.66-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libcatalyst-model-dbic-schema-perl 0.66-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libcatalyst-model-dbic-schema-perl 0.66-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcatalyst-model-dbic-schema-perl 0.66-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms