[Dancer-users] init on first run
damien krotkine
dkrotkine at gmail.com
Sat May 21 11:37:51 CEST 2011
Hi,
you can use a state variable :
before sub {
state $cache_loaded ||= _load_cache();
}
the only requirements are that you use perl 5.10 or greater, and that
_load_cache() does all the init you want, and return true on success.
On 20 May 2011 20:57, Nick Knutov <mail at knutov.com> wrote:
> Hello all,
>
> what is the best way to do some initialization for some data on the only
> first run? Something like 'before sub', but it should run only on the first
> run of the script instance.
>
> Example of use:
>
> our $first;
> before sub {
> # if this is the first run of instance
> # $cache->{statuses} = ... # load some static data from DB
>
> # I can do
> # _load_cache() unless $first;
> # $first = 1;
> # but this is not beautiful
> }
>
> --
> Best Regards,
> Nick Knutov
> http://knutov.com
> ICQ: 272873706
> Voice: +7-904-84-23-130
> _______________________________________________
> Dancer-users mailing list
> Dancer-users at perldancer.org
> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.backup-manager.org/pipermail/dancer-users/attachments/20110521/3a3aac50/attachment.htm>
More information about the Dancer-users
mailing list