|
/export/home/cpanrun/depot/main/contrib-patched/perl/CPAN/src/HTML-Myasp/blib/html/site/lib/HTML/Myasp.html |
In the call to send_page:
send_page('myfile.html',
{
-users => \&list_users,
-other_data => sub { print "this is the other data"; ... }
},
{
__user__ => $sesion->current_user,
__date__ => localtime(time),
});</PRE>
<P>The first key of the second parameter (the tags_hash) is ``-users '' and it points to a reference of a subroutine.</P>
<P>All this means this:</P>
<P>``All the content found in the template between the marks <xx:users> and </xx:users>, the marks inclusive, will be replaced with whatever the subroutine ''list_users`` prints, using the standard print command''.</P>
<P>The second key ``-other_data'', is shown just to illustrate the declaration of an inline anonymous subroutine.</P>
<P>As in the module Apache::ASP, the subroutines will receive as the first parameter a hash reference with the attributes of the tag, and as a second argument the body of the tag. This may be useful in some cases when you want to use a micro template zone, for example, to predesign the rows in a table.</P>
<P>In the case of tables, is suggested to leave the table declaration in the template as in the example, and leave the rows marked, in order to be generate dynamically.</P>
<P>
<H2><A NAME="keywords_replace_hash">keywords_replace_hash</A></H2>
<P>This parameter (optional), contains the keywords that will be replaced with the specified content. Note that no printing is allowed here, the value asigned to the keyword will be put in the resulting page. Each keyword will be replace as many times as it appear in the document.</P>
<P>No prefixing or sufixing is enforced here, the developer (or designer) can chose the keywords to replace at will.</P>
<P>This form is very well suited for the dynamic content associated with atomic values. As shown in the example:</P>
<P>The HTML file:</P>
<PRE>
<html>
....
__user__
__date__
</PRE>
<PRE>
With the keywords_replace_hash
...
{
__user__ => $sesion->current_user,
__date__ => localtime(time),
});</PRE>
<P>Will render an HTML file with the result of calling $sesion->current_user instead of the string __user__. __date__ will be replaced with the result of calling localtime(time).</P>
<P>If you allways name the marks with initial and ending double underline __, like in the example, here is the code of a shell script that receives a file as parameter and generate a skeleton keywords hash:</P>
<P>#!/bin/sh</P>
<P>perl -ne 'print ``$1\t=>\ttextfield(-name=>\''$2\``),\n'' while /\b(__([\w-]+)__\b)/g' $1</P>
<P>
<HR>
<H1><A NAME="global processing">Global Processing</A></H1>
<P>In the web sites, there are sections that must be present in many pages (if not in all the pages). The system provides two functions that access associative arrays (hashs) that will be allways processed as if they were present in the call to send_page. For example, if you want to allways translate the __user__ mark with the current user and supossing there is some $sesion->current_user method that return this value, you cant at the begining of the request in some handler call:</P>
<P>HTML::Myasp::add_replace_entry(_user__ => $sesion->current_user);</P>
<P>And if you have some sections delimited to replace, you can call:</P>
<P>HTML::Myasp::add_sub_entry(``-section'' => sub { my ($attr, $body) = @_; my $s = new OV::Section($attr->{id}); $s->home_page_news });</P>
<P>The last call, is an example where there are multiple section marks in the html file, in this case, an electronic newspaper, for example:</P>
<P><myasp:section id=foo><p>This is dummy data not used for now. Here must be the top foo.</p></myasp:section>
<myasp:section id=bar><p>This is dummy data not used for now. Here must be the bar section.</p></myasp:section></P>
<P>The id attribute is used to pass a parameter to the call to the funcion that will produce the content.</P>
<P>
<HR>
<H1><A NAME="debugging">Debugging</A></H1>
<P>At this time, there is a Package variable DEBUG that you can set to see aditional information in standard error (traditionally the file error_log in apache).</P>
<P>$HTML::Myasp::DEBUG=1;</P>
<P>There is only one level of debugging, and shows too much information.</P>
<P>
<HR>
<H1><A NAME="todo">TODO</A></H1>
<P>Many things. It uses a rude regex based parser i expect to polish it with something better in the future. Do a finer debugging control.</P>
<P>
<HR>
<H1><A NAME="export">EXPORT</A></H1>
<P>send_page</P>
<P>
<HR>
<H1><A NAME="author">AUTHOR</A></H1>
<P>Hans Poo, <A HREF="mailto:hans@opensource.cl">hans@opensource.cl</A></P>
<P>
<HR>
<H1><A NAME="see also">SEE ALSO</A></H1>
<P>perl(1). Apache::ASP (XMLSubsMatch) HTML::Template</P>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<FONT SIZE=+1><STRONG><P CLASS=block> HTML::Myasp - Generate HTML pages based on Templates. JATP (Just Another
Template Parser).</P></STRONG></FONT>
</TD></TR>
</TABLE>
</BODY>
</HTML>
|
/export/home/cpanrun/depot/main/contrib-patched/perl/CPAN/src/HTML-Myasp/blib/html/site/lib/HTML/Myasp.html |