[dancer-users] Order of loading plugins
Naveed Massjouni
naveedm9 at gmail.com
Fri Dec 28 13:17:34 GMT 2012
On Thu, Dec 27, 2012 at 5:37 PM, Rolf Schaufelberger <rs at plusw.de> wrote:
> Hi,
> as I wrote in my previous mail I'm just testing Dancer if it can replace
my current framework.
>
> Currently I'm using DBIC (and like to keep it) and I store some
parameters and all my i18n stuff in a database.
> So at server startup I need at first my DBIC connection settings to be
able to pull my other settings and my localization stuff from database.
> While I'm not shure yet, whether I can use some of the existing plugins
for I18N,
> the general question for me is, how can I configure the order, how
plugins are loaded and initialized ?
>
> Regards
> Rolf Schaufelberger
There are generally 2 ways to configure Dancer apps. You can do static
configuration via config files such as config.yml. You can do dynamic
configuration at run-time via the `set` and `config` keywords. The
following is one approach
you can take:
use Dancer;
use Dancer::Plugin::DBIC qw(schema);
# Set configuration at run time. This code only runs once at app
start-up.
my $dbconfig = schema->resultset('Config')->search({ env =>
'production' });
# This will set top-level config settings.
set $dbconfig->get_columns();
# You can use `config` to set nested values, such as for plugins.
config->{plugins}{I18N}{language} = $dbconfig->language;
# Now define your routes, etc.
get '/' => sub { ... };
dance;
In the above example, the DBIC plugin is configured first, behind the
scenes, via a config file such as config.yml (not shown). Since your other
plugin depends on it, you can configure it inside the app, at the file
lexical scope. This will only get run once, when your app is loaded
(unless you are running your app via CGI). And this provides some control
over the order that your plugins are "configured". I don't know how to
control the order that plugins are "loaded". But I know for the plugins I
have written, it is fine to load them in any order, and configure them
dynamically at run-time.
I don't claim this is the best approach. Just the first thing that came to
my mind.
Regards,
Naveed Massjouni
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20121228/548dcbd6/attachment.htm>
More information about the dancer-users
mailing list