[dancer-users] Usage Of Plugins Out Of CPAN
Andrew Beverley
andy at andybev.com
Tue May 26 14:54:58 BST 2015
On Mon, 2015-05-25 at 23:53 +0300, Kadir Beyazlı wrote:
> Hi,
Hi Kadir, I can see 2 problems with your code:
> # Start of plugin
> package Dancer2::Plugin::OnTuesday;
> # ABSTRACT: Make sure a route only works on Tuesday
> use Dancer2::Plugin;
>
> register on_tuesday => sub {
> my ( $dsl, $route_sub, @args ) = plugin_args(@_);
>
> my $day = (localtime)[6];
> $day == 2 or return pass;
>
> return $route_sub->( $dsl, @args );
^^^^
If you want to use your keyword as function on your route (as you are
doing), then you need to return a code ref here. See this for an
example:
https://github.com/PerlDancer/Dancer2-Plugin-Auth-Extensible/blob/master/lib/Dancer2/Plugin/Auth/Extensible.pm#L238
> };
>
> register_plugin;
> # End of plugin
>
> To be able to use above plugin at my local, I created .pm file at
> following folder:
>
> MyApp/lib/Dancer2/Plugin/OnTuesday.pm
>
> I wrote following code at folder MyApp/test.pl
>
> # Start of script
> use Dancer2;
> use lib "lib";
>
> use Dancer2::Plugin::OnTuesday;
>
> get '/' => on_tuesday => sub { return "tuesday" };
^^
Your other mistake is that you need to remove this fat comma
P.S. Make sure you view this plain text email in a fixed-width font (not
the default for Gmail?), otherwise you will probably be removing the
wrong fat comma ;-)
Andy
More information about the dancer-users
mailing list