[dancer-users] set vs var

Hermann Calabria hermann at ivouch.com
Mon Feb 22 18:23:58 GMT 2016


I’m using D1, and have a before hook that sets a var with a payload of session/client-specific values.  This works well when running D1 normally as a web app.  However there are a few tasks that need to run via a daily cron job, for which I load D1 manually.  In those cases I lose the vars setting, even if I set them manually, knowing the hook does not execute.

The following snippet:

  use strict;
  use Dancer ':syntax';  
  Dancer::Config::setting('appdir', '/home/s1/www/');
  Dancer::Config::setting('views', '/home/s1/www/views');
  config->{'environment'} = 'development';
  Dancer::Config::load();

  var hello => "hi, I used var";
  set hello => "hi, I used set";

  print template('test', {});          # uses Template Toolkit

with the following template test.tt:

  Hello using vars = <% vars.hello %>
  Hello using settings = <% settings.hello %>

yields:

  Hello using vars =
  Hello using settings = hi, I used set

In this case, ‘vars’ is not passed on to Template Tookit, whereas ‘settings’ is.  If I had run this within a normal D1 route, ‘vars’ would have been passed.

So it appears I need to refactor the entire (large) application to use “set” and not “var”.  Is this correct?  Why isn’t “var” the correct option here?  Or if it is, what am I doing wrong?

Thx in advance!
Hermann
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20160222/33027f8d/attachment.html>


More information about the dancer-users mailing list