[dancer-users] [Dancer2] broken plugins

Yanick Champoux yanick at babyl.dyndns.org
Tue Apr 21 00:02:47 BST 2015


On 2015-04-19 07:59 AM, Sawyer X wrote:
> Yanick Champoux and Russell Jenkins have both produces two different
> implementations that resolve our current problems in different ways.
> They are available online.

Mine is at
https://github.com/PerlDancer/Dancer2/compare/master...yanick:plugins-yanick

And Russell's is at
https://github.com/PerlDancer/Dancer2/compare/master...veryrusty:playground/plugins


For additional giggles, here's the commentaries what went with the
disclosure of that branch:

Look first at poc/lib/Dancer2/Plugin/Foo.pm
That's a plugin that use an inner plugin, and export one
keyword (truncate_txt). The API is subject to change, but keywords are
defined via

	sub keywords { @list_of_keywords }

and the list of keywords are expected to be method for that plugin. Note
that the plugin inherit the attributes 'app()' and 'config()'.  Whatever
thing this plugin wants to do to the app, it does in its
`BUILD`.

After, look at poc/lib/poc.pm  That's the main app file.
A plugin can be added via

	use Dancer2::Plugin::Foo ':app';

The ':app' there will cause the plugin to be auto-added to the app (via
$app->with_plugins(...)) and have the keywords exported. If that's not
desired (for example, in testing files), then just doing

	use Dancer2::Plugin::Foo;

will do a regular, boring, non-exporting 'use' of the module.


After that, you can look at lib/Dancer2/Plugin2, which does
the export dance, and lib/Dancer2/Core/App, which has been
augmented by the 'with_plugins' method.


Joy,
`/anick


More information about the dancer-users mailing list