Re: how to pass data in internal redirects?
Take a look at PageKit (www.pagekit.org) - i use it and i like it. This is good Perl MVC framework. Anton. - Original Message - From: F. Xavier Noria [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, February 26, 2002 12:09 PM Subject: how to pass data in internal redirects? As an exercise studying mod_perl I am trying to see how could the MVC pattern be implemented. I've thought a possible approach would be to write the model using normal Perl classes, and controllers and views with Apache modules. I suppose that controllers would use internal redirects to call the views, is there a way to pass Perl data this way? For example, in the hangman game in O'Reilly's book a controller would load a session from the cookie, process user's guest, modify the state and redirect the request internally to the view. Ideally the view shouldn't read the data to display from the database again... could it be passed somehow by the first content handler? -- fxn
Re: how to pass data in internal redirects?
I suppose that controllers would use internal redirects to call the views, is there a way to pass Perl data this way? For the project I work on (a WWW-enabled PKI), we simply use CGI-encoded URLs. This way, we can do the controllers in Perl and the views in PHP, which is great for security (PHP is easier to sandbox) besides all other engineering advantages of MVC. There are quite a lot of Perl modules on CPAN that are convenient for turning structured Perl data into strings and back - please read the last two weeks' worth of list archives. -- Dominique QUATRAVAUX Ingénieur développeur sénior 01 44 42 00 35 IDEALX
Re: how to pass data in internal redirects?
Surprisingly I'm actually doing a proof of principle on the same theme. I'm developing a set of MVC classes which tie in with either tt2 or mason. I've got abstract Model, View and Controller classes. View can be subclassed into HTML, XML, whatever. I'm using normal classes at the moment, but if I get the go ahead, I'll be replacing these with some sort of pseudo-hash framework. My controller object would use the request object and the environment to determine a framework/templates and which overloaded Controller to generate. There is a generic events handler in the base class, which gets overloaded and which specialises the associated model object for the particular view subclass. I haven't looked at pre-reading the model and passing it into the first content handler, since in my case the model is likely to emerge from a large dataset. Once possible idea, floating in my head is to follow a principle adopted by the first company i was with, in that I could have a transitory daemon through which the data is called - this could possibly cache models requests, preventing second re-reads; also checking to see if the underlying model has changed, as per the original MVC paper. I guess that we can then reaccess the model at any point thereafter so that the the controller doesn't need to reaccess the data. Another point would be to cache the final generated templates, so that the view and controller override interaction with the model, where this data is already persistant. Got my basic framework in place - might make it my first cpan release if I can figure out how - want to share ideas? fiq On Tue, 26 Feb 2002, F. Xavier Noria wrote: As an exercise studying mod_perl I am trying to see how could the MVC pattern be implemented. I've thought a possible approach would be to write the model using normal Perl classes, and controllers and views with Apache modules. I suppose that controllers would use internal redirects to call the views, is there a way to pass Perl data this way? For example, in the hangman game in O'Reilly's book a controller would load a session from the cookie, process user's guest, modify the state and redirect the request internally to the view. Ideally the view shouldn't read the data to display from the database again... could it be passed somehow by the first content handler? -- fxn
Re: how to pass data in internal redirects?
I am also implementing a MVC pattern under mod_perl for an internal project at work. The app collects process data from our manufacturing processes and makes it available on the internal network. Here's a quick overview of the way I've done it. Model: The model consists of a backend database (MySQL) and a set of perl classes that interact with it. Each perl class encapsulates the data and methods associated with an entity in the application (like an Assembly, Company, etc). These classes know nothing of mod_perl. The only other thing worth mentioning is that each entity has a method called to_hash that creates a hash representation of itself that can be plugged directly into a HTML template (see View below). View: The view consists of a set of templates developed using the Template Toolkit. I strongly believe that templates should only display data, not generate it (no dbase calls). The controller creates the dynamic data, stuffs it into the template, and sends it back to the user. Controller: The core controller (an Apache handler) is responsible for authorization, gathering user input, performing any actions, and returning the appropriate view to the user.Whenever it performs an action, the controller needs to create and monkey with a rather large set of Entity classes. To simplify the code in the controller, I developed a set of Facade classes that are responsible for chunks of related actions. So, the controller instantiates a Facade and calls it's methods. The results are plugged directly into a template. Only Entity classes speak SQL. Only templates speak HTML. Everything else works with object methods or hashes. Whenever I need an internal redirect, I use CGI encoded URLs, just as Dom mentioned in his email. I don't know if this is the best design, but it works for this application. If you made it this far into the email, you might be interested in some sample code...let me know. If you have comments, please speak up. I'm the only developer on the project, so if I've gone off the deep end, I might not notice. Thanks, Tim On Tue, 26 Feb 2002, F. Xavier Noria wrote: As an exercise studying mod_perl I am trying to see how could the MVC pattern be implemented. I've thought a possible approach would be to write the model using normal Perl classes, and controllers and views with Apache modules. I suppose that controllers would use internal redirects to call the views, is there a way to pass Perl data this way? For example, in the hangman game in O'Reilly's book a controller would load a session from the cookie, process user's guest, modify the state and redirect the request internally to the view. Ideally the view shouldn't read the data to display from the database again... could it be passed somehow by the first content handler
Re: how to pass data in internal redirects?
$r-pnotes persist across internal_redirects, I believe. --Jon Robison Igor Sysoev wrote: On Tue, 26 Feb 2002, F. Xavier Noria wrote: I suppose that controllers would use internal redirects to call the views, is there a way to pass Perl data this way? For example, in the hangman game in O'Reilly's book a controller would load a session from the cookie, process user's guest, modify the state and redirect the request internally to the view. Ideally the view shouldn't read the data to display from the database again... could it be passed somehow by the first content handler? As far as I know r-notes() do not persist across internal redirections. You can try r-err_header_out() but clean up it in second handler before content output. Igor Sysoev
Re: how to pass data in internal redirects?
On Tue, 26 Feb 2002 08:32:37 -0500 Henigan, Timothy [EMAIL PROTECTED] wrote: : I don't know if this is the best design, but it works for this application. : If you made it this far into the email, you might be interested in some : sample code...let me know. If you have comments, please speak up. I'm the : only developer on the project, so if I've gone off the deep end, I might not : notice. Yeah, I am surely biased because in my company everything is done with Java where servlets act as controllers and forward requests to JSPs. Here people basicaly put data in the session object, for instance a User associated with the session. You have static data shared by everybody... it's a bit different as you probably know [*]. But I want to learn the multi-processes way of program with Apache and his related technologies. I believe, for instance, the Java people here at work do not completly realize they use the session object both to store state _and_ as a cache mechanism sometimes. You are not aware of what you are taking for granted until you play with other techniques. So, a controller could in principle perform a call to a template engine as yours does, conceptually there is no need to do that internal redirect. In fact, there is no need to have two different files if I take the pattern a bit further. For instance, I believe a page written in Embperl or PHP could begin with the controller code and once finished the view code could follow, that would be MVC too in my opinion. Well, just sharing thoughts. -- fxn [*] If needed, load balancing is done taking sessions into account.
Re: how to pass data in internal redirects?
F. Xavier Noria wrote: For example, in the hangman game in O'Reilly's book a controller would load a session from the cookie, process user's guest, modify the state and redirect the request internally to the view. It would probably be orders of magnitude faster to just call a template engine from your controller to render the view. - Perrin
Re: how to pass data in internal redirects?
At 16:06 26.02.02 +0100, you wrote: So, a controller could in principle perform a call to a template engine as yours does, conceptually there is no need to do that internal redirect. In fact, there is no need to have two different files if I take the pattern a bit further. For instance, I believe a page written in Embperl or PHP could begin with the controller code and once finished the view code could follow, that would be MVC too in my opinion. Ahem. No. If you do not separate, you do not separate. If you do not have separate files, you can not use the same view with different controllers. I am even using external redirects. This gives more stability against users pressing reload - they are only reloading views. See http://www.catstep.de/zobel/post2redirect.html for details. Joachim -- ... ein Geschlecht erfinderischer Zwerge, die fuer alles gemietet werden koennen.- Bertolt Brecht - Leben des Galilei
how to pass data in internal redirects?
As an exercise studying mod_perl I am trying to see how could the MVC pattern be implemented. I've thought a possible approach would be to write the model using normal Perl classes, and controllers and views with Apache modules. I suppose that controllers would use internal redirects to call the views, is there a way to pass Perl data this way? For example, in the hangman game in O'Reilly's book a controller would load a session from the cookie, process user's guest, modify the state and redirect the request internally to the view. Ideally the view shouldn't read the data to display from the database again... could it be passed somehow by the first content handler? -- fxn
Re: how to pass data in internal redirects?
On Tue, 26 Feb 2002, F. Xavier Noria wrote: I suppose that controllers would use internal redirects to call the views, is there a way to pass Perl data this way? For example, in the hangman game in O'Reilly's book a controller would load a session from the cookie, process user's guest, modify the state and redirect the request internally to the view. Ideally the view shouldn't read the data to display from the database again... could it be passed somehow by the first content handler? As far as I know r-notes() do not persist across internal redirections. You can try r-err_header_out() but clean up it in second handler before content output. Igor Sysoev