[dancer-users] Porting a plugin to Dancer 2
Phin Jensen
phin at endpoint.com
Tue May 14 17:00:29 BST 2013
Hello,
I'm new to Perl, and Dancer, and I've been working on porting a plugin
(Dancer::Plugin::Nitesi) to Dancer 2. Reading the documentation on
Dancer2::Plugin, all I can see that is different in Dancer 2 plugins is
the use of the $dsl variable.
So I added 'my $dsl = shift;' to every 'sub' or 'register ... => sub',
and changed the necessary code to use the $dsl variable, but in one
subroutine, it will only give this error:
Variable "$dsl" is not imported at
<home>/perl5/perlbrew/perls/perl-5.16.3/lib/site_perl/5.16.3/Dancer2/Plugin/Nitesi.pm
line 347.
This is the code for the subroutine:
> sub _update_session {
> my $dsl = shift;
> my ($function, $acct) = @_;
> my ($key, $sref);
>
> my $settings = plugin_setting();
>
> # determine session key
> $key = $settings->{Account}->{Session}->{Key} || 'user';
>
> $function ||= '';
>
> if ($function eq 'init') {
> # initialize user related information
> $dsl->app->session{$key} = $acct;
> } elsif ($function eq 'update') {
> # update user related information (retrieve current state
> first)
> $sref = $dsl->app->session{$key};
>
> for my $name (keys %$acct) {
> $sref->{$name} = $acct->{$name};
> }
>
> $dsl->app->session->{$key} = $sref;
>
> return $sref;
> }
> elsif ($function eq 'destroy') {
> # destroy user related information
> $dsl->app->session->{$key} = undef;
> }
> else {
> # return user related information
> return $dsl->app->session($key);
> }
> };
I've tried changing the $dsl declaration to all of these:
> my ($dsl, $function, $acct) = @_;
> my ($function, $acct, $dsl) = @_;
> my ($function, $dsl, $acct) = @_;
> my $dsl = shift @_;
Nothing seems to work.
I've attached the whole file. I'm pretty sure it's the only file I've
changed, and I've probably made a mess of it.
Any help would be much appreciated, again, I'm new to Perl and Dancer,
so I don't really know what I'm doing.
Thanks.
--
Phin Jensen
End Point Corporation
phin at endpoint.com
404-692-4034
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Nitesi.pm
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20130514/5a44bf79/attachment.asc>
More information about the dancer-users
mailing list