Re: [Catalyst] Subject: Simple question: setting pre-set fields/creation actions in Catalyst::Controller::DBIC::API::REST
first things first. In a restful environment, a client might create a request with json content and a header that specifys the content type which is being sent to the web server. The web server will receive that request containing XYZ-content then it will look up the request header Content-Type which must indicate that content being sent is application/json. Then, it can correctly parse that XYZ-content into the proper content type and transform it into a perl structure that you can store or do something else. Then, you will process that content and generate a response for the requesting client. If your app will respond to the client with a json content you must specify that into the response header: content-type: application/json. That way when the client receives that response it will know the content is a json and correctly understand it. So you should get that working and understood before you can proceed. Check if you are receiving some content in the correct controller. Try do Dump the contents of $c-req and make sure you are getting the correct contents with the respective content types. cheers, Hernan Lopes On Thu, Jun 5, 2014 at 7:27 AM, Andy Holyer andyh.ena...@gmail.com wrote: I've been coding in Perl for years, but I'm still pretty new to Catalyst, so please excuse the newbie question. I'm putting together a Catalyst application which uses Calalyst::Controller::DBIC::API::REST to interface with the database. So, in lib/MyApp/Controller/ there are a bunch of files of the form {Table}.pm, which each consists of basically a __PACKAGE__-config() call setting various things, including create_requires, create_allows and so on. Simple question: Several of these tables require status etc. to be set heardwired in code, and several of the others have some business logic which needs to take place on e.g. creation. What's the canonical way to do this? I'm guessing it means defining a begin method, but I'd really like to know the proper way to do this. Can't see this anywhere in the docs (unless I'm looking in the wrong place), but it's such a common occurrence it *must* be a FAQ. Thanks in Advance. Andy Holyer, Brighton, UK ___ 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] automatically updating a join table
Having in mind you are new to perl, do not continue development untill you learn about Data::Dumper and Data::Printer. With these tools you can Dump the contents of variables/objects and see which methods and attributes are avaliable, and you can see the type of those variables/objects. You can do so by trying: $ perl -e 'use URI; my $x=URI-new(http://www.bla.com/bla;) ; use DDP; warn p $x; '\ So when you do that with $user, you will find out $user is actually related to DBIx::Class object. And, that method create_related is actually related to DBIx::Class. When you do: $c-model('DB::User')-new_result({}); You are actually using the DB::User model which is a DBIx::Class table class. DBIx::Class is the orm the tutorial uses. And also probably the most complete orm from all the existing programing languages. If you want to learn more about DBIx::Class, you must read the documentation: http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/ResultSet.pm#new_result I would suggest you halt your development there, and start another quicky one that will only use DBIx::Class orm. So you can create 1 'test table' in your sql test database with a couple rows. Then, you can make a quick script (a simple perl.pl file) and try to create, update, delete and select rows from that table using the DBIx::Class orm. Also have in mind that people often call DBIx::Class as dbic. That simple perl script would look something like this: 0. create a simple database with a simple table with a couple of columns. (you can do that in your database) 1. create the orm schema using *DBIx*::*Class*::*Schema*::*Loader *like this: dbicdump -o dump_directory=./lib \ -o debug=1 \ DB::Some::Database::Namespace \ 'dbi:Pg:dbname=your_database_name' \ myuser \ mypassword 2. create a script.pl that will use the generated schema: use lib ( ./lib ); use DBSchema; medico my $schema = DBSchema-connect('dbi:Pg:dbname=your_database_name', 'hernan', 'lopes'); my $plant = $schema-resultset('Plant')-find({ id = 1}); #search in table Plant where id = 1 print $plant-color; #green check the dsn correct for your database... dbi::Pg:dbname is for postgres. Lookup the one you must use. also, when you execute the script.pl you can do so with the DBIC_TRACE=1 option, ie: $ export DBIC_TRACE=1 perl script.pl That way you will see debug output. One handy dbic row method is: http://search.cpan.org/~ribasushi/DBIx-Class-0.08250/lib/DBIx/Class/Row.pm#update_or_insert try using that one. When you are able to insert, update and search and find, try creating relationships among tables and re-run the dbicdump command so your orm mappings get updated. Also, remember -search returns multiple items and -find is for 1 item. then you will be able to continue on that example you are working on, all by yourself. And, welcome to perl and catalyst, I hope you are being able to do what you need. Its powerful tools once you master them. On Thu, Jun 5, 2014 at 8:20 PM, Bob Miller b...@computerisms.ca wrote: Hello I am new to Perl and Catalyst, I hope I my terminology correct. much gratitude to the authors of the fine Catalyst documentation, the tutorials are excellent tools of understanding... I have been through the tutorial and am currently modelling after the authentication and authorization article on the advent calendar found here: http://www.catalystframework.org/calendar/2011/15 The goal: I want users of roleB to create new users that are automatically set to roleA. So I created an authentication chain, and have created a related set of templates and forms to play with. The goal is to remove the Role selection option and have the userroles join table updated automatically at user creation time. The efforts: I started in Form/EditUser.pm has_field arguments by setting a default = 1 argument and omitting the field from displaying in the template, but it did not update the join field. I found in HTML::FormHandler::Manual::Defaults an explanation that if the item object contains an accessor, the default won't be used. since in following the example I am using an accessor, it seems I will not succeed using the form to set the value. I looked at the useradd sub in the example again, I saw fields being automatically set like so: my $user = $c-model('DB::User')-new_result({}); $user-password($temp_password); So I figured I should be able to use the accessor to do the same in the join table, maybe like: $user-userroles({'roleid' = '1'}); This, nor any variation on syntax I tried, does not update the join table when the user is created. I went back through the basicCRUD tutorial, and found the example where the book_author table is updated, and it uses an argument called create_related (or add_to_$rel), so I tried $user-create_related('userroles', {roleid = '1'}); It actually works quite well in that when the form is processed the user is created
Re: [Catalyst] Re: New design
its because catalyst can do everything, including dance. And its solid like a brick. And cpan is the universe that has all the things. []'s Hernan On 7/24/13, Lance A. Brown la...@bearcircle.net wrote: David Dorward said the following on 7/23/2013 7:30 PM: Then we come to Man With A Brick. Putting the first brick in place is a good image for getting started … but completely breaks from the space theme from elsewhere in the page. It's also the first section that uses translucent backgrounds and it really feels like part of a different site. Man with a Brick is an image from near the end of the movie The Fifth Element. Does that generate licensing/copyright/etc. issues? Design looks cool. I see the same issue with the space dancers others have mentioned. --[Lance] -- GPG Fingerprint: 409B A409 A38D 92BF 15D9 6EEE 9A82 F2AC 69AC 07B9 CACert.org Assurer ___ 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] New design
Good good On 7/23/13, Mark Keating m.keat...@shadowcat.co.uk wrote: The nice chaps at Evozon have recently been making design mocks for a bunch of Perl sites and they have come up with a fresh look for Catalyst. Take a look and let me know what you guys think. http://www.mdk.me.uk/community/mocks/Catalyst.jpg Kind regards Mark -- Mark Keating BA (Hons), Writer, Photographer, Cat-Herder. Managing Director: http://www.shadow.cat For more that I do visit: http://www.mdk.me ___ 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] How to avoid repeating methods in controllers ?
you might want something like this, where one class defines common attributes, and other classes extend it, for example package CommonAttributes; use Moose; has name = ( is = 'rw', ); sub jump { my ( $self, $c ) = @_; warn JUMP; } 1; package ControllerOne; use Moose; extends qw/CommonAttributes/; sub method_controller_one { my ( $self ) = @_; warn method from controller 1; } 1; package ControllerTwo; use Moose; extends qw/CommonAttributes/; sub method_controller_two { my ( $self ) = @_; warn method from controller 2; } 1; package MyApp; my $one = ControllerOne-new( name = 'Name: One' ); $one-method_controller_one(); warn $one-name; $one-jump; my $two = ControllerTwo-new( name = 'Name Two:' ); warn $two-name; $two-method_controller_two(); $one-jump; On 7/21/13, Robert Rothenberg rob...@gmail.com wrote: I prefer to put as much code as I can (especially business logic code) into Moose role methods. This makes it easier to share code among multiple controller methods, and it makes the code a little easier to read as well as test (since the role methods don't require the Catalyst server to be running per se: the context can be simulated using CatalystX::Test::MockContext). If the code really does require a controller, I create a base controller class that uses configuration parameters from $self-{config}, and then have the actual controllers use something like __PACKAGE__-config( table = 'foo', .. ); On Wed, Jul 17, 2013 at 3:05 AM, cc loo mobile.cc...@gmail.com wrote: Hi all, i'm a network engineer by trade and is picking up perl/catalyst to upgrade my skills :) I have a couple of controllers each having same methods, chaining off their respective 'base' methods. I build my controllers off this guide here: http://search.cpan.org/~ether/Catalyst-Manual-5.9007/lib/Catalyst/Manual/Tutorial/04_BasicCRUD.pod#Refactor_to_Use_a_'base'_Method_to_Start_the_Chains So, i have controller_a with a method 'list' , chaining off 'base' controller_b with a method 'list', chaining off' 'base' Is there a more graceful manner of inheriting this method instead of copy/paste on every controller i have ? ___ 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] FormFu: How to ensure a field value is unique?
There is only one way.. you must check if that id exists wherever you are saving it... and you can verify in many ways... ie. ajax, or on form submit. In your case, follow the formhandler docs and you will find a section where it validates the form... in that point, you can show the error to your user: 'username already registred' On Mon, Jun 3, 2013 at 11:31 AM, Carl Franks fireart...@gmail.com wrote: Hi, On 2 June 2013 12:33, Bjørn-Helge Mevik b...@mevik.net wrote: model: DB::OpusTwikiBrukernavn 'resultset' is not defined at /home/bhm/perl5/lib/perl5/HTML/FormFu.pm line 498. HTML::FormFu::Model::DBIC can retrieve the DBIC schema when you set either 'schema', or both 'context' and 'model', or just 'context' by calling for its default model. resultset() must always be set - so you can't just pass the entire resultset name to 'model'. Try this config instead of the single 'model' above: model: DB resultset: OpusTwikiBrukernavn Use of uninitialized value $name in pattern match (m//) at /home/bhm/perl5/lib/perl5/HTML/FormFu/Element.pm line 71. Use of uninitialized value $root in hash element at /home/bhm/perl5/lib/perl5/HTML/FormFu/Role/NestedHashUtils.pm line 43. I don't think this is also immediately linked to your error, but it indicates that you're using a field element without a name - this is unsupported by FormFu, and may cause other errors. Carl ___ 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] catalyst and dojo, ajax come from?
Ajax means: Asynchronous Javascript and XML That means you must have some sort of client, that usualy is the web browser (toghether with your dojo). And, that browser makes ajax calls to the web services... and those webservices could be catalyst, with tt, or whatever you want. So the true function of ajax is always to perform asynchronous javascript and xml... Only your web browser must know about the ajax.. the webserver doesnt need to know what is ajax.. the webserver must receive a request and send back a response with content type..,. if that request is a complete page, or a small div from ajax call, that doesnt matter for the web server... it doesnt need to know its answering ajax call. The webserver will treat it as a request. So... catalyst respond to requests... that request can be anything. And, the browser knows about ajax and uses its features. On Sat, May 4, 2013 at 6:28 AM, 疾驰者 78778...@qq.com wrote: Hi: I may be a newbie to catalyst or dojo. My app is a data heavy app, the major function is to import data, manipulate data and display data. I want to use Catalyst, TT, dojo develop this app. My question is about ajax, catalyst include ajax and dojo include ajax. In such app using catalyst and dojo, what's the true function about ajax from catalyst or dojo? Thanks any response. ___ 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] moniker_map arg in app_create.pl
you should name your model singular, not plural On Wed, May 4, 2011 at 1:31 PM, matthew couchman (JIC) matthew.couch...@bbsrc.ac.uk wrote: Hi, I have a table called plant_species which by default creates a schema result class PlantSpecy when I run my app_create.pl script. To get around this I’ve tried passing moniker_map=’{ plant_species = “PlantSpecies” }’ as an extra argument. It looks like the argument is read because it appears in lib/App/Model/App.pm but I still have a PlantSpecy.pm file rather than PlantSpecies.pm. Can anyone help? Thanks very much, Matt. ___ 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] Caching SQL results for speed...?
i remember you mentioned something about many to many select options, try disabling those.. and then does the form works faster? if so, then the problem is mostly like in there ... try populating your options manually On Thu, Apr 14, 2011 at 1:15 PM, will trillich will.trill...@serensoft.comwrote: On Wed, Apr 13, 2011 at 1:19 AM, Darren Duncan dar...@darrenduncan.netwrote: will trillich wrote: 70% of the time is taken up in five modules: 1) SQL::Abstract 2) DBIx::Class::ResultSet 3) Class::Accessor::Grouped 4) DBIx::Class::Storage::DBI 5) HTML::FormHandler::Field ...because in 200 iterations they were called millions of times each. (The form requested has several select/option menus.) So, several 5000s (millions / 200) of calls for a single screen? That sounds like a lot for one screen. Do you need that much? -- Darren Duncan My question is similar -- why five thousand or more calls for rendering one page? The code does simple things like my $form = $self-form; # parse_form_for_numerics(): # change any $1,234 to 1234, parse 12-apr-09 to a date 2009-04-12, etc # and stuff results into $c-req-params parse_form_for_numerics( $c, $form ); my $processed = $form-process( item = $item, params = $c-req-params, ); if ( $form-has_errors) { ... } return unless $processed; # since we're testing rendering a fresh page there's no processing, that's it So why would this simple code generate 5,000+ calls to SQL::Abstract methods or to DBIx::Class::Resultset methods? Even commenting-out #parse_form_for_numerics() it's about the same. Still looking into this. -- 11 cheers for binary! ___ 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] Catalyst under Plack (PSGI)
to configure your logs on catalyst and psgi, create your myapp/script/my_app.psgi correctly and tell it where to log, like this #!/usr/bin/env perl use strict; use warnings; use lib ( ./lib ); use MyApp; use Catalyst::Engine::PSGI; use FCGI::ProcManager; use Plack::Builder; use Plack::Middleware::AccessLog; use Plack::Middleware::Debug; my $name = `pwd`; $name =~ s/\W//g; my $log_dir = '/catalyst'; die log_dir $log_dir does not exist\n unless -d $log_dir; die log_dir $log_dir is not writable\n unless -w $log_dir; MyApp-setup_engine('PSGI'); my $app = sub { MyApp-run(@_) }; builder { my $logfh; my $access_logfile = $log_dir/access-log-$name; my $error_logfile = $log_dir/error-log-$name; open $logfh, , $access_logfile or die $!; open STDERR, , $error_logfile or die $!; $logfh-autoflush(1); enable AccessLog, logger = sub { print $logfh @_ }; # if we're using perlbal, fix some request params. replace 12.34.56.78 with your public IP enable_if { $_[0]-{REMOTE_ADDR} eq '127.0.0.1' || $_[0]-{REMOTE_ADDR} eq '123.123.123.123' } Plack::Middleware::ReverseProxy; return $app; }; On Mon, Feb 21, 2011 at 9:11 AM, Oleg A. Mamontov o...@mamontov.net wrote: Hello. I trying to switch my Catalyst application from mod_perl to Plack. But can't understand how to deal with stderr properly? Warning from catalyst goes to stderr and Plack doesn't capture it into psgi.errors, is it right behavour? Now i use workaround: C::P::Log::Dispatch and C::P::LogWarnings, but it seems to me not the right decision. Perhaps Catalyst::Engine::PSGI may duplicate stderr with psgi.errors? -- Cheers, Oleg A. Mamontov mailto: o...@mamontov.net jabber: lon...@charla.mamontov.net icq uin: 79-521-617 cell:+7-903-798-1352 ___ 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] Authentication not working as expected
I dont know about the book, but this manual sure works and my opinion is its better than any book, (find the authorization/authentication and compare what you missed) the url should be http://search.cpan.org/~zarquon/Catalyst-Manual-5.8005/lib/Catalyst/Manual/Tutorial/01_Intro.pod att, Hernan On Tue, Jan 11, 2011 at 2:09 PM, Ben Lavery ben.lav...@gmail.com wrote: Dear all, After installing Catalyst on an OpenIndiana virtual machine, I've been working through the Definitive Guide to Catalyst for the last few weeks and have been impressed with how smoothly most of it has gone. I have, however, become unstuck at Chapter 6. The book explains how to create an application that uses some simple CRUD with user and role data, and uses authentication to prevent users updating other user's data. I have a working application that allows one to create and read user data, but I can't figure out how to apply the authentication. The book says: When using the Authentication plug-in, as we showed in Chapter 3... I've gone back to Chapter 3 and followed the steps, but I'm not sure where I am supposed to put the $c-authenticate. If I place it in DBAuthTest::Controller::Root in a subroutine called auto, every page on the site needs me to log in, but no matter what I put in the username and password fields it says that the data is invalid. As such I have no idea where I have gone wrong, after Googling I can't find similar problems, or people who have had similar problems or implemented a similar system in a similar way. I have looked at the source code provided on the publisher's site, but it doesn't include code for the whole chapter, and indeed seems to stop given code a page or two previous to where I am now... I have uploaded a copy of my application to http://hashbang0.com/personal/DBAuthTest.tar.bz2 (~46K) which I hope help demonstrate where I am currently. Many thanks for your time, I appreciate any help you can give, Ben Lavery ___ 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] Authentication not working as expected
'); # Return 0 to cancel 'post-auto' processing and prevent use of application return 0; } # User found, so return 1 to continue with processing after this 'auto' return 1; } sub index :Path :Args(0) { my ( $self, $c ) = @_; $c-stash(template = \'Welcome please a href=/loginlogin/a'); #or i could use: template = 'index.tt2', and create that file inside myapp/root } sub hidden_page :Path('/hidden_page') :Args(0) { my ( $self, $c ) = @_; $c-stash( template = \'CONTEÚDO ESCONDIDO' ); } sub login : Path('/login') : Args(0) { my ( $self, $c ) = @_; my $form = HTML::FormHandler-new({ field_list = [ username = { type = 'Text', label = 'Login', required = 1, required_message = 'Campo Requerido', }, password = { type = 'Password', label = 'Password', required = 1, required_message = 'Campo Requerido', }, submit = { type = 'Submit', value = 'Login', }, ], }); $c-stash( template = \$form-render); # Get the username and password from form my $username = $c-request-params-{username} || undef; my $password = $c-request-params-{password} || undef; # If the username and password values were found in form if ( defined($username) defined($password) ) { # Attempt to log the user in if ( $c-authenticate( { username = $username, password = $password } ) ) { $c-forward('hidden_page'); return; } else { # Set an error message $c-stash-{error_msg} = Login desconhecido. Verifique seu login e senha e tente novamente. ; } } # If either of above don't work out, send to the login page $c-detach('index') if ($c-user_exists); } sub logout : Path('/logout') : Args(0) { my ( $self, $c ) = @_; # Clear the user's state $c-logout; # Send the user to the starting point $c-response-redirect( $c-uri_for('/') ); } 12. now create your schema: script/example_catalyst_auth_create.pl model DBICSchemamodel DBIC::Schema Example::Catalyst::Auth::DBSchema create=static dbi:Pg:dbname=test_auth dblogin password 13. add many_to_many relationships to model User vim lib/Example/Catalyst/Auth/DBSchema/Result/User.pm 14. insert before make_immutable or 1 __PACKAGE__-many_to_many('roles', 'users_to_roles' = 'role'); 15. add many_to_many relationships to model Role vim lib/Example/Catalyst/Auth/DBSchema/Result/Role.pm 14. insert before make_immutable or 1 __PACKAGE__-many_to_many('users', 'users_to_roles' = 'user'); att, Hernan On Tue, Jan 11, 2011 at 3:18 PM, Mike Raynham catal...@mikeraynham.co.ukwrote: On 11/01/11 16:09, Ben Lavery wrote: Dear all, After installing Catalyst on an OpenIndiana virtual machine, I've been working through the Definitive Guide to Catalyst for the last few weeks and have been impressed with how smoothly most of it has gone. I have, however, become unstuck at Chapter 6. The book explains how to create an application that uses some simple CRUD with user and role data, and uses authentication to prevent users updating other user's data. I have a working application that allows one to create and read user data, but I can't figure out how to apply the authentication. The book says: When using the Authentication plug-in, as we showed in Chapter 3... I've gone back to Chapter 3 and followed the steps, but I'm not sure where I am supposed to put the $c-authenticate. If I place it in DBAuthTest::Controller::Root in a subroutine called auto, every page on the site needs me to log in, but no matter what I put in the username and password fields it says that the data is invalid. As such I have no idea where I have gone wrong, after Googling I can't find similar problems, or people who have had similar problems or implemented a similar system in a similar way. I have looked at the source code provided on the publisher's site, but it doesn't include code for the whole chapter, and indeed seems to stop given code a page or two previous to where I am now... I have uploaded a copy of my application to http://hashbang0.com/personal/DBAuthTest.tar.bz2 (~46K) which I hope help demonstrate where I am currently. Many thanks for your time, I appreciate any help you can give, Ben Lavery The authentication section of the online tutorial, as suggested by Hernan Lopes, is definitely worth reading. However, what follows may get you started. The following approach doesn't deal with roles or permission levels - it just tests if a user
Re: [Catalyst] Roles and Permissions -- Controller vs View
try something like this... which is basically 1. verify the roles on the controller 2. build a data structure of displayed content based on roles and set to stash 3. let the view processes whats in the stash without checking for any roles in the end its 1 controler and 1 view Controller: sub render_buttons{ my $buttons = { managers = { (if $user-is_mgr) ? ( edit = 'manager_btn_edit.tt2' ) : (), //OR something like //edit = { tt_template = 'manager_btn_edit.tt2', href = '/foo/edit', }, }, everyone = { view = 'manager_btn_view.tt2', }, } $c-stash(buttons = $buttons); } View: [% PROCESS $buttons.everyone.view %] [% PROCESS $buttons.managers.edit %] On Tue, Dec 28, 2010 at 3:35 PM, will trillich will.trill...@serensoft.comwrote: In our web app we have lots of features that are predicated upon the user's role. For example, a show link is available to everyone, but an edit link is only available to managers. Is there a best-practices approach for dealing with this? There are two places where user-role is significant -- controller and view. In the controller we use chaining to bounce a user out of an edit method if they don't have the right role. And in the view we use lots of [% IF c.user.is_mgr %] logic to determine whether or not to display the links. (Using user-friendly urls like /thingy/27/edit makes the URL easy to guess, so checking inside the controller is a good idea.) So right now we're checking for the same thing in the view that we're checking for in the controller. The more features that get added that require role-checking, the more hairy this gets. Is there a way to get all this rolled up into one place? Or at least make the view a bit more elegant? -- Failure is not important. How you overcome it, is. -- Nick Vujicic ___ 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] receiving form-elements in sequence...?
Thats not how you do it. you should use javascript to create a hash, or array of IDs and positions and then post that to your server. On Mon, Dec 27, 2010 at 2:51 PM, will trillich will.trill...@serensoft.comwrote: Quick question: how do we determine the sequence of submitted form elements? Background: we've got several data-rows that we're going to let the user reorder via Javascript drag-and-drop. Looking in $c-req-params, being a hash, gives us all elements, but no clue as to which item is first, which is next, which is last. So in case the opening line above isn't quite the right question, how do we submit a new sequence of rows via $c-req? This is probably a simple one, but we haven't found the $c-req-[sequenced-form-items] method yet (gotta be available via Catalyst::Request, I hope). Pointers gladly welcomed. Thanks! -- Failure is not important. How you overcome it, is. -- Nick Vujicic ___ 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] DBIx::Class - table relations and joins
Thats DBIx::Class question and not a catalyst question. here are dbix class docs: http://search.cpan.org/~frew/DBIx-Class-0.08124/everything you need is there. Take a look at joining at the bottom of the page. --Hernan On Tue, Dec 14, 2010 at 1:27 PM, Vivek Chhikara vi...@chhikara.org wrote: I am new to catalyst and need guidance in fetching some data from my mysql db. I want to know how can I write below queries(12) Here is dummy table structure I am using. - table1 === qid sid status name __PACKAGE__-set_primary_key(qid); __PACKAGE__-belongs_to(queq_dump, 'MYAPP::Schema::Result::Table2, {qid = 'qid'}); - table2 pid eid qid name primary_key == pid+qid+eid - QUERY 1 === select A.qid, A.name, A.name from table1 A, table2 B where A.qid = B.qid and A.sid = 1 and B.pid != 2 QUERY 2 === select A.qid, A.name, A.name from table1 A, table2 B where A.qid = B.qid and B.eid = (select min(eid) from table2 where table2.status = 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/ ___ 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] FormHandler -- pro or con?
Of course you can load a fields config from a file, db or wathever here is a simple form example of formhandler with perl catalyst: in your User.pm controller: use HTML::FormHandler; sub fields { return [ display0 = { type = 'Display', html = 'h1Personal data/h1', }, name = { type = 'Text', label= 'Name', required = 0, required_message = 'required', css_class= 'form50', }, submit = { type = 'Submit', css_class = 'form100 clear', value = 'submit', }, ]; } sub myform :Path('/myform') :Args(0) { my ( $self, $c ) = @_; my $form = HTML::FormHandler-new( field_list = $self-fields); $c-res-body( $form-render ); } On 12/7/10, Octavian Rasnita orasn...@gmail.com wrote: From: Toby Corkindale t...@dryft.net On 1 December 2010 02:34, will trillich will.trill...@serensoft.com wrote: Anybody else *dissing* FormHandler? We've started developing based on FormHandler lately and haven't had troubles... yet? I'm running it, and have been very happy with it. It's nice that you can put all your common form elements into roles and then combine them. I'm familiar with Moose, so HFH's syntax came fairly naturally to me, but I guess it could be confusing to others? Performance is reasonable - and a lot faster compared to FormFu. Cheers, Toby Is there a way of making H::FH beeing more elegant? I mean, is there a way of doing something to not need using Perl code for creating the forms, but only using some configuration files like in H::FF's case? 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/ ___ 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] Transferring control via root/auto
your redirect will make auto be executed again and redirecting again to loginedit On Tue, Dec 7, 2010 at 1:53 PM, Thompson r...@matsch.com wrote: Here is my problem, If a user logs in for the 1st time I want to force them to change their password. I have a specific action in my Users controller to handle that. What I'm having a problem with is (redirecting or forwarding or detaching - i've tried them all) from the root/auto function to my specific controller function. I either get an internal server error or page isn't redirecting properly, depending what i use. I've put my logic in the root/auto because regardless of the request changing their password is mandatory. Here is my current root/auto using redirect. sub auto : Private { my ($self, $c) = @_; if ($c-user_exists() $c-check_any_user_role('User') $c-user-changePassword ) { $c-res-redirect($c-uri_for($c-controller('Users')-action_for('loginedit'), [$c-user-id] )); $c-detach(); } return 1; } Any help would be appreciated. Rob T ___ 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] Which Form Validation Libs?
formhandler and formbuilder have some syntax similarities. shouldnt be hard to move from one to the other. Just in case you are curiousm, here are some examples: FormBuilder: http://www.formbuilder.org/tutor/index.pl?c=1s=5 FormHandler: http://search.cpan.org/~gshank/HTML-FormHandler-0.32005/lib/HTML/FormHandler/Manual/Catalyst.pod --Hernan On Tue, Nov 30, 2010 at 9:26 AM, Shlomi Fish shlo...@iglu.org.il wrote: On Tuesday 30 November 2010 11:31:56 David Schmidt wrote: another great module which from my perception is used the most lately is HTML::FormHandler http://search.cpan.org/~gshank/HTML-FormHandler-0.32005/http://search.cpan.org/%7Egshank/HTML-FormHandler-0.32005/ I can recommend *against* HTML-FormHandler. For my day job's Perl and Catalyst project, we initially decided to go with HTML-FormHandler, only to discover it was buggy, quirky and had severe memory leaks. We ended up doing many workarounds and recently made a transition from it to HTML-FormFu, which while by no means perfect, is much saner. My co-worker nothingmuch who has done many of the workarounds can provide further comments on it. Recently I had to over-ride a role in the login form (for which we need to use HTML-FormHandler due to CatalystX::SimpleLogin) that will accept an empty string as the 'action=' attribute because it only placed true values of the attribute there, which ruled out empty strings. But I recall many other fun hours debugging HTML-FormHandler. Stay away if you can. Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ What does Zionism mean? - http://shlom.in/def-zionism rindolf She's a hot chick. But she smokes. go|dfish She can smoke as long as she's smokin'. Please reply to list if it's a mailing list post - http://shlom.in/reply . ___ 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] Re: superuser switch-user session function?
Indeed, i think it should login as a new user not changing the actual session. maybe something like: admin clicks login as joeuseropen a new browser window as adminverify its admin and re-login as a new user. register on session user is admin so he can log back in. Then add button terminate session, close window and logout and log back in with adminfoologin on parent.window --Hernan On Tue, Nov 30, 2010 at 1:01 PM, Peter Karman pe...@peknet.com wrote: will trillich wrote on 11/29/2010 05:37 PM: Aha! It looks like a sneaky, evil, wrong, mean, horrid way to switch-user in the middle of a session is to $c-session-{__user}{id} = $new_id_here; # since id = PK But that's undoubtedly bad form of the worst kind. What's the canonical non-sneaky above-board friendly golden way to do this? I don't know that there is a canonical way. This is Perl. As I mentioned in my reply to this thread in July[0], one way is to login as the new user and store the original username in the new user's session. That way the app knows that the new user is allowed to revert to the original user, but otherwise the app treats the current session just as it would if the new user had logged in normally. [0] http://www.mail-archive.com/catalyst@lists.scsys.co.uk/msg09968.html -- Peter Karman . http://peknet.com/ . pe...@peknet.com ___ 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] FormHandler -- pro or con?
Formhandler works like a charm, does many useful checks and you wont have any trouble with it. i have been using it for a while without any problem. As for the memory leaks, it can affect you when resources are limited or when you are running out of ram. (no idea if there are any leaks on formhandler) If you decide to change, formbuilder is the closest option to formhandler. --Hernan On Tue, Nov 30, 2010 at 1:34 PM, will trillich will.trill...@serensoft.comwrote: Anybody else *dissing* FormHandler? We've started developing based on FormHandler lately and haven't had troubles... yet? On Tue, Nov 30, 2010 at 5:26 AM, Shlomi Fish shlo...@iglu.org.il wrote: I can recommend *against* HTML-FormHandler. For my day job's Perl and Catalyst project, we initially decided to go with HTML-FormHandler, only to discover it was buggy, quirky and had severe memory leaks. We ended up doing many workarounds and recently made a transition from it to HTML-FormFu, which while by no means perfect, is much saner. My co-worker nothingmuch who has done many of the workarounds can provide further comments on it. Recently I had to over-ride a role in the login form (for which we need to use HTML-FormHandler due to CatalystX::SimpleLogin) that will accept an empty string as the 'action=' attribute because it only placed true values of the attribute there, which ruled out empty strings. But I recall many other fun hours debugging HTML-FormHandler. Stay away if you can. Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ What does Zionism mean? - http://shlom.in/def-zionism rindolf She's a hot chick. But she smokes. go|dfish She can smoke as long as she's smokin'. Please reply to list if it's a mailing list post - http://shlom.in/reply. ___ 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/ -- Failure is not important. How you overcome it, is. -- Nick Vujicic ___ 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] Overriding Catalyst::View::TT WRAPPER
I personally think that [% IF no_wrapper %] etc is not clean enough so i would create a new view and call it View::NoWrapper then you can set $c-stash( current_view = 'NoWrapper', template = 'src/mypage.html', ); and then, you will need to set a wrapper.tt. But you can choose to leave it with [% content %] only, or add some html headers.. or whatever you need. --Hernan On Mon, Nov 29, 2010 at 11:27 PM, Sam Kaufman samuel.c.kauf...@gmail.comwrote: I've found the easiest way is to have some logic in your wrapper: something like this: [% IF no_wrapper; content; ELSE; content WRAPPER site/html + site/layout; END; %] so $c-stash(no_wrapper = 1) and it won't be wrapped. -Sam On Mon, Nov 29, 2010 at 8:16 PM, Mesdaq, Ali ames...@websense.com wrote: Hey Everyone, Got a question about how I can override my application's TT wrapper. The closest thing I found was http://search.cpan.org/~abraxxa/Catalyst-View-TT-0.36/lib/Catalyst/View/TT.pm#CONFIGURATIONhttp://search.cpan.org/%7Eabraxxa/Catalyst-View-TT-0.36/lib/Catalyst/View/TT.pm#CONFIGURATION. But what I am trying to do is basically have the wrapper turned off for a specific public method where I will create a new TT file that I want used without it being wrapped. Thanks, ALI MESDAQ Sr. Security Researcher WEBSENSE, INC. ph: +1.858.320.9466 fax: +1.858.784.4466 www.websense.com Websense TRITON™ For Essential Information Protection™ Web Security | Data Security | Email Security Protected by Websense Hosted Email Security -- www.websense.com ___ 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/ ___ 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] Catalyst::Authentication::Credential::OAuth
To integrate facebook login onto your site, Have you tried Catalyst::Authentication::Credential::FBConnect ? It works and lets you access users facebook id from $c-user-session_uid as documented 1. You need to register under http://developers.facebook.com and register a new application. You must include the exact address you will use on the machine for it to work ie. http://localhost:3000/; 2. you need to configure include these onto your myapp.conf Plugin::Authentication default_realm facebook realms facebook credential class FBConnect api_key my_app_key secret my_app_secret app_namemy_app_name /credential /facebook /realms /Plugin::Authentication 3. you need a piece of javascript from facebook to create login button (replace with your appId/fb_app_id as below): sub login_facebook : Path('/loginfacebook') : Args(0) { my ( $self, $c ) = @_; my $fb_app_id = ''; $c-stash( template = \FBLOGIN pfb:login-button autologoutlink=true/fb:login-button/p pfb:like/fb:like/p div id=fb-root/div script window.fbAsyncInit = function() { FB.init({appId: '$fb_app_id', status: true, cookie: true, xfbml: true}); FB.Event.subscribe('auth.sessionChange', function(response) { if (response.session) { // A user has logged in, and a new cookie has been saved window.location=/fblogin; //redirects user to our facebook login so we can validate him and get his user id. } else { // The user has logged out, and the cookie has been cleared window.location=/; } }); }; (function() { var e = document.createElement('script'); e.type = 'text/javascript'; e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; e.async = true; document.getElementById('fb-root').appendChild(e); }()); /script FBLOGIN ); } 4. then , i created an action /fblogin to register facebook credentials internally when user logs in (see in the js) sub fbauthenticate :Path('/fblogin') :Args(0) { my ($self, $c) = @_; if ($c-authenticate()) { $c-log-debug($c-user-session_uid); $c-log-debug($c-user-session_key); $c-log-debug($c-user-session_expires); } $c-res-redirect('/'); } So remember, register at the http://developer.facebook.com with the same url your application will use, include ports if its not 80 --Hernan On Tue, Nov 23, 2010 at 8:32 PM, Blaine Everingham grandmasterbla...@hotmail.com wrote: Hi, I was wondering if anyone has a simple example of using OAuth with facebook to allow user login, to your software. I keep getting the error oauth_parameters_absent:scope, but Catalyst::Authentication::Credential::OAuth document does not outline where you are supposed to enter this. Thanks, Blaine ___ 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] Re: Trying out FormHandler, running into maketext error
will trilich, are you using widget type submit ? try to replace with type = 'Submit' Hernan Lopes On Mon, Nov 22, 2010 at 1:38 AM, John Anderson geneh...@genehack.orgwrote: On Nov 21, 2010, at 10:26 PM, will trillich wrote: Pooh. Still no luck. When we try a more more Moose-y approach, we do get updated database records (stuffing the URL with arguments to affect a form-submit) but still can't render, with the same error as before: Have you looked at the docs for HTML::FormHandler::TraitFor::I18N? Based on that, you may want to see if you have something in $ENV{LANGUAGE_HANDLE} or try passing in a language handle to your form constructor -- or may try push_errors instead of add_errors, as that documentation suggests. j. ___ 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] Re: Trying out FormHandler, running into maketext error
will trillich, that error happens when i use has_field 'submit' = ( widget = 'submit' ) can you test your form with this instead: has_field 'submit' = (type = 'Submit', label = 'Submit', value='Submit', required = 0, ) i bet your error will go away On Mon, Nov 22, 2010 at 12:19 PM, will trillich will.trill...@serensoft.com wrote: Our form-class includes has_field 'submit' = ( widget = 'submit' ) Do you mean type='submit' instead of widget='submit'? Interesting that you'd think of this as a suspect. What's the rationale? On Mon, Nov 22, 2010 at 9:16 AM, Hernan Lopes hernanlo...@gmail.comwrote: will trilich, are you using widget type submit ? try to replace with type = 'Submit' Hernan Lopes On Mon, Nov 22, 2010 at 1:38 AM, John Anderson geneh...@genehack.orgwrote: On Nov 21, 2010, at 10:26 PM, will trillich wrote: Pooh. Still no luck. When we try a more more Moose-y approach, we do get updated database records (stuffing the URL with arguments to affect a form-submit) but still can't render, with the same error as before: Have you looked at the docs for HTML::FormHandler::TraitFor::I18N? Based on that, you may want to see if you have something in $ENV{LANGUAGE_HANDLE} or try passing in a language handle to your form constructor -- or may try push_errors instead of add_errors, as that documentation suggests. j. ___ 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/ -- Failure is not important. How you overcome it, is. -- Nick Vujicic ___ 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] Trouble using Catalyst::Controller::FormBuilder
indeed, again: here is a simple form example of formhandler with perl catalyst: in your User.pm controller: use HTML::FormHandler; sub fields { return [ display0 = { type = 'Display', html = 'h1Personal data/h1', }, name = { type = 'Text', label= 'Name', required = 0, required_message = 'required', css_class= 'form50', }, submit = { type = 'Submit', css_class = 'form100 clear', value = 'submit', }, ]; } sub myform :Path('/myform') :Args(0) { my ( $self, $c ) = @_; my $form = HTML::FormHandler-new( field_list = $self-fields); $c-res-body( $form-render ); } And, start your server, access your http://localhost:3000/myform see more on the catalyst manual and formhandler manual -Hernan On Wed, Nov 10, 2010 at 12:11 PM, David Schmidt davew...@gmx.at wrote: On Wed, Nov 10, 2010 at 2:37 PM, Eric Berg eb...@bergbrains.com wrote: I'm trying to get Catalyst::Controller::FormBuilder to work, but am running into some problems. Per the docs, the config should be like this: use base 'Catalyst::Controller::FormBuilder'; But my class is from a brand-new Catalyst install, so it's using extends like this: BEGIN {extends 'Catalyst::Controller'; } So I changed it to this: BEGIN {extends 'Catalyst::Controller::FormBuilder'; } And now I'm seeing this error: Couldn't load class (GLR) because: Couldn't instantiate component GLR::Controller::Payment, The 'add_attribute' method cannot be called on an immutable instance at /usr/local/lib/perl/5.10.1/Class/MOP/Class/Immutable/Trait.pm line 32 Can anyone steer me in the right direction to get this working? BTW, I'm a long-time Perl guy, but this is my first Catalyst app. Thanks! Eric ___ 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/ People seem to move towards HTML::FormHandler these days. http://search.cpan.org/~gshank/HTML-FormHandler-0.32005/http://search.cpan.org/%7Egshank/HTML-FormHandler-0.32005/ ___ 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] error handling (Chain where ajax and non-ajax actionschain off)
Octavian, Its just an action with attributes predefie ie: (in your controller): __PACKAGE__-config( action = { myaction = { Chained = 'base', PathPart = q{myaction}, Args = 0, }, }); sub myaction :Action { my ( $self, $c,) = @_; .. } --Hernan 2010/11/10 Octavian Rasnita orasn...@gmail.com Hi, From: Eden Cardim edencar...@gmail.com in Controller::Artist: sub error_404 :Action { Can I find more information about the :Action dispatch type? Is it just a replacement for :Private? Or it is something different? 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/ ___ 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] Accessing DB from external model
Mike, also, if you havent already, take a look on Catalyst::Tutorial , in my opinion its by far the best documentation to begin with catalyst. http://search.cpan.org/~zarquon/Catalyst-Manual-5.8005/lib/Catalyst/Manual/Tutorial/01_Intro.pod On 11/5/10, Mike Raynham catal...@mikeraynham.co.uk wrote: On 05/11/10 10:10, Octavian Rasnita wrote: From: Mike Raynham catal...@mikeraynham.co.uk Hi, I am fairly new to all things Perl and Catalyst, and would like to know if what I am attempting to do is correct. I've recently finished reading 'The Definitive Guide to Catalyst', which has been very helpful, but I am still a little confused about separating my business logic from my Catalyst application, and accessing the database connection from my non-Catalyst application. At the moment, I have my external class in the lib/MyApp directory. It uses the connection info found in MyApp::Model::DB, like so: --- # lib/MyApp/MyExternalClass.pm MyApp::MyExternalClass use MyApp::Model::DB; use MyApp::Schema; my $connect_info = MyApp::Model::DB-config-{connect_info}; my $schema = MyApp::Schema-connect( $connect_info ); # Do stuff with $schema... --- That works, and I can connect to the database. However, I have searched this mailing list, and found this: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/msg00817.html Here, the connection information is moved from MyApp::Model::DB to MyApp::DB, and then Catalyst::Model::Adaptor is used to glue MyApp::Model::DB to MyApp::DB. Is it a good idea? MyApp::Model::DB appears to be part of the Catalyst application, so if I want to access the database from an external model, it makes sense to me to move the connection code outside of the Catalyst application. Regards, Mike The best idea would be to put the connection information in the application's config file like in the example below. (This example uses a Perl data structure, but you can use any configuration type accepted by Config::Any). 'Model::DB' = { schema_class = 'MyApp::Schema', connect_info = { dsn = 'dbi:Oracle:host=10.10.10.10;port=1521;sid=ora8', user = 'user', password = password, #name_sep = '.', LongReadLen = 100*1024*1024, LongTruncOk = 1, on_connect_call = 'datetime_setup', on_connect_do = [ alter session set NLS_COMP='LINGUISTIC', alter session set NLS_SORT='BINARY_AI', ], }, }, The model will access the connection information directly if it is defined in the config file, and you can use the data from this config file in any other external program. You can use the module Config::JFDI for using the Catalyst config file easier. Octavian Hi, Thanks for the speedy response. When you put it like like, it all seems so simple and obvious :-) Config::JFDI looks handy - I'll take a look at that. Regards, Mike ___ 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] Catalyst with HTML::FormHandler
here is a simple form example of formhandler with perl catalyst: in your User.pm controller: use HTML::FormHandler; sub fields { return [ display0 = { type = 'Display', html = 'h1Personal data/h1', }, name = { type = 'Text', label= 'Name', required = 0, required_message = 'required', css_class= 'form50', }, submit = { type = 'Submit', css_class = 'form100 clear', value = 'submit', }, ]; } sub myform :Path('/myform') :Args(0) { my ( $self, $c ) = @_; my $form = HTML::FormHandler-new( field_list = $self-fields); $c-res-body( $form-render ); } On 11/5/10, Blaine Everingham grandmasterbla...@hotmail.com wrote: Sorry the error message is Error: Can't locate MyApp/UserInterface/Form/User.pm in @INC (@INC contains: C:/strawberry/perl/site/lib C:/strawberry/perl/vendor/lib C:/strawberry/perl/lib .) Resource: User.pm Path: /MyApp-Software/lib/MyApp/UserInterface/Controller/Admin Location: line 5 Line 5 of /MyApp-Software/lib/MyApp/UserInterface/Controller/Admin/User.pm is: use MyApp::UserInterface::Form::User; Date: Fri, 5 Nov 2010 14:40:37 -0400 From: st...@matsch.com To: catalyst@lists.scsys.co.uk Subject: Re: [Catalyst] Catalyst with HTML::FormHandler The actual error message would help... On 11/5/2010 2:33 PM, Blaine Everingham wrote: I'm new to Catalyst and and trying to build a simple form. In the Catalyst controller MyApp/UserInterface/Controller/Admin/Users.pm I've added an 'use MyApp::UserInterface::Form::User', however it can not find this file. Meaning that it's not in the INC path. Obviously I could push this directory on to the INC stack, but none of the examples that I've seen have had to do this. What is the proper way to go about this? Below is an example of the directory structure. MyApp/UserInterface/Controller MyApp/UserInterface/Controller/Admin MyApp/UserInterface/Controller/Admin/Users.pm MyApp/UserInterface/Form MyApp/UserInterface/Form/User.pm MyApp/UserInterface/Model MyApp/UserInterface/Schema MyApp/UserInterface/View ___ 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/ ___ 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] C::P::Redirect
Hey Jon, In perl catalyst apps you can set a proper response status for your redirect as simple as: ie. $c-res-redirect( '/foo/bar.html', 301 ); Read more at: http://search.cpan.org/~bobtfish/Catalyst-Runtime-5.80029/lib/Catalyst/Response.pm#$res-%3Eredirect%28_$url,_$status_%29 -Hernan On 11/3/10, Jon jonfda...@wetxt.com wrote: Hello, I'm using C::P::Redirect, which redirect to pages with an HTTP 302 status code. Does anyone have an elegant way to set these redirects as 301s? The 302 is *ok*, but I would prefer the 301. Thanks! - Jon ___ 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] best practices for handling forms?
perl Catalyst Forms with Formhandler and Thickbox: You know you dont always need a template.tt2 file... this is useful with ajax (especially with thickbox) so you can pass a scalar as template, so you end up with: $c-stash( template = $form-render, current_view = 'Ajax', ); 1. You could create an Ajax view. 2. Or you can set body content directly. This way you skip creating TT files for forms and render them directly into the $c-res-body or $c-stash( template = \'foo baz') If you use something like thickbox, you can render any $form directly into a modal. Its very handy! For example: __PACKAGE__-config( action = { edit = { Chained = 'base', Args = 1, }, }, ); sub base : Chained('/') PathPart('foobar') CaptureArgs(0) {} sub edit :Action { my ( $self, $c, $foobar_id ) = @_; my $form = HTML::FormHandler-new( schema = 'DBSchema::Foo', params = $c-req-params, field_list = $self-form_fields($c), ); if( $c-req-method eq 'POST' $form-process() ) { ... } else { #OPTION 1 (create an Ajax View and create a wrapper for it. Then render the form into stash template var): $c-stash( template = \$form-render, current_view = 'Ajax', ); #OPTION 2 (set your content type and charset and render the form into the body, needs no view/TT files): $c-res-content_type('text/html charset=utf-8'); $c-res-body($form-render); } } sub form_fields { return [ field_one = { type = 'Text', label = '...', css_class = '...', maxlength = 160, required = 1, required_message = 'Required Text', }, submit = { type = 'Submit', value = 'Save', css_class = '...', }, ]; } and DRY on edit update unless necessary... 1. If there is an argument its update? 2. Else, when it has no args then its edit/new ? use your foregin_key_id and $form('foregin_key_id')-value = '...' to set it , then formhandler will know whether to update or create a new entry. Take care, hernan On Mon, Sep 20, 2010 at 6:48 PM, E R pc88m...@gmail.com wrote: 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] best practices for handling forms?
correction: you can pass a reference to $c-stash(template = \'foobas'), so you end up with: $c-stash( template = \$form-render, current_view = 'Ajax', ); On Mon, Sep 20, 2010 at 8:09 PM, Hernan Lopes hernanlo...@gmail.com wrote: perl Catalyst Forms with Formhandler and Thickbox: You know you dont always need a template.tt2 file... this is useful with ajax (especially with thickbox) so you can pass a scalar as template, so you end up with: $c-stash( template = $form-render, current_view = 'Ajax', ); 1. You could create an Ajax view. 2. Or you can set body content directly. This way you skip creating TT files for forms and render them directly into the $c-res-body or $c-stash( template = \'foo baz') If you use something like thickbox, you can render any $form directly into a modal. Its very handy! For example: __PACKAGE__-config( action = { edit = { Chained = 'base', Args = 1, }, }, ); sub base : Chained('/') PathPart('foobar') CaptureArgs(0) {} sub edit :Action { my ( $self, $c, $foobar_id ) = @_; my $form = HTML::FormHandler-new( schema = 'DBSchema::Foo', params = $c-req-params, field_list = $self-form_fields($c), ); if( $c-req-method eq 'POST' $form-process() ) { ... } else { #OPTION 1 (create an Ajax View and create a wrapper for it. Then render the form into stash template var): $c-stash( template = \$form-render, current_view = 'Ajax', ); #OPTION 2 (set your content type and charset and render the form into the body, needs no view/TT files): $c-res-content_type('text/html charset=utf-8'); $c-res-body($form-render); } } sub form_fields { return [ field_one = { type = 'Text', label = '...', css_class = '...', maxlength = 160, required = 1, required_message = 'Required Text', }, submit = { type = 'Submit', value = 'Save', css_class = '...', }, ]; } and DRY on edit update unless necessary... 1. If there is an argument its update? 2. Else, when it has no args then its edit/new ? use your foregin_key_id and $form('foregin_key_id')-value = '...' to set it , then formhandler will know whether to update or create a new entry. Take care, hernan On Mon, Sep 20, 2010 at 6:48 PM, E R pc88m...@gmail.com wrote: 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] best practices for handling forms?
Ohh, by the way, if you need to write html into the form, you can also do it without any TT view file. With Formhandler it is very simple, just use the field of type 'Display', for example: has_field 'display0' = ( type = 'Display', html = ' div class=clearh1 class=formtitleYour Personal Data/h1/div scriptfoo bar baz/script ' ); On Mon, Sep 20, 2010 at 8:09 PM, Hernan Lopes hernanlo...@gmail.com wrote: perl Catalyst Forms with Formhandler and Thickbox: You know you dont always need a template.tt2 file... this is useful with ajax (especially with thickbox) so you can pass a scalar as template, so you end up with: $c-stash( template = $form-render, current_view = 'Ajax', ); 1. You could create an Ajax view. 2. Or you can set body content directly. This way you skip creating TT files for forms and render them directly into the $c-res-body or $c-stash( template = \'foo baz') If you use something like thickbox, you can render any $form directly into a modal. Its very handy! For example: __PACKAGE__-config( action = { edit = { Chained = 'base', Args = 1, }, }, ); sub base : Chained('/') PathPart('foobar') CaptureArgs(0) {} sub edit :Action { my ( $self, $c, $foobar_id ) = @_; my $form = HTML::FormHandler-new( schema = 'DBSchema::Foo', params = $c-req-params, field_list = $self-form_fields($c), ); if( $c-req-method eq 'POST' $form-process() ) { ... } else { #OPTION 1 (create an Ajax View and create a wrapper for it. Then render the form into stash template var): $c-stash( template = \$form-render, current_view = 'Ajax', ); #OPTION 2 (set your content type and charset and render the form into the body, needs no view/TT files): $c-res-content_type('text/html charset=utf-8'); $c-res-body($form-render); } } sub form_fields { return [ field_one = { type = 'Text', label = '...', css_class = '...', maxlength = 160, required = 1, required_message = 'Required Text', }, submit = { type = 'Submit', value = 'Save', css_class = '...', }, ]; } and DRY on edit update unless necessary... 1. If there is an argument its update? 2. Else, when it has no args then its edit/new ? use your foregin_key_id and $form('foregin_key_id')-value = '...' to set it , then formhandler will know whether to update or create a new entry. Take care, hernan On Mon, Sep 20, 2010 at 6:48 PM, E R pc88m...@gmail.com wrote: 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