Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflict between apps when using DSL object in plugins #1630

Open
nfg opened this issue Jul 30, 2021 · 0 comments
Open

Conflict between apps when using DSL object in plugins #1630

nfg opened this issue Jul 30, 2021 · 0 comments

Comments

@nfg
Copy link
Contributor

nfg commented Jul 30, 2021

Hello!

At $WORK we have a fairly complicated Dancer2 app that's grown over the years. It's composed of three different Dancer2 apps, one handling web requests, another handling API requests, and another for a weird edge case that isn't worth getting into. On development, our psgi file looks something like

builder {
    mount '/' => App::Web->to_app;
    mount '/api' => App::API->to_app;
    mount '/other' => App::Other->to_app;
};

Cool. We have some Dancer2::Plugin cases to share code between them. It's been working pretty well so far.

For a new ticket, we're adding a new endpoint in App::API that uses a plugin, and this plugin -- which worked fine before -- spits out errors like this:

Can't call method \"var\" on an undefined value at lib/App/Plugin/StaticPage.pm line 273.\n

And the line is

$plugin->dsl->app->request->var('layout' => $page->layout);

OK. I dug into it. Eventually I figured out that for that bit of code, $plugin->app and $plugin->dsl->app referred to the different apps. I need to render a template in the API with $plugin->dsl->template. Calling that invokes the hooks for the web app, and from there everything blows up. It looks like whichever app loads the plugin first stakes its claim on the dsl() function installed by Dancer2::Plugin:

if ( $app_dsl_cb ) {
my $dsl = $app_dsl_cb->();
{
## no critic qw(TestingAndDebugging::ProhibitNoWarnings)
no strict 'refs';
no warnings 'redefine';
*{"${caller}::dsl"} = sub {$dsl};
}
}

In short: I think multiple instances of the same plugin share the same dsl object. This causes weird conflicts between the apps.

I'll see if I can put together a merge request reproducing this behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant