You are viewing a plain text version of this content. The canonical link for it is here.
Posted to asp@perl.apache.org by "John D. Leonard II" <jo...@ce.gatech.edu> on 2001/09/12 22:20:22 UTC

RE: Includes revisited

Tim:

Good questions:

1) Rule 1 -> ALWAYS USE "USE STRICT!"  Trying to access global variables in
a mod_perl/ASP environment will kill you at the most inopportune time.

ONLY PASS VARIABLES VIA THE ARGUMENT LIST.  DO NOT DEPEND ON GLOBAL
VARIABLES!  ALWAYS USE "my"

2) Here is an example:

main.asp:
---------

<h1>Header 1</h1>
<%
my $MyLocalVar = "happy days!";

$Response->Include("myfile.inc", $MyLocalVar);
%>
<%
# now, pass an anonymous array
$Response->Include("myfile.inc", [$var1,$var2,$var3]);

# now, pass a scalar, anonymous array, and anonymous hash.  (Now I'm being a
smart ass.)

$Response->Include("myfile.inc",
($MyLocalVar,[$var1,$var2,$var3],[my1=>'hello',my2=>'world']) );

%>
...


myfile.inc:
-----------
<%

my ($arg1,$arg2,$arg3) = @_;  # arguments enter the ASP include file in "@_"

if (scalar $arg1){

}elsif (ref $arg1){

} else {

}

#or

if (@_ == 1) {  #if the number of arguments is 1,
}elsif (@_ == 2) { # etc...
}

# from the "myfile.inc" I also have access to all the other global objects
including $Response, $Request,
# $Server, $Session, and $Application.

%>

JL


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: Includes revisited

Posted by Joshua Chamas <jo...@chamas.com>.
Tim Pushor wrote:
> 
> Its probably just my thick headedness, but reading the SSI section on
> www.apache-asp.org now seems to make sense.
> 
> I wasn't sure quite what you meant by compiling the include as a subroutine.
> If its a subroutine? what happens to the HTML?
> 

The HTML gets printed as in $Response->Write('HTML');

> While we're on this subject, what *really* happens when an asp page
> containing both perl code and HTML gets compiled?
> 

To see how a script is getting compiled, put an intended
perl syntax error in it, and set Debug to 1,2, or 3.
The perl script will be displayed in the browser.

Basically the ASP script gets turned inside out into a regular
perl script, with the HTML ending up in $Response->Write() 
and the perl code just being perl.  <%= %> is optimized
when surrounded by HTML to be like 
  
  $Reponse->Write('HTML'.$scalar_insert.'HTML');

So an ASP script like:

HTML <%= 'HEAD' %>
<% #code; %>
END

would become something like:

$Response->Write('HTML '. 'HEAD' .'
'); #code; $Response->Write('
END
');}

The white space is preserved so errors in the perl
script refer to real line #s.  Also the final perl
script is wrapped up as a subroutine in the GlobalPackage
which defaults to a namespace derived off of where 
Global & global.asa are located.  

This is similar to how Apache::Registry compiles perl CGI 
scripts, and the same caveats apply, for example try to avoid 
defining subroutines in your ASP scripts, as you can
create a my closure problem that UseStrict won't catch.

For more info see the Parse, ParseHelper, & CompilePerl
subroutines in ASP.pm.

--Josh
_________________________________________________________________
Joshua Chamas                           Chamas Enterprises Inc.
NodeWorks Founder                       Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


RE: Includes revisited

Posted by Tim Pushor <ti...@crossthread.com>.
Its probably just my thick headedness, but reading the SSI section on
www.apache-asp.org now seems to make sense.

I wasn't sure quite what you meant by compiling the include as a subroutine.
If its a subroutine? what happens to the HTML?

While we're on this subject, what *really* happens when an asp page
containing both perl code and HTML gets compiled?

Tim

BTW I really appreciate the help. Apache-ASP is a cool tool :)

-----Original Message-----
From: Joshua Chamas [mailto:joshua@chamas.com]
Sent: Wednesday, September 12, 2001 2:40 PM
To: Tim Pushor
Cc: john.leonard@ce.gatech.edu; asp@perl.apache.org
Subject: Re: Includes revisited


Tim Pushor wrote:
>
> Thanks John for helping clear that up.
>
> Now after reading your excellent description, and looking at the
Apache-ASP
> docs, its clear.
>
> 'include' is a correct term, while 'inline' most certainly is not.
>

What docs were confusing?  If you have any pointers,
I'd be happy to incorporate them.

Note that $Response->Include() creates a dynamic include
whereas

  <!--#include file=... -->

creates an inline one, where vars have the same scope
as the including file.  The latter changes to a dynamic
$Response->Include() if it has the syntax

  <!--#include file=... args=... -->

or if DynamicIncludes are turned on.  The history here
is the inline SSI style includes came first, where the
$Response->Include() and @args SSI notation came later,
thus the differences.

--Josh
_________________________________________________________________
Joshua Chamas                           Chamas Enterprises Inc.
NodeWorks Founder                       Huntington Beach, CA  USA
http://www.nodeworks.com                1-714-625-4051


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: Includes revisited

Posted by Joshua Chamas <jo...@chamas.com>.
Tim Pushor wrote:
> 
> Thanks John for helping clear that up.
> 
> Now after reading your excellent description, and looking at the Apache-ASP
> docs, its clear.
> 
> 'include' is a correct term, while 'inline' most certainly is not.
> 

What docs were confusing?  If you have any pointers, 
I'd be happy to incorporate them.

Note that $Response->Include() creates a dynamic include
whereas

  <!--#include file=... -->

creates an inline one, where vars have the same scope
as the including file.  The latter changes to a dynamic
$Response->Include() if it has the syntax

  <!--#include file=... args=... --> 

or if DynamicIncludes are turned on.  The history here
is the inline SSI style includes came first, where the 
$Response->Include() and @args SSI notation came later, 
thus the differences.

--Josh
_________________________________________________________________
Joshua Chamas                           Chamas Enterprises Inc.
NodeWorks Founder                       Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: Includes revisited

Posted by Tim Pushor <ti...@crossthread.com>.
Thanks John for helping clear that up.

Now after reading your excellent description, and looking at the Apache-ASP
docs, its clear.

'include' is a correct term, while 'inline' most certainly is not.

Thanks again,
Tim
----- Original Message -----
From: "John D. Leonard II" <jo...@ce.gatech.edu>
To: "Tim Pushor" <ti...@crossthread.com>; <as...@perl.apache.org>
Sent: Wednesday, September 12, 2001 2:20 PM
Subject: RE: Includes revisited


> Tim:
>
> Good questions:
>
> 1) Rule 1 -> ALWAYS USE "USE STRICT!"  Trying to access global variables
in
> a mod_perl/ASP environment will kill you at the most inopportune time.
>
> ONLY PASS VARIABLES VIA THE ARGUMENT LIST.  DO NOT DEPEND ON GLOBAL
> VARIABLES!  ALWAYS USE "my"
>
> 2) Here is an example:
>
> main.asp:
> ---------
>
> <h1>Header 1</h1>
> <%
> my $MyLocalVar = "happy days!";
>
> $Response->Include("myfile.inc", $MyLocalVar);
> %>
> <%
> # now, pass an anonymous array
> $Response->Include("myfile.inc", [$var1,$var2,$var3]);
>
> # now, pass a scalar, anonymous array, and anonymous hash.  (Now I'm being
a
> smart ass.)
>
> $Response->Include("myfile.inc",
> ($MyLocalVar,[$var1,$var2,$var3],[my1=>'hello',my2=>'world']) );
>
> %>
> ...
>
>
> myfile.inc:
> -----------
> <%
>
> my ($arg1,$arg2,$arg3) = @_;  # arguments enter the ASP include file in
"@_"
>
> if (scalar $arg1){
>
> }elsif (ref $arg1){
>
> } else {
>
> }
>
> #or
>
> if (@_ == 1) {  #if the number of arguments is 1,
> }elsif (@_ == 2) { # etc...
> }
>
> # from the "myfile.inc" I also have access to all the other global objects
> including $Response, $Request,
> # $Server, $Session, and $Application.
>
> %>
>
> JL
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
> For additional commands, e-mail: asp-help@perl.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org