On Sun, 2011-07-03 at 10:25 +0600, Nick Knutov wrote:
Thanks! Look like exactly what I need.
btw, is there any way to run 'before' in such scripts?
Well, 'before' handlers are supposed to run before a request; given that you're looking at a script where there is no request, I think them not running is correct and expected.
I changed
before sub {...}
to
sub _init {...} before sub {_init()}; # in main app
app::_init(); # in Dancer ':script' app
but this is ugly.
It'll do the job, even if a little ugly. Personally, if it's code that should run on startup before any requests are processed, I'd just put it in the script as-is, rather than in a before handler - e.g. use Dancer qw(:script); # my initialisation code goes here # now declare routes -- David Precious ("bigpresh") http://www.preshweb.co.uk/ "Programming is like sex. One mistake and you have to support it for the rest of your life". (Michael Sinz)