[dancer-users] Any way to import plugins into extension apps?

Steve Dondley sdondley at gmail.com
Fri Dec 15 16:10:49 GMT 2017


Here's the few lines from a hypothetical MainApp in /lib:

# File 1
package MainApp;
use ExtendingApp;
use HTML::Element;

And here is a perl module that extends this app.

# File 2
package ExtendingApp;
use Dancer2 appname => MainApp;

get '/' => sub {
   my $element = HTML::Element->new('h1');
};

### END ###

This works. I get no errors because the HTML::Element module can be seen
inside routes. However, unless I'm missing something, this doesn't work.

# File 1
package MainApp;
use ExtendingApp;
use Dancer2::Plugin::Database;

# File 2
package ExtendingApp;
use Dancer2 appname => MainApp;

get '/' => sub {
   my @data = database->quick_select('test_table', {});
};

### END ###

The above results in an error: Can't locate object method "quick_select"
via package "database" (perhaps you forgot to load "database"?)

I'm forced to add "use Dancer2::Plugin::Database" to File 2. I'm curious to
know if there's some way to import commonly used plugins into extension
apps.

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20171215/c94e5578/attachment.html>


More information about the dancer-users mailing list