[dancer-users] Usage Of Plugins Out Of CPAN
John Stoffel
john at stoffel.org
Thu May 28 01:09:31 BST 2015
>>>>> "Andrew" == Andrew Beverley <andy at andybev.com> writes:
Andrew> On Tue, 2015-05-26 at 22:09 +0300, Kadir Beyazlı wrote:
>> return $route_sub->( $dsl, @args )
>>
>> is a coderef.
Andrew> But it doesn't necessarily return a coderef, and certainly didn't when I
Andrew> 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;
So how the heck does this app know to use Dancer2::Plugin::Tuesday in
the first place? It's totally not obvious. And where did
MyDancer2::Plugin::Logout come from?
This example doesn't seem to be all that useful because it's not
showing and explaining how things work. We're not all web gods who do
this day in and day out for $WORK... so of us are poor mortals with
colds who feel fairly dumb right now. *grin*
Should test.pl really be:
use Dancer2;
use lib "lib";
use MyDancer2::Plugin::Tuesday;
get '/' => sub { tuesday; };
start;
Instead? What am I missing?
John
More information about the dancer-users
mailing list