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

Hello Monks

I only ever ask stupid questions so apologies in advance for this!

So the problem is this: I have a process which adds some tables to a database. The user is able to specify a prefix which will be applied to all table names in the set (so in a sense these have dynamic names). Then via a second process I allow the user to create a schema using DBIx::Class::Schema::Loader, using custom options.

Next I want to use that schema. The question is, how can I figure out what moniker DBIx::Class::Schema::Loader used to create the schema file for a given table? I mean I know the original table name and options that were passed to make_schema_at, and I'm looking for something like

my $moniker = DBIx::Class::Schema::Loader->moniker_of_table( $table_name, \%orig_load_options );

(Obviously it's probably not going to be quite as convenient as this, but you get the idea!)

I did notice a _table2moniker method while looking over the DBIx::Class::Schema::Loader::Base code - but I can't seem to find anything intended for public use. (The moniker creation code looks pretty complex...)

Can someone point me in the right direction...?

Replies are listed 'Best First'.
Re: how can I figure out what moniker DBIx::Class::Schema::Loader used for a given table?
by Your Mother (Archbishop) on Dec 29, 2017 at 04:12 UTC

    It's not a stupid question. DBIC is a weird and deep, but awesome!, space. This one is easy if I understand. This kind of introspection, with $schema->sources, will give you the answer–

    my $schema = DBIx::Class::Schema::Loader::make_schema_at(UR_STUFS); for my $moniker ( $schema->sources ) { my $source = $schema->source($moniker); printf "%30s -> %s\n", $source->name, $moniker; }

      Yes I realised this morning I was fixating on the DBIx::Class::Schema::Loader class and forgetting I could inspect the Schema itself! This works perfectly - many thanks for your help!

Re: how can I figure out what moniker DBIx::Class::Schema::Loader used for a given table?
by 1nickt (Canon) on Dec 29, 2017 at 01:10 UTC

    Hi, the documentation for DBIx::Class::Schema::Loader::Base shows how to control naming for monikers and other elements of your schemas by specifying a version number. If you are not specifiying a version, you are using the default, so consulting the documentation there will show you how the monikers are constructed.

    Hope this helps!


    The way forward always starts with a minimal test.

      Thanks for your comment - but I did already look at the docs you mentioned and actually it doesn't help too much. You said "If you are not specifying a version..." - however the user has the option to specify the version. So if I were to try to emulate the module's naming system then I'd need to do it for all versions. Obviously that doesn't make sense. It seems odd to me that the same process that creates the monikers during make_schema_at cannot be queried independently of the make process. (This is what I am trying to find a way to do). Thanks for trying to help though...

        I guess I can't conceive of any case in which I'd want to give my users that much control over the inner workings of my app. Is it really necessary? If you need to provide access to other options, can you create a wrapper that supports only the ones you want to enable?


        The way forward always starts with a minimal test.