[Pas-dev] Proposal
Status: Beta
Brought to you by:
mortis
From: Kyle R . B. <mo...@vo...> - 2003-03-25 16:00:56
|
Some new PSP tags for advanced users. First, some background. In many of the sites I've done with Pas using PSP, I've written code that generates HTML because it's easier for me if the HTML is generated, but not really necessary to have it be dynamic at run-time. I.e. there is nothing in the generated HTML that relies on query specific data/parameters. If there were some kind of macro system, I would have used that in it's place. So that's what I'm proposing, a type of macro-system to pre-execute some of the code in the PSP. Sections marked in this way will be resolved during the compilation of the PSP code. There are several benefits, and side-effects to this. The new tags might be <%& %> and <%&= %> - I beleive an ampersand modifier might be available. These sections would then be executed as they were encountered in the page during compilaiton. The #line advantage that PSP has over some of the other templating systems should still hold by the way. Within these sections, $self could be an instance of the parent object of the PSP/page (because we're compiling the page, the object that represents the actual page wouldn't be availble until compilation was finished, so the closest thing we can offerr is the parent) - what ever is declared in the <%@ page extends = "xyz" %> tag(s). That instance would be constructed with an empty query object, but not have it's request_init method called. These code blocks could then be used to produce HTML (or even generate PSP code for that matter, which is one of the side-effects of implementing this) at compile time - so you can have a highly refactored presentation layer. In one applicaiton, we are using psp code to genreate some of our forms, since they all have the same look and feel, but only differ in the labels and names of the form elements, so instead of incurring the penalty of that code executing at run-time, we could use this type of system to resolve it at compile time: <%& my $formSpec = FormSpec->new; $formSpec->method('POST'); $formSpec->action('/pas/mySite/FormHandler'); $formSpec->addTextField( 'First Name', '-name' => 'firstName', '-size' => 20, ); $formSpec->addTextField( 'Last Name', '-name' => 'firstName', '-size' => 20, ); %> <FORM METHOD="<%&= $formSpec->method %>" ACTION="<%&= $formSpec->action %>"> <%& foreach my $elem ( $formSpec->formElements ) { %> <%&= $elem->name %>: <%= $self->query-><%&= $elem->elemType %>( <%&= $elem->elemArgs %> ) %> <BR> <%& } %> </FORM> Would be resolved to: <FORM METHOD="POST" ACTION="/pas/mySite/FormHandler"> First Name: <%= $self->query->textfield( -name => 'firstName', -size => 20 ) %> <BR> Last Name: <%= $self->query->textfield( -name => 'lastName', -size => 20 ) %> <BR> </FORM> This is obviously a somewhat contrived example, but it should serve to illustrate the concept. A more basic example might be a refactored site that has the start, or header of a page in an include file: <!-- in _header.psp --> <HTML> <HEAD> <TITLE><%&= $Page::title %></TITLE> </HEAD> <BODY BGCOLOR="<%&= $Page::bgcolor %>"> <!-- in index.psp --> <%& $Page::title = 'My Site - Main Page'; $Page::bgcolor = '#FFFFFF'; %> <%@ include file = "_header.psp" %> <!-- the main body goes here... --> <%@ include file = "_footer.psp" %> Which would resolve to a compile PSP page that looked like this: <HTML> <HEAD> <TITLE>My Site - Main Page</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF"> ... In many of the sites I've worked on, this could be used to refactor the presentation layer to make it easier for the site designers/developers to introduce common look and feel to the pages. In many cases, this could also be used as a significant optmization technique to cut down on the overhead of generating a page -- it could greatly reduce the run-time costs of large portions of the pages that are currently dynamically generated from PSP/Perl code. I beleive I can see how to implement this in the compiler without a huge amount of effort. I think the benefits would be huge. Thoughts/Feedback/Comments? Kyle -- ------------------------------------------------------------------------------ Wisdom and Compassion are inseparable. -- Christmas Humphreys mo...@vo... http://www.voicenet.com/~mortis ------------------------------------------------------------------------------ |