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.


In reply to Change DBIx::Class accessor in schema loader for Moose role hook by gryphon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.