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
problem importing from sub-modules #487
Comments
The sub test doesn't return a Dancer App. In your example just remove the package Dancer2Sub;
use parent 'Exporter';
our @EXPORT_OK = qw( test );
sub test { 'test'; }
1; and in dancer2_test.pl do something like: use Dancer2;
use Dancer2Sub qw( test );
get '/' => sub { test() };
dance; |
Hello João, On Sat, 02 Nov 2013, João Bolila wrote:
|
The problem is that calling "use Dancer2" plays with your import. That's on purpose. I think you could fix this with a role behavior, or using callbacks. Dancer1 has |
Hello Sawyer, On Sun, 08 Dec 2013, Sawyer X wrote:
package ABC; don't need to call Dancer2 ':syntax';my $p = params->{foo}; 1;
|
Well, my 2 cents (so we can maybe wrap this up)
|
I would recommend to write your own plugin for utility functions. This gives you access to Dancer2 DSL and you "export" your functions with register. No need to mimic that with Exporter. |
Dancer2 applications are web applications, and should not be used to store utility functions for other Dancer2 applications. This is simply not something that should work to begin with. I hope the suggestions we offered were helpful. |
Hello Dancers,
First I'd like to thank the Dancer devel team - great concept, fun to work with.
I started porting a project from Dancer to Dancer2 and ran into this problem:
It happens when I import things from a sub-module that also 'use's Dancer2. Here is some test code. First, the script dancer2_test.pl:
!/usr/bin/perl
use Dancer2Sub qw( test );
use Dancer2;
print test(), "\n";
And the sub-module, Dancer2Sub.pm:
package Dancer2Sub;
use parent 'Exporter';
our @EXPORT_OK = qw( test );
use Dancer2;
sub test { 'test'; }
1;
Putting EXPORT_OK inside a BEGIN block doesn't help.
The problem seems to be that _set_import_method_to_caller in Dancer2.pm overwrites Dancer2Sub's normal import method. This makes it difficult to (e.g.) make a function-oriented Utils sub-module that uses Dancer[2]
syntax (params, session, etc).
My environment is
This is perl 5, version 12, subversion 4 (v5.12.4) built for x86_64-linux-thread-multi
running on Fedora release 15 (Lovelock):
Linux tove 2.6.43.8-1.fc15.x86_64 #1 SMP Mon Jun 4 20:33:44 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
and running Dancer2 v0.010 (which, wrt _set_import_method_to_caller, seems to be the same as the latest on GitHub).
Regards,
reid
The text was updated successfully, but these errors were encountered: