[dancer-users] Usage Of Plugins Out Of CPAN

Andrew Beverley andy at andybev.com
Wed May 27 20:42:08 BST 2015


On Tue, 2015-05-26 at 22:09 +0300, Kadir Beyazlı wrote:
> return $route_sub->( $dsl, @args )
> 
> is a coderef.

But it doesn't necessarily return a coderef, and certainly didn't when I
ran the code myself.

>  But I read another article from following link :
> search.cpan.org/dist/Dancer2/lib/Dancer2/Plugin.pm
> 
> and saw that there are simpler ways of writing and calling a plugin.
> In my opinion, the example at first link is not good because people
> starting to Dancer2 read this article. I did following and it worked:
> 
>   package Dancer2::Plugin::Tuesday;
>   use Dancer2::Plugin;
> 
>   register tuesday => sub {
>     my $dsl  = shift;
>     my $app  = $dsl->app;
>     my $conf = plugin_setting();
> 
>     return "today is tuesday";
>   };
> 
>   register_plugin;
>   1;
> 
> and called in a simpler way  :
> 
> #test.pl
> use Dancer2;
> use lib "lib";
> 
> use MyDancer2::Plugin::Logout;
> 
> get '/' => sub { tuesday };
> 
> start;

Great, thanks for posting this. If you get a chance to submit a PR to
improve the documentation then that would be very welcome.

> >> get '/' => on_tuesday => sub { return "tuesday" };
> >
> >                        ^^
> > Your other mistake is that you need to remove this fat comma
> >
> [KB] I saw above call from first link. I copied it. If it is wrong I
> think it should be changed.

I don't know for sure off the top of my head whether the example is
wrong, but if it definitely doesn't work exactly as detailed in the
example, then please submit a PR or bug report.

Thanks,

Andy





More information about the dancer-users mailing list