[dancer-users] Porting a plugin to Dancer 2

Stefan Hornburg (Racke) racke at linuxia.de
Wed May 15 08:36:16 BST 2013


On 05/14/2013 06:00 PM, Phin Jensen wrote:
> 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.
> 

Unfortunately Nitesi uses Nitesi::Object (a clone of "Dancer::Object") as base class, which is
think is causing this particular problem.

I'll look into this matter.

Regards
         Racke

-- 
LinuXia Systems => http://www.linuxia.de/
Expert Interchange Consulting and System Administration
ICDEVGROUP => http://www.icdevgroup.org/
Interchange Development Team



More information about the dancer-users mailing list