Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Change DBIx::Class accessor in schema loader for Moose role hook

by gryphon (Abbot)
on Sep 11, 2013 at 21:43 UTC ( #1053571=perlquestion: print w/replies, xml ) Need Help??

gryphon has asked for the wisdom of the Perl Monks concerning the following question:

Greetings all,

I have a DBIx::Class schema loader + Moose role + accessor problem/question. I've got DBIx::Class schema loader building a schema, and from this there's a generated class, specifically *::Result::User for the "user" table. In that table, there's a "passwd" column that I'd like to encrypt/decrypt magically in DBIC appropriately on read/write. In the schema loader configuration, I'm asking for a specific Moose role to get added to the *::Result::User class. Ultimately, I'd like to tell DBIC that the "passwd" column should have a "_passwd" accessor, then write a "sub passwd" in the role.

To get to this, I added a "custom_column_info" key to my schema loader configuration. If I want to add any keys to the column definitions, this works perfectly as expected. However, for some reason, any "accessor" keys are silently filtered and never end up in the generated schema classes.

Here's the schema loader code:

#!/usr/bin/env perl use strict; use warnings; use DBIx::Class::Schema::Loader 'make_schema_at'; use App::Conf; my ( $dsn, $dbname, $username, $password ) = @{ App::Conf->new->get('database') }{ qw( dsn dbname username pass +word ) }; make_schema_at( 'App::Db::Schema', { dump_directory => 'lib', naming => 'current', quiet => 0, generate_pod => 1, use_namespaces => 1, use_moose => 1, schema_base_class => 'App::Db', result_roles_map => { User => ['App::Db::Base::Result::User'], }, custom_column_info => sub { my ( $table_name, $column_name, $column_info ) = @_; if ( $table_name eq 'user' and $column_name eq 'passwd' ) +{ $column_info->{accessor} = '_passwd'; } return $column_info; }, }, [ $dsn . $dbname, $username, $password ], );

What am I doing wrong here? Thanks.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1053571]
Approved by sparkyichi
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2020-10-28 21:08 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (264 votes). Check out past polls.