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

Hi monks,

So, after some tinkering I realsied that it actaully wasn't too hard to get my sessions into a postgresql database using Dancer2:Session:DBIC. I'm having an issue with my config.yml though, this is what I've got in my file at present:

appname: "xxxx" layout: "main" charset: "UTF-8" template: "template_toolkit" engines: template: template_toolkit: start_tag: '<%' end_tag: '%>' session: "DBIC" engines: session: DBIC: dsn: "dbi:Pg:database=xxxx" schema_class: "xxxx::Schema" user: "" password: "" # resultset: "Session" id_column: "id" data_column: "data"
This breaks template toolkit and I just get <% content %> where the HTML should be. If I replace the template toolkit block above with template: "template_toolkit" (uses the default tags [% %]) it works fine.

If I leave the template toolkit block as it is above and remove the session config block completely template toolkit works properly (with <% %> tags). I've tried swapping the config blocks around so that TT is after session, that gives me an Unable to create a new session: No schema class defined error. I've also tried playing around with the yaml formatting/spacing but I can't get them to play nicely. Can anyone spot what I'm doing wrong?

Replies are listed 'Best First'.
Re: Dancer 2 yaml config file (is a hash of hashes ... key collision/clobbering is a common pitfall)
by Anonymous Monk on Feb 09, 2015 at 00:42 UTC

    Can anyone spot what I'm doing wrong?

    looks like you're using yaml instead of code, and its tricking your mind, see https://metacpan.org/pod/distribution/Dancer2/lib/Dancer2/Config.pod#MANIPULATING-SETTINGS-VIA-CODE

    Config is a hash, a hash of hashes, meaning there is only one %engines, there can be only one engines

    { 'engines' => { 'template' => { 'template_toolkit' => { 'start_tag' => '<%', 'end_tag' => '%>', }, }, 'session' => { 'DBIC' => { 'user' => '', 'pass' => '', ... }, }, }, 'template' => 'template_toolkit', 'session' => 'DBIC', ... }

    IMHO, this is one of those pitfalls that shouldn't exist :) Dancer provides so many conveniences, why not a reminder that key are colliding/being clobbered

      Ah, ok yes that makes sense, got it working (at last) with:
      engines: session: DBIC: dsn: "dbi:Pg:database=dbname" schema_class: "xxxx::Schema" user: "" password: "" #resultset: id_column: "id" data_column: "data" template: template_toolkit: start_tag: '<%' end_tag: '%>' session: "DBIC" template: "template_toolkit"
      Thank you.
Re: Dancer 2 yaml config file
by etherald (Novice) on Feb 08, 2015 at 23:46 UTC
    possibly you need to entitize those <>s?
    composure/composure