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
[Dancer2 0.200003] Weird behaviour with Plugin Inclusion #1216
Comments
What version of the plugins are you using? |
Should be the last ones,
|
Preliminary debugging shows that the problem is due to the order here:
Because You're basically calling a plugin that tries to use keywords for a class that did not import them yet. |
This might work if we shift the call for keywords on the calling class rather than on the app's name as class, but I'm not sure if we can reach it. |
I understood the issue, and i already fixed it in my code. |
I'm trying to see whether we can really fix it, as in you wouldn't need to change any order. :) |
The following patch in - foreach my $keyword ( keys %{$_[0]->app->name->dsl->dsl_keywords} ) {
+ my $app_dsl_cb;
+ ## no critic qw(ControlStructures::ProhibitCStyleForLoops)
+ for ( my $i = 0; my $caller = caller($i); $i++ ) {
+ $app_dsl_cb = $caller->can('dsl')
+ and last;
+ }
+
+ $app_dsl_cb
+ or croak('Could not find Dancer2 app');
+
+ foreach my $keyword ( keys %{ $app_dsl_cb->()->dsl_keywords} ) { I'll prepare a pull request for this. |
Nice! |
Thank you for raising this issue. :) |
The problem in GH #1216 is when a user loads a plugin which tries to access a DSL, while only loading "Dancer2" (and thus instating the DSL) comes after. In that case, the DSL in the app class does not exist yet, and thus fails.
Pull request created. :) |
The problem in GH #1216 is when a user loads a plugin which tries to access a DSL, while only loading "Dancer2" (and thus instating the DSL) comes after. In that case, the DSL in the app class does not exist yet, and thus fails.
Merged and will be released soon. Thanks for reporting the issue. |
Thanks for the fix |
[ BUG FIXES ] * GH #1216: Make DSL work in edge-case of plugins calling DSL before the app class loaded Dancer2. (Sawyer X) * GH #1210: Show proper module/line number in log output (Masaaki Saito) [ ENHANCEMENTS ] * GH #900: Switch from to_json to encode/encode_json (Nuno Ramos Carvalho) * GH #1196: Move serializer from JSON to JSON::MaybeXS (Nuno Ramos Carvalho) * GH #1215: Remove unused DANCER2_SHARE_DIR env variable (Jason A. Crome) [ DOCUMENTATION ] * PR #1213: Clarify params merging docs and related examples (Daniel Perrett) * Add Peter Mottram (@SysPete) to list of core developers. (Russell Jenkins) * PR #1208: Introduce appdir before it's used; simplify description of what a view is (James E Keenan) * GH #1218: By request, remove David Golden from list of core developers. Created "emeritus" section to honor the contributions of former core developers. Thanks, xdg!
Hi,
i got an app that was working on Dancer 0.166001 and is breaking with 0.200003 .
Here is a trimmed down version of the problem. Once including Dancer2::Plugin::Database , i get a
Can't locate object method "dsl" via package "DemoApp"
error message*lib/DemoApp.pm
*lib/DemoApp/Extension.pm
That code runs on Dancer2 0.166001, but not on 0.200003.
Fix is pretty simple, in my code, if i reverse in
lib/DemoApp.pm
the inclusion of Dancer2 and DemoApp::Extension, it is then working as expected:instead of
It might be worth a hint in documentation for people upgrading from a version below 0.200001 to 0.200001 and above.
The code is working properly in 0.200001 and above if in my case the DemoApp::Extension package do not include plugin Dancer2::Plugin::Database .
I can't tell if it's a bug of Dancer2 or of my code, but it's a breaking change. That's happening with other plugin as well, like Dancer2::Plugin::Email.
The text was updated successfully, but these errors were encountered: