[Dancer-users] a couple of questions re. Plugins
David Precious
davidp at preshweb.co.uk
Tue Nov 15 20:44:26 CET 2011
On Sunday 13 November 2011 22:54:17 Puneet Kishor wrote:
> 1. Does a plugin have to reside under Dancer::Plugin::MyPlugin? Or, can it
> be situated anywhere, like, for example, under app/lib?
There's no reason the plugin couldn't be e.g.
appdir/lib/Dancer/Plugin/MyPlugin.pm, if that's what you're asking.
There's no absolute need for plugins to live under the Dancer::Plugin
namespace, although it's probably a good idea - and also, the plugin_setting()
method exposed by Dancer::Plugin to allow plugins to get their config might
not work properly as I think it expects to remove Dancer::Plugin:: from the
start of the package name.
If you really want your plugin under a different namespace - try it and see :)
> 2. Is it possible to call a method in the application from within MyPlugin?
> Here is what I mean --
>
> In my app.pm, I have a method called
>
> sub opts {
> }
>
> I typically set a bunch of template options in the above sub routine, and
> use it like so
>
> get '/' => sub {
> my $opts = opts();
> template 'index', $opts;
> };
>
> I am creating plugin that automatically generates a web page like so
>
> return engine('template')->apply_layout($content);
>
> I would like to run `app::opts()`, and pass the $opts to the template from
> within the plugin. I am at a loss how to do that.
If you 'use Dancer' as well as 'use Dancer::Plugin' within your plugin, I
think you should be able to call template() from within the plugin.
Cheers
Dave P
--
David Precious ("bigpresh")
http://www.preshweb.co.uk/
"Programming is like sex. One mistake and you have to support
it for the rest of your life". (Michael Sinz)
More information about the Dancer-users
mailing list