Apache-ASP

 view release on metacpan or  search on metacpan

site/articles/perlmonth1_intro.html  view on Meta::CPAN

application development, which promised to be maintainable, powerful,
and fast.  But support for perl under PerlScript was shoddy, VBScript, 
ASP's native tongue, seemed a pathetic alternative, and an NT/IIS solution lacks a certain 
portability.  Thus I was led to developing <a href=http://www.apache-asp.org>Apache::ASP</a>, 
which runs under Doug MacEachern's <a href=http://perl.apache.org>mod_perl</a> 
for <a href=http://www.apache.org>Apache</a>.

<h3>Maintainable</h3>

I had been doing CGI style web applications for a couple of years already, 
and had never been quite satisfied with the CGI programming, 
growing less so as the HTML I was working with became increasingly more 
complex than the CGI it was embedded in.  The idea of embedding the scripting 
within the flow of the HTML seemed like a more natural fit over time.
This natural flow speaks to the heart of <b>maintainability</b>,
where another developer can pick up your code and get a feel for
it on the first read.
<p>
Check out the difference in how it feels to embed the HTML
in the scripting, versus embedding the scripting in the HTML.
A reasonably complex table, which is structurally HTML heavy,
only touches the tip of the iceberg:
<p>
<table border=2 bgcolor=blue>
<tr><td>
        <table border=4 bgcolor=white>
        
            <tr><td>SOME</td></tr>
            
            <tr><td>DATA</td></tr>
             
                </table><td><table border=4 bgcolor=white>
                
            <tr><td>TO</td></tr>
            
            <tr><td>LOOP</td></tr>
             
                </table><td><table border=4 bgcolor=white>
                
            <tr><td>OVER</td></tr>
            
            <tr><td>:)</td></tr>
            
        </table>
</td></tr>
</table>
<p>
Coding this table in CGI, you might get:
<pre>
<hr width=90% size=1>
use CGI qw/:standard *table/;
my(@data) = (&#39;Some&#39;, &#39;Data&#39;, &#39;To&#39;, &#39;Loop&#39;, &#39;Over&#39;, &#39;:)&#39;);
print 
  header,
  start_html(&#39;Example&#39;),
  start_table({-border=&gt;2, -bgcolor=&gt;&#39;blue&#39;}),
  Tr,td,
  start_table({-border=&gt;4, -bgcolor=&gt;&#39;white&#39;})
  ;

# pretend we are reading from database cursor, so code
# would be written like so
my($data, $count);
while(@data) { 
    if($data and $count++ % 2) {
	print end_table,td,start_table({-border=&gt;4, -bgcolor=&gt;&#39;white&#39;});
    }
    $data = shift @data;
    print Tr({align=&gt;CENTER},
	     [td([uc($data).&quot;\n&quot;])]
	    )
      ;
}

print 
  end_table,
  end_table,
  end_html
  ;

<hr width=90% size=1>
</pre>
When designing the above table ASP style, a much more 
natural flow to the script takes form, wherein the developer 
can literally see the table in table layout of the page:
<pre>
<hr width=90% size=1>
&lt;% my(@data) = (&#39;Some&#39;, &#39;Data&#39;, &#39;To&#39;, &#39;Loop&#39;, &#39;Over&#39;, &#39;:)&#39;); %&gt;
&lt;html&gt;
&lt;head&gt;&lt;title&gt;Example&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
&lt;table border=2 bgcolor=blue&gt;
&lt;tr&gt;&lt;td&gt;
	&lt;table border=4 bgcolor=white&gt;
	&lt;%
	my($data, $count);
	while(@data) { 
	    if($data and $count++ % 2) {
		%&gt; 
		&lt;/table&gt;&lt;td&gt;&lt;table border=4 bgcolor=white&gt;
		&lt;% 
	    } 
	    $data = shift @data;
	    %&gt;
	    &lt;tr&gt;&lt;td&gt;&lt;%=uc $data%&gt;&lt;/td&gt;&lt;/tr&gt;
	    &lt;%
	}
	%&gt;
	&lt;/table&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;

<hr width=90% size=1>
</pre>
<p>
Doesn't the HTML-centric ASP read better?  You'll see that
this becomes more true as the html of your site becomes increasingly
complex.
<p>



( run in 0.648 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )