Re: [Pas-dev] Re: PAS include file directive
Status: Beta
Brought to you by:
mortis
From: Justin B. <ju...@le...> - 2004-01-26 15:14:42
|
>>i've been poking around the compiler trying to figure out why this >>doesn't work: >> >><% my $filename = $self->config->get('pspFileName'); %> >><%@ include file="$filename" %> > > > PSP directives (things that start with %@, like 'include file') are > resolved at compile time. File inclusions are expanded during > compilation, the file referenced is inserted into the text of the PSP > as if you wrote it directly into the PSP file. Once all the > directives are resolved, then the code for the page object is emitted. A couple of print statments later and I was able to finally see this. > Tags like expressions (<%= %>) and code (<% %>) tags are what become > part of the code of the generated page object. So they don't get > 'run' until the page object's execute() method is invoked. > > Does that make sense? Yup. >>$filename doesn't get translated and the compiler complains that it's >>can't find a file named '$filename'. > > Exactly, there is no evaluation or execution of the referenced file > name in include directives. I see that now. > Run-time inclusion is not part of the <%@ include file ... %> > directive. > > What exactly are you after with the run-time inclusion? JSP handles > it with a taglet, something like: > > <psp:include uri="/u/r/i"> > <psp:arg name="foo" value="baz" /> > <psp:arg name="bar" value="qux" /> > </psp:include> > > It uses a 'uri' for an important reason. In JSP, that taglet actually > causes the system to execute the code pointed to by the uri as an HTTP > request, passing in the specified parameters as a query string (or as > post-data if you specify that the request should be a POST). It's not > an include in the sense of code inclusion, or in the sense of a > method-call, it's including the output produced by the referenced uri. I want to be able to include a specific snippet of code dependent on a parameter in the configuration file. In the sales force application that we've worked on, we have multiple sites running on a single code base. What if a client wants a little different look to a page? Instead of completely duplicating the page like we have been when this case arises, I'd rather just grab what file gets included from the config file and run with it. If we can do this then the system can be more template based where a client could even choose a different layout instead of being restricted to a single layout. After reviewing the code more last night, the include file directive could almost be made to happen at runtime... we'd just need access to a compiler (isn't it already there in the RequestHandler?). The resolveIncludeFile method could be moved to Org::Bgw::Pas::Page.pm or Org::Bgw::Pas::Base.pm. That method would pretty much remain the same except it would compile the file it finds and return the results. Justin |