Re: [Catalyst] Re: question for mst : using $c-config-{blah} ...
On Sun, Aug 03, 2008 at 06:30:02PM +0200, Daniel McBrearty wrote: wait, it is on $self not $c, so my reservations don't really apply. but what about reall config stuff that can change from one installation to another? then you have to do $c-config-{my_var}, right? How isn't something like connect_info real config? Put the config in a block specific to the model/view/controller that needs it and access stuff from within that component via $self-{whatever}, for preference. $self-config is broken since it only gives you the class level defaults which is why you should never call it. $c-config is an acceptable workaround for the fact we don't have a seperate app object so you can't do $c-app-my_var yet, but you should try and avoid needing it wherever possible. My preferred trick is to start off with a config file tailored to how the user sees it and wrap finalize_config to mangle it into appropriate components' config - see for e.g. http://code2.0beta.co.uk/reaction/svn/Reaction-Example-MailerForm/1.000/trunk/lib/MailerForm/ConfigFilter.pm and http://code2.0beta.co.uk/reaction/svn/Reaction-Example-MailerForm/1.000/trunk/t/config_filter.t for some simple mangling code and the end result - example configfile is at http://code2.0beta.co.uk/reaction/svn/Reaction-Example-MailerForm/1.000/trunk/mailerform.conf -- Matt S Trout Need help with your Catalyst or DBIx::Class project? Technical Directorhttp://www.shadowcat.co.uk/catalyst/ Shadowcat Systems Ltd. Want a managed development or deployment platform? http://chainsawblues.vox.com/http://www.shadowcat.co.uk/servers/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Re: question for mst : using $c-config-{blah} ...
On Mon, Aug 4, 2008 at 11:14 AM, Matt S Trout [EMAIL PROTECTED] wrote: On Sun, Aug 03, 2008 at 06:30:02PM +0200, Daniel McBrearty wrote: wait, it is on $self not $c, so my reservations don't really apply. but what about reall config stuff that can change from one installation to another? then you have to do $c-config-{my_var}, right? How isn't something like connect_info real config? By real config, I mean stuff which is entirely specific to the app, and not generic for a particular Cat component. An example might something like email addresses that input from a certain form is sent to. Maybe real wasn't the best word. Put the config in a block specific to the model/view/controller that needs it and access stuff from within that component via $self-{whatever}, for preference. $self-config is broken since it only gives you the class level defaults which is why you should never call it. $c-config is an acceptable workaround for the fact we don't have a seperate app object so you can't do $c-app-my_var yet, but you should try and avoid needing it wherever possible. In my app, I have done it rather differently - anything that is config is in the config file - class level or whatever. And everything is accessed using $c-config-{whatever} The reason I like this is simplicity - if it says config, I know where to find it, end of story. Just a personal preference. I guess if it isn't broken or likely to cause issues (it's been like that for a year and half now) I'm not going to worry about it. Thanks for the clarification. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Re: question for mst : using $c-config-{blah} ...
On Mon, Aug 04, 2008 at 01:59:06PM +0200, Daniel McBrearty wrote: On Mon, Aug 4, 2008 at 11:14 AM, Matt S Trout [EMAIL PROTECTED] wrote: On Sun, Aug 03, 2008 at 06:30:02PM +0200, Daniel McBrearty wrote: wait, it is on $self not $c, so my reservations don't really apply. but what about reall config stuff that can change from one installation to another? then you have to do $c-config-{my_var}, right? How isn't something like connect_info real config? By real config, I mean stuff which is entirely specific to the app, and not generic for a particular Cat component. An example might something like email addresses that input from a certain form is sent to. Maybe real wasn't the best word. You're drawing a line that doesn't exist. Your DBIC model is specific to your app. An email address that gets sent to is model or controller config - the example I showed you is a mailer form app - and the addresses and other form info get passed to the form manager model. In my app, I have done it rather differently - anything that is config is in the config file - class level or whatever. And everything is accessed using $c-config-{whatever} The reason I like this is simplicity - if it says config, I know where to find it, end of story. Just a personal preference. The reason I hate it is that it's a god object. But if it works for you for the moment, I wouldn't worry too much about it. Once the app/ctx split stuff comes in you'll probably want to rethink so you can have multiple copies of your app in the same process. But until then, I'd strongly recommend against it for new code but I don't see any business value to going back and changing old code that already works that way. -- Matt S Trout Need help with your Catalyst or DBIx::Class project? Technical Directorhttp://www.shadowcat.co.uk/catalyst/ Shadowcat Systems Ltd. Want a managed development or deployment platform? http://chainsawblues.vox.com/http://www.shadowcat.co.uk/servers/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] Re: question for mst : using $c-config-{blah} ...
wait, it is on $self not $c, so my reservations don't really apply. but what about reall config stuff that can change from one installation to another? then you have to do $c-config-{my_var}, right? On Sun, Aug 3, 2008 at 6:16 PM, Daniel McBrearty [EMAIL PROTECTED] wrote: (snip from another thread ...) You should never, ever EVER access $self-config in a model, view or controller object. Your config value will be in $self-{key}. It's considered normal to do package My::Controller::Foo; use strict; use warnings; use parent qw(Catalyst::Controller); __PACKAGE__-mk_accessors(qw(foo bar)); __PACKAGE__-config( foo = 'default_for_foo', bae = { default = 'for_bar' }, ); then later in your code just call $self-foo to get the runtime value. (/snip) Why is that Matt? I wasn't aware and have done it a fair bit. Not hard to change, but I'd like to know why. Not really a big deal, but I actually prefer the explicit use of config, for two reasons: 1. There is no chance of accidentally stomping on something else in $c namespace 2. It let;s you know where to go look for that particular bit of $c later in you need to cheers Daniel -- There's an infinite supply of time, we just don't have it all yet. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Re: question for mst : using $c-config-{blah} ...
On Sun, Aug 3, 2008 at 9:30 AM, Daniel McBrearty [EMAIL PROTECTED] wrote: wait, it is on $self not $c, so my reservations don't really apply. but what about reall config stuff that can change from one installation to another? then you have to do $c-config-{my_var}, right? It's all merged properly if you use ConfigLoader. In your MyApp.pm if you have: __PACKAGE__-config( 'Model::Foo' = { bar = 'baz' } ); And in MyApp/Model/Foo.pm you have: __PACKAGE__-config( bar = 'foo' ); If you have a method in Model::Foo, $self-{bar} will be equal to 'baz'. The order is always Component - App - External Conf. External Conf has other orders, but that's another email. You never want to use $c-config because $c-config-{'Model::Foo'} should, and in most cases will, be equal to $self-{...} config keys, you aren't guaranteed that. You are, however, guaranteed that $self-{...} keys are populated from config after component construction (component time, I believe) (mst, feel free to correct me if I got any points wrong :)) ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/