Re: [Catalyst] Defining ARRAY in Config::General config
On Tue, Sep 21, 2010 at 07:29, Pavel A. Karoukin hipp...@gmail.com wrote: Hello, I am using Catalyst::Plugin::Mail and want to define email config in myapp.conf. But C::P::Mail expects email config variable to be array ref. How I can assign array value to config variable in myapp.conf? Multiple rows with same name and different values form array in myapp.conf For example: room 7 room 9 room 13 Example is in Config::General syntax best regards Kamen ___ 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] best practices for handling forms?
Hi, A clean example that uses HTML::FormFu is: package MyApp::Controller::Foo; use Moose; extends 'Catalyst::Controller::HTML::FormFu'; # or just use parent 'Catalyst::Controller::HTML::FormFu' if you don't use Moose sub edit : Local FormConfig { my ($self, $c, $id) = @_; my $form = $c-stash-{form}; my $foo = $c-model(DB::Foo)-find($id); if ($form-submitted_and_valid) { $form-model-update($foo); $c-flash(notice = Foo was updated successfully.); $c-res-redirect($c-uri_for_action('/foo/index')); } else { $form-model-default_values($foo); } } sub edit : Local FormConfig { You can use Path or the chaining dispatch type or something else, not only Local. If you use the attribute FormConfig, it will search for the form placed by default in root/forms/foo/edit.conf If you want to use another specified form, you can use something like: sub edit : Local FormConfig('path/to/another/form') { my $form = $c-stash-{form}; If you use the FormConfig attribute, it will place the form in the stash automaticly so you just need to get it from there. my $foo = $c-model(DB::Foo)-find($id); This uses DBIx::Class result class DB::Foo for getting the $foo record. if ($form-submitted_and_valid) { This will be true only if the form past all the validation and constraints. $form-model-update($foo); This will update the $foo record in the database. In order to work this way, you need to have defined the database schema in myapp.conf like: 'Controller::HTML::FormFu' = { model_stash = { schema = 'DB', }, }, And in the edit.conf form configuration file (defined below using Config::General) you will need to have defined the resultset like: model_config resultset Foo /model_config $c-res-redirect($c-uri_for_action('/foo/index')); $c-uri_for_action is prefered because /foo/index is not a URI but an internal path to the index action from the Foo controller and this code doesn't need to be changed even if the public URI to that action changes. $form-model-default_values($foo); This fills the form with the values from $foo record when the form is displayed. HTH. --Octavian - Original Message - From: E R pc88m...@gmail.com To: The elegant MVC web framework catalyst@lists.scsys.co.uk Sent: Tuesday, September 21, 2010 12:48 AM Subject: [Catalyst] best practices for handling forms? Hi, I am curious what everyone thinks as being the best practices for handling forms in Catalyst. Are there any Catalyst applications you have run across which are good examples of how to use Catalyst's features to handle forms? To illustrate what I am getting at, below is typical Rails (v2) controller code which implements updating the attributes of an object: def edit @book = Book.find(params[:id]) @subjects = Subject.find(:all) end def update @book = Book.find(params[:id]) if @book.update_attributes(params[:book]) flash[:notice] = 'Book successfully updated.' redirect_to :action = 'show', :id = @book else @subjects = Subject.find(:all) render :action = 'edit' end end In Catalyst, this would be appear something like (and please correct me if I have made any errors here): sub edit :Args(1) { my ($self, $c, $id) = @_; ... set up $c-stash for template 'edit' ... # no need to set $c-stash-{template} - will be set from the current action } sub update :Args(1) { my ($self, $c, $id) = @_; ...process form... if (form is valid) { ...perform updates... $c-flash-{notice} = 'Book successfully updated.'; $c-res-redirect('show', $id); } else { ... set up $c-stash for 'edit' template ... $c-stash-{template} = 'edit'; } } Any comments on this architecture? Is there a better way? My main problems are: 1. The code ... set up $c-stash for 'edit' template ... is duplicated in both edit and update (which is also true for the Rails code). 2. Having the template name defaulted from the current action is nice, but that means we have to explicitly set it in the update method. Is it better to always explicitly set the template name in a controller method? Then update could perform a $c-detach('edit', $id) or would you use $c-go('edit', $id)? Thanks, ER ___ 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/ ___ 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] Defining ARRAY in Config::General config
The problem appears when the array should have just a single item, because in that case Config::General reports it as a scalar value. I don't know if there is a better way of defining a single-item array with Config::General, but I found a workaround that may work. We can use something like: foo bar foo This creates an array with 2 elements and the last one is undef. --Octavian - Original Message - From: Kamen Naydenov pa...@kamennn.eu To: The elegant MVC web framework catalyst@lists.scsys.co.uk Sent: Tuesday, September 21, 2010 9:05 AM Subject: Re: [Catalyst] Defining ARRAY in Config::General config On Tue, Sep 21, 2010 at 07:29, Pavel A. Karoukin hipp...@gmail.com wrote: Hello, I am using Catalyst::Plugin::Mail and want to define email config in myapp.conf. But C::P::Mail expects email config variable to be array ref. How I can assign array value to config variable in myapp.conf? Multiple rows with same name and different values form array in myapp.conf For example: room 7 room 9 room 13 Example is in Config::General syntax best regards Kamen ___ 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/ ___ 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] Defining ARRAY in Config::General config
On Tuesday, September 21, 2010 02:52:52 am Octavian Rasnita wrote: The problem appears when the array should have just a single item, because in that case Config::General reports it as a scalar value. I don't know if there is a better way of defining a single-item array with Config::General, but I found a workaround that may work. We can use something like: With Config::General = 2.47 and Config::Any = 0.20, you can use the syntax foo [ bar ] or foo = [ bar ] to set the key foo to an arrayref containing the single value bar. The latest version of Catalyst::Plugin::ConfigLoader will ensure that you're up to date. Andrew ___ 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] Defining ARRAY in Config::General config
Hi Andrew, I tried: C:\Documents and Settings\Teddy perl -MConfig::General -e print $Config::General::VERSION 2.49 #The program: use Config::General; use Data::Dumper; my $conf = Config::General-new('config.conf'); my %conf = $conf-getall; print Dumper \%conf; #The configuration file: array2 foo [ bar ] /array2 foo [ bar ] #The result: $VAR1 = { 'foo' = '[ bar ]', 'array2' = { 'foo' = '[ bar ]' } }; So it seems it doesn't work as it should because it creates a scalar that contains [ bar ]. Am I missing something? Thanks. --Octavian - Original Message - From: Andrew Rodland and...@cleverdomain.org To: The elegant MVC web framework catalyst@lists.scsys.co.uk Sent: Tuesday, September 21, 2010 11:27 AM Subject: Re: [Catalyst] Defining ARRAY in Config::General config On Tuesday, September 21, 2010 02:52:52 am Octavian Rasnita wrote: The problem appears when the array should have just a single item, because in that case Config::General reports it as a scalar value. I don't know if there is a better way of defining a single-item array with Config::General, but I found a workaround that may work. We can use something like: With Config::General = 2.47 and Config::Any = 0.20, you can use the syntax foo [ bar ] or foo = [ bar ] to set the key foo to an arrayref containing the single value bar. The latest version of Catalyst::Plugin::ConfigLoader will ensure that you're up to date. Andrew ___ 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/ ___ 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] Defining ARRAY in Config::General config
On Tue, Sep 21, 2010 at 2:14 PM, Octavian Rasnita octavian.rasn...@ssifbroker.ro wrote: Hi Andrew, I tried: C:\Documents and Settings\Teddy perl -MConfig::General -e print $Config::General::VERSION 2.49 #The program: use Config::General; use Data::Dumper; my $conf = Config::General-new('config.conf'); To obtain single value arrays with the syntax in question, the above line should be: my $conf = Config::General-new( -ConfigFile = 'config.conf', -ForceArray = 1 ); ___ 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] Defining ARRAY in Config::General config
On Tue, Sep 21, 2010 at 8:06 AM, Emanuele Zeppieri ema...@gmail.com wrote: On Tue, Sep 21, 2010 at 2:14 PM, Octavian Rasnita octavian.rasn...@ssifbroker.ro wrote: Hi Andrew, I tried: C:\Documents and Settings\Teddy perl -MConfig::General -e print $Config::General::VERSION 2.49 #The program: use Config::General; use Data::Dumper; my $conf = Config::General-new('config.conf'); To obtain single value arrays with the syntax in question, the above line should be: my $conf = Config::General-new( -ConfigFile = 'config.conf', -ForceArray = 1 ); How I can pass this -ForceArray to Config::General in my catalyst app? Regards, Pavel ___ 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] Defining ARRAY in Config::General config
On Tue, Sep 21, 2010 at 3:30 PM, Pavel A. Karoukin pa...@yepcorp.com wrote: On Tue, Sep 21, 2010 at 8:06 AM, Emanuele Zeppieri ema...@gmail.com wrote: On Tue, Sep 21, 2010 at 2:14 PM, Octavian Rasnita octavian.rasn...@ssifbroker.ro wrote: Hi Andrew, I tried: C:\Documents and Settings\Teddy perl -MConfig::General -e print $Config::General::VERSION 2.49 #The program: use Config::General; use Data::Dumper; my $conf = Config::General-new('config.conf'); To obtain single value arrays with the syntax in question, the above line should be: my $conf = Config::General-new( -ConfigFile = 'config.conf', -ForceArray = 1 ); How I can pass this -ForceArray to Config::General in my catalyst app? http://search.cpan.org/~bricas/Catalyst-Plugin-ConfigLoader-0.30/lib/Catalyst/Plugin/ConfigLoader.pm#DESCRIPTION ___ 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: Defining ARRAY in Config::General config
Pavel A. Karoukin pa...@yepcorp.com writes: On Tue, Sep 21, 2010 at 8:06 AM, Emanuele Zeppieri ema...@gmail.com wrote: To obtain single value arrays with the syntax in question, the above line should be: my $conf = Config::General-new( -ConfigFile = 'config.conf', -ForceArray = 1 ); How I can pass this -ForceArray to Config::General in my catalyst app? Upgrade Config::Any to version 0.20, which passes it by default. If you don't want to specify a direct versioned requirement for an indirect dependency in your Makefile.PL, you can require Catalyst::Plugin::ConfigLoader version 0.29, which depends on Config::Any version 0.20. -- ilmari A disappointingly low fraction of the human race is, at any given time, on fire. - Stig Sandbeck Mathisen ___ 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] Defining ARRAY in Config::General config
On Tue, Sep 21, 2010 at 8:53 AM, Emanuele Zeppieri ema...@gmail.com wrote: On Tue, Sep 21, 2010 at 3:30 PM, Pavel A. Karoukin pa...@yepcorp.com wrote: On Tue, Sep 21, 2010 at 8:06 AM, Emanuele Zeppieri ema...@gmail.com wrote: On Tue, Sep 21, 2010 at 2:14 PM, Octavian Rasnita octavian.rasn...@ssifbroker.ro wrote: Hi Andrew, I tried: C:\Documents and Settings\Teddy perl -MConfig::General -e print $Config::General::VERSION 2.49 #The program: use Config::General; use Data::Dumper; my $conf = Config::General-new('config.conf'); To obtain single value arrays with the syntax in question, the above line should be: my $conf = Config::General-new( -ConfigFile = 'config.conf', -ForceArray = 1 ); How I can pass this -ForceArray to Config::General in my catalyst app? http://search.cpan.org/~bricas/Catalyst-Plugin-ConfigLoader-0.30/lib/Catalyst/Plugin/ConfigLoader.pm#DESCRIPTION Thank you! ___ 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] Pb with fcgid on CentOS
Hi, I have a trouble to run Catalyst with Apache2/fcgid/suexec on CentOS 5.5 I have a classical VirtualHost definition in the apache configuration with : DocumentRoot /opt/myapp/root Alias /static /opt/myapp/root/static SuexecUserGroup appuser appuser Location /static SetHandler default-handler /Location Alias / /var/www/myapp/myapp_wrapper.fpl/ Location / Options ExecCGI Order allow,deny Allow from all /Location The myapp_wrapper.fpl contains mainly : unshift @ARGV, /opt/myapp/script/myapp_fastcgi.pl; exec @ARGV or die... to run the fastcgi command of Catalyst keeping the arguments. (The fpl script must be in /var/www because of suexec configuration). The wrapper script is called, the fastcgi.pl script also, but ends up with : STDIN is not a socket; specify a listen location at .../Catalyst/Engine/FastCGI.pm line 95. It seems to me, according fcgid documentation, that a socket is created, but it is not send to the myapp_fastcgi.pl A Dumper(\...@argv) and Dumper(\%ENV) in the wrapper reveals that no arguments are send to the script, and that the environment variables only contains PATH, so error message is correct... Suggestions welcome... -- Julien Gilles. ___ 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] Make the money format macro globally available.
Hi Duncan - On Tue, 21 Sep 2010 17:52 +0100, Duncan Garland duncan.garl...@motortrak.com wrote: How do you make the money macro available in all templates? [% USE money=format('%.2f') -%] Presumably something goes in here: __PACKAGE__-config( TEMPLATE_EXTENSION = '.tt', render_die = 1, WRAPPER = 'wrapper.tt', ); You can put commonly used macros, formats, etc. in a file named e.g. pre_process_config.tt in your main templates directory, then add PRE_PROCESS to your config: __PACKAGE__-config( TEMPLATE_EXTENSION = '.tt', render_die = 1, WRAPPER = 'wrapper.tt', PRE_PROCESS = 'pre_process_config.tt'. ); HTH, Larry ___ 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] best practices for handling forms?
Hernan, Octavian - thanks for your replies. Both of you have given examples where the display of the form and the processing of the form are handled by the same method. In that case in order to go from one page to the next you always need to use a redirect. Doing this is very clean, but it involve another communications round trip. If the form display and form processing are handled by separate methods, you can avoid the redirect if you're careful. Any thoughts on this issue? Thanks, ER ___ 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] Defining ARRAY in Config::General config
From: Emanuele Zeppieri ema...@gmail.com To obtain single value arrays with the syntax in question, the above line should be: my $conf = Config::General-new( -ConfigFile = 'config.conf', -ForceArray = 1 ); Aa, thanks. Octavian ___ 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] best practices for handling forms?
You don't need to do the redirect if you don't want it, but it is the recommended way. Instead of the redirect, you can forward to another method that prints the page you want: $c-forward('foo/success_method', ['possible', 'parameters']); In that case after the data is stored in DB, the specified method is called. But after doing a POST request it is a good idea to do a redirect because if the user would refresh the page, he might send the posted data again. Octavian - Original Message - From: E R pc88m...@gmail.com To: The elegant MVC web framework catalyst@lists.scsys.co.uk Sent: Tuesday, September 21, 2010 8:25 PM Subject: Re: [Catalyst] best practices for handling forms? Hernan, Octavian - thanks for your replies. Both of you have given examples where the display of the form and the processing of the form are handled by the same method. In that case in order to go from one page to the next you always need to use a redirect. Doing this is very clean, but it involve another communications round trip. If the form display and form processing are handled by separate methods, you can avoid the redirect if you're careful. Any thoughts on this issue? Thanks, ER ___ 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/ ___ 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] Defining ARRAY in Config::General config
On Tuesday, September 21, 2010 08:30:43 am Pavel A. Karoukin wrote: On Tue, Sep 21, 2010 at 8:06 AM, Emanuele Zeppieri ema...@gmail.com wrote: On Tue, Sep 21, 2010 at 2:14 PM, Octavian Rasnita my $conf = Config::General-new( -ConfigFile = 'config.conf', -ForceArray = 1 ); How I can pass this -ForceArray to Config::General in my catalyst app? By having the current version of Config::Any installed, like I said in the first place. :) Andrew ___ 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] New install getting Wide character in syswrite error
Good afternoon, I setup an installation of our app for a new developer last night and keep getting the 'Caught exception in engine Wide character in syswrite at...' error when making POST requests. Reading through the archives I expect this is a Unicode encoding problem. But I can't figure out where I'm going wrong with the new setup. (Note, the app works fine on 4 other workstations/servers, so I'm guessing it's a problem specific to this one setup.) There was a test error when installing Catalyst::Plugin::Unicode::Encoding. I downgraded Encode to v2.39 and then Catalyst::Plugin::Unicode::Encoding installed cleanly. The plugin list is: __PACKAGE__-setup(qw/ ConfigLoader AutoCRUD Static::Simple Params::Nested I18N Unicode::Encoding Cache::HTTP Session Session::Store::DBIC Session::State::Cookie Session::State::URI Authentication Authorization::Roles Authorization::ACL RequireSSL Cache /); What else can I try to resolve this problem? Thanks, Charlie -- Ꮚ Charlie Garrison ♊ garri...@zeta.org.au O ascii ribbon campaign - stop html mail - www.asciiribbon.org 〠 http://www.ietf.org/rfc/rfc1855.txt ___ 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/