Model - Encapsulated in *.pm modules.Viewer - HTML::Template files (and viewer related *.pm files e.g. Site::Components) Controller - The CGIApp framework and instance scripts (*.cgi) - hooks like cgiapp_prerun/postrun allow you to extend the controller
The controller is the CGIApp framework which processes and responds to events by instantiating the proper model and viewer modules. In my app I customize the controller, specifically the CGIApp::cgiapp_postrun hook so that it knows how to respond to text/html and text/plain content types. For text/html content types, it calls our Site::Comps::header and Site::Comps::footer to provide header and footer to outgoing content. The header and footer routines are themselves driven by HTML::Template but with some parameters.
-Carlos Rob Kinyon wrote:
Rhesa already answered your immediate question. I'm going to give you some advice in terms of why what you're doing isn't the best. In general, headers and footers should be managed by the templating system you're using. For example, I use Template Toolkit (TT) and it has the [% INCLUDE %] directive. HTML::Template has <TMPL_INCLUDE> and the others have similar directives. So, why should you do this? It all boils down to MVC - Model vs. View vs. Controller. Read http://en.wikipedia.org/wiki/Model-view-controller then come back to the following. The content you present to the user should be managed by your view, not your controller. In this case,your CGI::Application subclass is your controller and TT (or H::T, Mason, Embperl, etc) is your view. (Your model would be your database, in most cases, plus whatever business objects you have.) In the cases where you have headers, your template should be doing the right thing. In the cases where you don't, your template should still be doing the right thing. Your controller doesn't want to care about headers and such. It's too much work for it. Rob On 8/5/06, Carlos Ramirez <suppressed> wrote:I'm using cgiapp_postrun() to add header and footer to outgoing content. I'm some runmodes, I'm setting the outgoing content type to 'text/plain' which means that I do not want to add header and footer content to the outgoing content. According to the docs, I should be able to use header_props() to get the outgoing headers so that I can do the following in my cgiapp_postrun subroutine: sub cgiapp_postrun { my $headers = $self->header_props; if ($headers->{'-type'} eq 'text/html') { ## add header/footer to $$output_ref } } Unfortunately the above doesn't work. Printing $headers gives the string: 1/8? Any help is appreciated. Thanks. -Carlos --------------------------------------------------------------------- Web Archive: http://www.mail-archive.com/suppressed/ http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2 To unsubscribe, e-mail: suppressed For additional commands, e-mail: suppressed--------------------------------------------------------------------- Web Archive: http://www.mail-archive.com/suppressed/ http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2 To unsubscribe, e-mail: suppressed For additional commands, e-mail: suppressed
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.