Apache-ASP

 view release on metacpan or  search on metacpan

site/objects.html  view on Meta::CPAN

  my $buffer = '&' x 100000;
  $Server->HTMLEncode(\$buffer);
  print $buffer;
</pre></font>Using the reference passing method in benchmarks on 100K of
data was 5% more efficient, but maybe useful for some.
It saves on copying the 100K buffer twice.</font>
	
	<p>
	<a name=%24Server-%3EMapd3711f06></a>
	<font face=verdana><font class=title size=-1 color=#555555><b>$Server->MapInclude($include)</b></font>
<font face="courier new" size=3><pre>
</pre></font>API extension.  Given the include $include, as an absolute or relative file name to the current
executing script, this method returns the file path that the include would
be found from the include search path.  The include search path is the 
current script directory, Global, and IncludesDir directories.
<font face="courier new" size=3><pre>
</pre></font>If the include is not found in the includes search path, then undef, or bool false,
is returned. So one may do something like this:
<font face="courier new" size=3><pre>
  if($Server-&gt;MapInclude(&#39;include.inc&#39;)) {
    $Response-&gt;Include(&#39;include.inc&#39;);
  }
</pre></font>This code demonstrates how one might only try to execute an include if
it exists, which is useful since a script will error if it tries to execute an include
that does not exist.</font>
	
	<p>
	<a name=%24Server-%3EMap0fe1ebb5></a>
	<font face=verdana><font class=title size=-1 color=#555555><b>$Server->MapPath($url);</b></font>
<font face="courier new" size=3><pre>
</pre></font>Given the url $url, absolute, or relative to the current executing script,
this method returns the equivalent filename that the server would 
translate the request to, regardless or whether the request would be valid.
<font face="courier new" size=3><pre>
</pre></font>Only a $url that is relative to the host is valid.  Urls like &quot;.&quot; and 
&quot;/&quot; are fine arguments to MapPath, but <tt>http://localhost</tt> would not be.
<font face="courier new" size=3><pre>
</pre></font>To see this method call in action, check out the sample <a href=eg/server.htm>./site/eg/server.htm</a>
script.</font>
	
	<p>
	<a name=%24Server-%3EMai03cc9918></a>
	<font face=verdana><font class=title size=-1 color=#555555><b>$Server->Mail(\%mail, %smtp_args);</b></font>
<font face="courier new" size=3><pre>
</pre></font>With the Net::SMTP and Net::Config modules installed, which are part of the 
perl libnet package, you may use this API extension to send email.  The 
\%mail hash reference that you pass in must have values for at least
the To, From, and Subject headers, and the Body of the mail message.
<font face="courier new" size=3><pre>
</pre></font>The return value of this routine is 1 for success, 0 for failure.  If the MailHost
SMTP server is not available, this will have a return value of 0.
<font face="courier new" size=3><pre>
</pre></font>You could send an email like so:
<font face="courier new" size=3><pre>
 $Server-&gt;Mail({
		To =&gt; &#39;<b>&#115;&#111;&#109;&#101;&#098;&#111;&#100;&#121;&#064;&#121;&#111;&#117;&#114;&#100;&#111;&#109;&#097;&#105;&#110;&#046;&#099;&#111;&#109;&#046;&#102;&#111;&#111;&#098;&#097;&#114;</b>&#39;,
		From =&gt; &#39;<b>&#121;&#111;&#117;&#114;&#101;&#109;&#097;&#105;&#108;&#064;&#121;&#111;&#117;&#114;&#100;&#111;&#109;&#097;&#105;&#110;&#046;&#099;&#111;&#109;&#046;&#102;&#111;&#111;&#098;&#097;&#114;</b>&#39;,
		Subject =&gt; &#39;Subject of Email&#39;,
		Body =&gt; 
		 &#39;Body of message. &#39;.
		 &#39;You might have a lot to say here!&#39;,
		Organization =&gt; &#39;Your Organization&#39;,
                CC =&gt; &#39;<b>&#121;&#111;&#117;&#114;&#101;&#109;&#097;&#105;&#108;&#099;&#099;&#064;&#121;&#111;&#117;&#114;&#100;&#111;&#109;&#097;&#105;&#110;&#046;&#099;&#111;&#109;&#046;&#102;&#111;&#111;&#098;&#097;&#114;</b>&#39;,
                BCC =&gt; &#39;<b>&#121;&#111;&#117;&#114;&#101;&#109;&#097;&#105;&#108;&#098;&#099;&#099;&#064;&#121;&#111;&#117;&#114;&#100;&#111;&#109;&#097;&#105;&#110;&#046;&#099;&#111;&#109;&#046;&#102;&#111;&#111;&#098;&#097;&#114;</b>&#39;,
		Debug =&gt; 0 || 1,
	       });
</pre></font>Any extra fields specified for the email will be interpreted
as headers for the email, so to send an HTML email, you 
could set &#39;Content-Type&#39; =&gt; &#39;text/html&#39; in the above example.
<font face="courier new" size=3><pre>
</pre></font>If you have MailFrom configured, this will be the default
for the From header in your email.  For more configuration
options like the MailHost setting, check out the <a href=config.html><font size=-1 face=verdana><b>CONFIG</b></font></a> section.
<font face="courier new" size=3><pre>
</pre></font>The return value of this method call will be boolean for
success of the mail being sent.
<font face="courier new" size=3><pre>
</pre></font>If you would like to specially configure the Net::SMTP 
object used internally, you may set %smtp_args and they
will be passed on when that object is initialized.
&quot;perldoc Net::SMTP&quot; for more into on this topic.
<font face="courier new" size=3><pre>
</pre></font>If you would like to include the output of an ASP page as the
body of the mail message, you might do something like:
<font face="courier new" size=3><pre>
  my $mail_body = $Response-&gt;TrapInclude(&#39;mail_body.inc&#39;);
  $Server-&gt;Mail({ %mail, Body =&gt; $$mail_body });
</pre></font>
	
	<p>
	<a name=%24Server-%3EReg38562b5d></a>
	<font face=verdana><font class=title size=-1 color=#555555><b>$Server->RegisterCleanup($sub) </b></font>
<font face="courier new" size=3><pre>
 non-portable extension
</pre></font>Sets a subroutine reference to be executed after the script ends,
whether normally or abnormally, the latter occurring 
possibly by the user hitting the STOP button, or the web server
being killed.  This subroutine must be a code reference 
created like:
<font face="courier new" size=3><pre>
 $Server-&gt;RegisterCleanup(sub { $main::Session-&gt;{served}++; });
   or
 sub served { $main::Session-&gt;{served}++; }
 $Server-&gt;RegisterCleanup(\&amp;served);
</pre></font>The reference to the subroutine passed in will be executed.
Though the subroutine will be executed in anonymous context, 
instead of the script, all objects will still be defined 
in main::*, that you would reference normally in your script.  
Output written to $main::Response will have no affect at 
this stage, as the request to the www client has already completed.
<font face="courier new" size=3><pre>
</pre></font>Check out the <a href=eg/register_cleanup.asp>./site/eg/register_cleanup.asp</a> script for an example
of this routine in action.</font>
	
	<p>
	<a name=%24Server-%3ETra98c592dc></a>
	<font face=verdana><font class=title size=-1 color=#555555><b>$Server->Transfer($file, @args)</b></font>
<font face="courier new" size=3><pre>
</pre></font>New method from ASP 3.0.  Transfers control to another script.  
The Response buffer will not be cleared automatically, so if you 
want this to serve as a faster $Response-&gt;Redirect(), you will need to 



( run in 0.549 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )