On Thu, Dec 27, 2012 at 5:37 PM, Rolf Schaufelberger <<a href="mailto:rs@plusw.de">rs@plusw.de</a>> wrote:<br>> Hi,<br>> as I wrote in my previous mail I'm just testing Dancer if it can replace my current framework.<br>
><br>> Currently I'm using DBIC (and like to keep it) and I store some parameters and all my i18n stuff in a database.<br>> 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.<br>
> While I'm not shure yet, whether I can use some of the existing plugins for I18N,<br>> the general question for me is, how can I configure the order, how plugins are loaded and initialized ?<br>><br>> Regards<br>
> Rolf Schaufelberger<br><br>There are generally 2 ways to configure Dancer apps. You can do static<br>configuration via config files such as config.yml. You can do dynamic<br>configuration at run-time via the `set` and `config` keywords. The following is one approach<br>
you can take:<br><br><font face="courier new, monospace" size="1"> </font><span style="font-family:'courier new',monospace;font-size:x-small">use Dancer;</span><div><font face="courier new, monospace" size="1"> use Dancer::Plugin::DBIC qw(schema);<br>
<br> # Set configuration at run time. This code only runs once at app start-up.<br> my $dbconfig = schema->resultset('Config')->search({ env => 'production' });<br> # This will set top-level config settings.<br>
set $dbconfig->get_columns();<br> # You can use `config` to set nested values, such as for plugins.<br> config->{plugins}{I18N}{language} = $dbconfig->language;<br><br> # Now define your routes, etc.<br>
get '/' => sub { ... };<br><br> dance;</font><br><br>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.<br>
<br>I don't claim this is the best approach. Just the first thing that came to my mind.<br><br>Regards,<br>Naveed Massjouni</div>