[dancer-users] Question about the Dancer2 tutorial under Windows/Apache as an app...
Prairie Nyx
prairienyx at gmail.com
Sun May 31 04:47:55 BST 2015
Perl Dancer Community:
I am converting from Dancer to Dancer2 (better late than never) and also
developing some preliminary curriculum materials for CoderDojo using Perl
Dancer2 as a framework for web development.
I started with SawyerX's tutorial page:
http://search.cpan.org/~xsawyerx/Dancer2/lib/Dancer2/Tutorial.pod
The "dancr.pl" tutorial program ran just fine under the port 3000 server
and the tutorial was useful and instructive:
C:\Users\CoderDojo\Perl\Dancer\dancr>perl dancr.pl
>> Dancer2 v0.160001 server 2496 listening on http://0.0.0.0:3000
I ran into an issue when I tried to convert this demo into an app that
would run under Apache in a Windows environment, however.
The *crux* of the issue is that the "$flash message" does not work in the
app (I suspect because the global variable $flash and the two subroutines
are not part of a route, but I could *really* use an explanation, if this
issue is obvious to someone:
I created the app as normal:
C:\Apache24\htdocs>*dancer2 -a dancr*
+ dancr
+ dancr\config.yml
+ dancr\cpanfile
+ dancr\Makefile.PL
+ dancr\MANIFEST.SKIP
+ dancr\bin
+ dancr\bin\app.psgi
+ dancr\environments
+ dancr\environments\development.yml
+ dancr\environments\production.yml
+ dancr\lib
+ dancr\lib\dancr.pm
+ dancr\public
+ dancr\public\dispatch.cgi
+ dancr\public\dispatch.fcgi
+ dancr\public\404.html
+ dancr\public\500.html
+ dancr\public\favicon.ico
+ dancr\public\css
+ dancr\public\css\error.css
+ dancr\public\css\style.css
+ dancr\public\images
+ dancr\public\images\perldancer-bg.jpg
+ dancr\public\images\perldancer.jpg
+ dancr\public\javascripts
+ dancr\public\javascripts\jquery.js
+ dancr\t
+ dancr\t\001_base.t
+ dancr\t\002_index_route.t
+ dancr\views
+ dancr\views\index.tt
+ dancr\views\layouts
+ dancr\views\layouts\main.tt
With the resulting app files, I added the code from the original "dancr.pl"
demo to the applications "dancr.pm" module:
package dancr;
use Dancer2;
our $VERSION = '0.1';
get '/' => sub {
template 'index';
};
true;
I had to make the following adjustments to the code for Windows/Apache:
(1) Change the session to YAML
#set 'session' => 'Simple';
set 'session' => 'YAML';
(2) Adjust the path for request->base:
# $tokens->{'css_url'} = request->base . 'css/dancr.css';
$tokens->{'css_url'} = request->base . '/css/dancr.css';
Everything with the app works as expected *except* for the "$flash message"
code:
my $flash;
sub set_flash($message) {
my $message = shift;
$flash = $message;
}
sub get_flash {
my $message = $flash;
$flash = '';
return $message;
}
I suspect that since these subs are outside a route, perhaps I'm getting an
effect about the scope of the variables... but calls to these subroutines
do *not* set $flash or $message as expected:
template 'show_entries.tt', {
'msg' => get_flash,
set_flash('New entry posted!');
set_flash('You are logged in.');
set_flash('You are logged out.');
For each of these, the $flash variable (which is a free-standing global in
the module) is never set... and so the get_flash sub never returns a value.
--
Prairie Nyx
prairienyx at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20150530/8f723b21/attachment.html>
More information about the dancer-users
mailing list