[dancer-users] Trouble with DBIC in Plugins

Matthew Mallard matt at Q-technologies.com.au
Sat May 2 03:50:23 BST 2015

Andrew, thanks for your suggestions.

It’s pushing me beyond the plugins usage the documentation covers, would you be able to elaborate on how to achieve what you are suggesting (I don’t quite get all the flows within the auth/extensible plugin).

So do I create a sub in my custom plugin along these lines:
sub new {
    my ($class, $dsl) = @_;

    # Grab a handle to the Plugin::DBIC schema
    die "No schema method in app. Did you load DBIC::Plugin::DBIC before My::Custom::Module?"
        unless $dsl->can('schema');
    my $schema = $dsl->schema;

    my $self = {
        dsl_local      => $dsl,
        schema         => $schema,
    return bless $self => $class;

Then in my routes module I call plugins in this order:
use Dancer2::Plugin::DBIC
use My::Custom::Module

How does 'new' get called and what do I use to reference the schema in my custom plugin.

Let me know if there is some other background reading I should be doing for how this work,


PS - I am using version 0.0009 of Dancer2::Plugin::DBIC which I believe is the latest.

On 28 Apr 2015, at 5:51 pm, Andrew Beverley <andy at andybev.com> wrote:

> On Mon, 2015-04-27 at 22:26 +1000, Matthew Mallard wrote:
>> I’m getting a bit confused with plugins.  I’m sure that I was able to
>> use the DBIC Plugin at one point from one of my plugins, but I can’t
>> seem to get it to  work in 0.159002 or 0.160000.  DBIC seems to be
>> okay outside of plugins.
> Firstly, there is change going on in the world of plugins, which I
> suspect will fix this, but I haven't read up on the full details myself:
> http://lists.preshweb.co.uk/pipermail/dancer-users/2015-April/004512.html
>> 3 questions:
>> * why does it complain about "Plugin calls 'dsl' instead of
>> '$dsl->dsl’" when I appear to be using '$dsl->dsl’?
> Are you using an old version of the DBIC plugin? I think that is fixed
> in the most recent version.
>> * how do I get DBIC to print the SQL it’s executing so I can double
>> check it’s what I’m expecting?
>> * am I doing something else wrong in the way I’m trying to use DBIC?
> This is a bit more tricky. With the current plugin architecture,
> "schema" is not available in the DSL when you call it from another
> plugin as you are doing. You can workaround this by capturing it during
> plugin initialisation, as long as you load the DBIC plugin before yours.
> See Plugin::Auth::Extensible::Provider::DBIC for an example:
> https://github.com/ctrlo/Dancer2-Plugin-Auth-Extensible-Provider-DBIC/blob/master/lib/Dancer2/Plugin/Auth/Extensible/Provider/DBIC.pm#L171
> Andy
> _______________________________________________
> dancer-users mailing list
> dancer-users at dancer.pm
> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users

More information about the dancer-users mailing list