[cgiapp] Using ValidateRM etc...
Hi, I'm trying to expand my knowlege of C::A by finally incorporating some of the great sub modules into my applications.. Im writing a piece of software for booking swimming pool maintanence.. Here is my runmode that actually takes the data, validates it, and saves the data.. sub bookPool_do { my ($self) = @_; my $q = $self-query(); my $dbh = $self-param('dbh'); my ($results,$err_page) = $self-check_rm('poolcheck::bookPool', { required = [qw/fullname address primaryphone/], optional = [qw/secondaryphone pooltype coveroff accessby/], constraints = {zipcode = 'zip', primaryphone = 'american_phone', secondaryphone = 'american_phone', }, filters = ['trim'], msgs = {any_errors = 'err__', prefix='err_', }, }); return $err_page if $err_page; # if we got to this point, we have valid input, so we should insert it. my $bookid = _bookPool_do($q-param('bookid'), yada yada); if (!$bookid) { show error here ! } else { display success page. } } ValidateRM works great for validating the form, but I'm looking for an effecient way to display errors if the actual INSERT failed [ie _bookPool_do]. If that returns a 0 what i typically do is return the runmode that drew the page, display the error and fill in all the fields that the user had filled in. Since ValidateRM already re-fills in the form in case of an error I did not write the code i'd typically write to do that step. Does anyone have any elegant ideas that i could use without writing the by hand code to refill those entries ? I'm going to try HTML::Fillinform, unless ya'll have any better idea's. THanks. -- Jeff MacDonald http://www.halifaxbudolife.ca - Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [cgiapp] Using ValidateRM etc...
Jeff MacDonald wrote: Hi, I'm trying to expand my knowlege of C::A by finally incorporating some of the great sub modules into my applications.. It should make your life a little easier :) ValidateRM works great for validating the form, but I'm looking for an effecient way to display errors if the actual INSERT failed [ie _bookPool_do]. If that returns a 0 what i typically do is return the runmode that drew the page, display the error and fill in all the fields that the user had filled in. Since ValidateRM already re-fills in the form in case of an error I did not write the code i'd typically write to do that step. Does anyone have any elegant ideas that i could use without writing the by hand code to refill those entries ? I'm going to try HTML::Fillinform, unless ya'll have any better idea's. This is what ValidateRM uses internally and it's really easy to use so I'd go with it. I have run into a similar situation recently where I need to display the same sticky form with error messages that ValidateRM would have shown, but the decision to show such a form occurs well after the form validation. I did just what you're thinking of doing. I'm wondering if it might make it easier if ValidateRM exposes the method it uses to create the error page as part of it's public API? Would this make sense Mark? or is there a better way? -- Michael Peters Developer Plus Three, LP - Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [cgiapp] Using ValidateRM etc...
D'oh! Forgot that part! Also, you may need to put whatever flag in that anonymous hashref ('some_errors' in the docs) that triggers your template code that something is off. - Jason Michael Peters wrote: Jason Purdy wrote: if (!$bookid) { return $self-bookPool( { 'db_error' = 1, 'some_errors' = 1 } ); - Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [cgiapp] Using ValidateRM etc...
Thanks so much guys, here is what i ended up doing before seeing any replies *snipp* if (!$bookid) { my $fif = new HTML::FillInForm; my $output = $fif-fill(scalarref = \bookPool($self), fobject = $q); return $output; } else { return true; } Before I get lynched for having bookPool($self) instead of $self-bookPool is because I tend to keep everything like setup/pre_run/post_run et al in driver.pm, and all applaction stuff in another module. it's just my way of doing things, so i don't get 1 HUGE module file. Jeff. On Mon, 21 Mar 2005 13:56:55 -0500, Jason Purdy [EMAIL PROTECTED] wrote: D'oh! Forgot that part! Also, you may need to put whatever flag in that anonymous hashref ('some_errors' in the docs) that triggers your template code that something is off. - Jason Michael Peters wrote: Jason Purdy wrote: if (!$bookid) { return $self-bookPool( { 'db_error' = 1, 'some_errors' = 1 } ); -- Jeff MacDonald http://www.halifaxbudolife.ca - Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [cgiapp] Using ValidateRM etc...
On Mon, 21 Mar 2005 13:49:45 -0500, Michael Peters [EMAIL PROTECTED] wrote: This doesn't answer the question of how to duplicate the sticky form behavior of ValidateRM. He'd still have to use HTML::FillInForm. So something like: # if we got to this point, we have valid input, so we should insert it. my $bookid = _bookPool_do($q-param('bookid'), yada yada); if (!$bookid) { my $error_page = $self-bookPool( { 'db_error' = 1 } ); my $fif = HTML::FillInForm-new(); return $fif-fill( scalarref = \$error_page, fobject = $self-query ); } else { # return success } Since I use HTML::FillInForm so much, I usually turn the above into a helper function to simplify things: # if we got to this point, we have valid input, so we should insert it. my $bookid = _bookPool_do($q-param('bookid'), yada yada); if (!$bookid) { return $self-fillinform($self-bookPool( { 'db_error' = 1 } )); } else { # return success } sub fillinform { my $self = shift; my $html = shift; my $data = shift; my $fif = new HTML::FillInForm; if (ref $data eq 'HASH') { return $fif-fill(scalarref = $html, fdat = $data, @_); } elsif (ref $data) { return $fif-fill(scalarref = $html, fobject = $data, @_); } else { $self-query-delete('rm'); return $fif-fill(scalarref = $html, fobject = $self-query, @_); } } Just stick that function in your Base class. The function uses $self-query by default so you don't have to worry about passing in any data besides the actual HTML (but you can if you need to). The HTML needs to be passed in as a scalar ref, but I return that by default from all my runmodes. Cheers, Cees - Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [cgiapp] Using ValidateRM etc...
once again THANKS.. wow. great support. we went from having our own inhouse crap assed framework, to CGI:App. i'm delited ;) On Mon, 21 Mar 2005 14:30:36 -0500, Cees Hek [EMAIL PROTECTED] wrote: On Mon, 21 Mar 2005 13:49:45 -0500, Michael Peters [EMAIL PROTECTED] wrote: This doesn't answer the question of how to duplicate the sticky form behavior of ValidateRM. He'd still have to use HTML::FillInForm. So something like: # if we got to this point, we have valid input, so we should insert it. my $bookid = _bookPool_do($q-param('bookid'), yada yada); if (!$bookid) { my $error_page = $self-bookPool( { 'db_error' = 1 } ); my $fif = HTML::FillInForm-new(); return $fif-fill( scalarref = \$error_page, fobject = $self-query ); } else { # return success } Since I use HTML::FillInForm so much, I usually turn the above into a helper function to simplify things: # if we got to this point, we have valid input, so we should insert it. my $bookid = _bookPool_do($q-param('bookid'), yada yada); if (!$bookid) { return $self-fillinform($self-bookPool( { 'db_error' = 1 } )); } else { # return success } sub fillinform { my $self = shift; my $html = shift; my $data = shift; my $fif = new HTML::FillInForm; if (ref $data eq 'HASH') { return $fif-fill(scalarref = $html, fdat = $data, @_); } elsif (ref $data) { return $fif-fill(scalarref = $html, fobject = $data, @_); } else { $self-query-delete('rm'); return $fif-fill(scalarref = $html, fobject = $self-query, @_); } } Just stick that function in your Base class. The function uses $self-query by default so you don't have to worry about passing in any data besides the actual HTML (but you can if you need to). The HTML needs to be passed in as a scalar ref, but I return that by default from all my runmodes. Cheers, Cees - Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Jeff MacDonald http://www.halifaxbudolife.ca - Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[cgiapp] Is this the best way to use Cache::FileCache to cache output?
I'm working on a site that does a lot of mysql hits, and I want to cache pages for an hour. Here is a quick summary of how I'm doing it, in a base class for all CGI::Application modules. I will add some kind of package or method regex when I get to the pages that I don't want cached. Is this the best approach, or is there a better way? This might run on a shared host as CGIs for now, so I'm concerned about performance, but I'm trying to keep things relatively simple. In the examples below, $cache is created in the base class with: my $cache = new Cache::FileCache( { 'namespace' = 'mynamespace', 'default_expires_in' = '1 hour' } ); In cgiapp_prerun, check for cache and switch mode if found sub cgiapp_prerun { my ($self, $rm) = @_; my $cache_key = ref($self) . -$rm; $self-param(cache_key = $cache_key); my $output = $cache-get($cache_key); if ($output) { $self-param(cached_output = \$output); $self-prerun_mode('output_cached'); } } --- In cgiapp_postrun, cache output using the cache_key set above sub cgiapp_postrun { my $self = shift; my $output_ref = shift; my $rm = $self-get_current_runmode(); $cache-set($self-param('cache_key'), $$output_ref); } --- output_cached is in the base class too - sub output_cached { my $self = shift; warn output_cached called; return $self-param('cached_output'); } -- Barry Hoggard Tristan Media LLC w: www.tristanmedia.com yahoo/aim: hoggardb - Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[cgiapp] Global default for Templates
I'm looking at running one of my CGI apps under mod_perl using Apache::Registry to see how it performs. Apart from persistent DB connections, I guess the other benefit I'm looking to receive is the caching of templates. But I don't want to go through all of my modules adding the cache option to load_tmpl. Can I set this somehow in my base class's prerun or init methods? Dan - Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [cgiapp] Global default for Templates
Dan, I guess the other benefit I'm looking to receive is the caching of templates. But I don't want to go through all of my modules adding the cache option to load_tmpl. Can I set this somehow in my base class's prerun or init methods? You can override your base class's load_tmpl method (now inherited from CGI::App). Have a look at the source of CGI::App's load_tmpl , copy that code into your base class and just add the cache option. Thilo - Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: [cgiapp] Global default for Templates
Thanks very much, Thilo Dan -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Tuesday, 22 March 2005 16:51 To: [EMAIL PROTECTED] Cc: cgiapp@lists.erlbaum.net Subject: Re: [cgiapp] Global default for Templates Dan, I guess the other benefit I'm looking to receive is the caching of templates. But I don't want to go through all of my modules adding the cache option to load_tmpl. Can I set this somehow in my base class's prerun or init methods? You can override your base class's load_tmpl method (now inherited from CGI::App). Have a look at the source of CGI::App's load_tmpl , copy that code into your base class and just add the cache option. Thilo - Web Archive: http://www.mail-archive.com/cgiapp@lists.erlbaum.net/ http://marc.theaimsgroup.com/?l=cgiappr=1w=2 To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]