[dancer-users] Question about the Dancer2 tutorial under Windows/Apache as an app...

Gabor Szabo gabor at szabgab.com
Sun May 31 05:04:51 BST 2015


Strange. Why do you have the ($message) in the prototype of the function?

sub set_flash($message) {

If I have that I get a warning:

Illegal character in prototype for set_flash : $message at

Anyway you can put   debug("set_flash: $message") in the set_flash
functions to see on the console if it is really executed.

If that does not solve the problem, could you share a small but full
example that does work? (At least the full .pm file)

Gabor


On Sun, May 31, 2015 at 6:47 AM, Prairie Nyx <prairienyx at gmail.com> wrote:

> 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
>
> _______________________________________________
> dancer-users mailing list
> dancer-users at dancer.pm
> http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20150531/39acafa8/attachment.html>


More information about the dancer-users mailing list