Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ASP

Executing ASP in scalar...

 

 

ModPerl asp RSS feed   Index | Next | Previous | View Threaded


lindqvist at netstar

May 26, 2001, 5:23 PM

Post #1 of 6 (2443 views)
Permalink
Executing ASP in scalar...

Hello!

Is there any way to get Apache::ASP to do something like "$Response->Include"
on a scalar containing ASP code instead of a filename (something like "eval"
but for ASP instead of plain perl)?

(If I'm not mistaken Parse is in itself compatible with this, but Include
calls CompileInclude which verifies that the scalar contains a valid filename
before calling Parse which then (when we have a given it a filename) calls
ReadFile to get the data.)

It would be really good if someone could give me some hints on this - does
this functionality exist, or should i try to hack it into my Apache::ASP?


Thanks in advance,
Håkan Lindqvist

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl


joshua at chamas

May 27, 2001, 1:10 PM

Post #2 of 6 (2317 views)
Permalink
Re: Executing ASP in scalar... [In reply to]

Håkan Lindqvist wrote:
>
> Hello!
>
> Is there any way to get Apache::ASP to do something like "$Response->Include"
> on a scalar containing ASP code instead of a filename (something like "eval"
> but for ASP instead of plain perl)?
>

Until this functionality is released officially, I would try something like:

( untested )
sub my_execute {
my $asp_script = shift;
my $ASP = $main::Server->{asp}
my $perl_script = $ASP->Parse(\$asp_script);
my $sub = eval "sub { package $ASP->{GlobalASA}{'package'}; $perl_script }";
$@ && die("error compiling sub: $@");
eval { &$sub };
$@ && die("error executing sub: $@");
1;
}

To really support this functionality, I will need to move
all the ASP scripts being stored in a Tie::Cache kind of hash
of sub closures for the scripts, for those that try to reap
the benefits of an Apache::SizeLimit structure, where each
process might keep only 100 scripts compiled with a setting
on ScriptCacheSize ...

Otherwise the above functionality would either not receive the
benefits of caching, or would contribute to process bloat as
each dynamic script got compiled & cached at runtime.

-- Josh

_________________________________________________________________
Joshua Chamas Chamas Enterprises Inc.
NodeWorks <- Web Link Checking Huntington Beach, CA USA
http://www.nodeworks.com 1-714-625-4051

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl


lindqvist at netstar

May 27, 2001, 3:08 PM

Post #3 of 6 (2322 views)
Permalink
Re: Executing ASP in scalar... [In reply to]

On Sunday 27 May 2001 22:10, Joshua Chamas wrote:
[snip]
> Until this functionality is released officially, I would try something
> like:
>
> ( untested )
> sub my_execute {
> my $asp_script = shift;
> my $ASP = $main::Server->{asp}
> my $perl_script = $ASP->Parse(\$asp_script);
> my $sub = eval "sub { package $ASP->{GlobalASA}{'package'}; $perl_script
> }"; $@ && die("error compiling sub: $@");
> eval { &$sub };
> $@ && die("error executing sub: $@");
> 1;
> }
>
> To really support this functionality, I will need to move
> all the ASP scripts being stored in a Tie::Cache kind of hash
> of sub closures for the scripts, for those that try to reap
> the benefits of an Apache::SizeLimit structure, where each
> process might keep only 100 scripts compiled with a setting
> on ScriptCacheSize ...
>
> Otherwise the above functionality would either not receive the
> benefits of caching, or would contribute to process bloat as
> each dynamic script got compiled & cached at runtime.

Thank you very much for your helpful response... it seems however that the
code you supplied does not really work... (I know, you did say it was
untested.... and I honestly did not fully understand the code, so the
solution may be very obvious for you)...

Anyway, this is what I get:
error executing sub: Undefined subroutine
&Apache::ASP::Compiles::_var_www_tmp_sitenew_global_asa::SCALAR called at
(eval 295) line 1.


I really hope this functionality will eventually make it into Apache::ASP as
it is _so_ useful... :)

/Håkan Lindqvist

>
> -- Josh
>
> _________________________________________________________________
> Joshua Chamas Chamas Enterprises Inc.
> NodeWorks <- Web Link Checking Huntington Beach, CA USA
> http://www.nodeworks.com 1-714-625-4051
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: asp-unsubscribe [at] perl
> For additional commands, e-mail: asp-help [at] perl

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl


joshua at chamas

May 27, 2001, 8:24 PM

Post #4 of 6 (2332 views)
Permalink
Re: Executing ASP in scalar... [In reply to]

Håkan Lindqvist wrote:
>
> Thank you very much for your helpful response... it seems however that the
> code you supplied does not really work... (I know, you did say it was
> untested.... and I honestly did not fully understand the code, so the
> solution may be very obvious for you)...
>
> Anyway, this is what I get:
> error executing sub: Undefined subroutine
> &Apache::ASP::Compiles::_var_www_tmp_sitenew_global_asa::SCALAR called at
> (eval 295) line 1.
>

Yes, the code was a bit off, this actually seems to work for me
as an ASP script example:

<%
&my_execute("<\% print ('test print'); %\>");

sub my_execute {
my $asp_script = shift;
my $ASP = $main::Server->{asp};
my $perl_script = $ASP->Parse(\$asp_script);
my $sub = eval "sub { package $ASP->{GlobalASA}{'package'}; $$perl_script }";
$@ && die("error compiling sub: $@");
eval { &$sub };
$@ && die("error executing sub: $@");
1;
}
%>

Note the above code uses methods & members that are not
documented and may change, but hopefully the next release
I'll have this functionality for real and you can just replace
this code with the real API call.

--Josh

_________________________________________________________________
Joshua Chamas Chamas Enterprises Inc.
NodeWorks <- Web Link Checking Huntington Beach, CA USA
http://www.nodeworks.com 1-714-625-4051

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl


joshua at chamas

May 27, 2001, 11:32 PM

Post #5 of 6 (2340 views)
Permalink
Re: Executing ASP in scalar... [In reply to]

Joshua Chamas wrote:
>
> Håkan Lindqvist wrote:
> >
> > Thank you very much for your helpful response... it seems however that the
> > code you supplied does not really work... (I know, you did say it was
> > untested.... and I honestly did not fully understand the code, so the
> > solution may be very obvious for you)...
> >

This feature where $Response->Include() can take
a raw ASP script as a scalar ref will be in the 2.11
release. I'll send it to you separately.

So normal use would be $Response->Include($file)
but now the API will also support $Response->Include(\$script_text)

--Josh

_________________________________________________________________
Joshua Chamas Chamas Enterprises Inc.
NodeWorks <- Web Link Checking Huntington Beach, CA USA
http://www.nodeworks.com 1-714-625-4051

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl


pmak at aaanime

May 27, 2001, 11:56 PM

Post #6 of 6 (2328 views)
Permalink
Re: Executing ASP in scalar... [In reply to]

On Sun, 27 May 2001, Joshua Chamas wrote:

> This feature where $Response->Include() can take
> a raw ASP script as a scalar ref will be in the 2.11
> release. I'll send it to you separately.

If all else fails, I suppose it would work to write the ASP script to a
temporary file (there are CPAN perl modules that handle how to find an
unused temporary file name) and $Response->Include() it. It probably
wouldn't be efficient, but would work as a temporary kludge. e.g.:

sub raw_include {
my $tmpfile = (generate a temporary filename);
open(TMP, $tmpfile);
print TMP shift;
close(TMP);
$Response->Include($tmpfile);
unlink($tmpfile);
}

-Philip Mak (pmak [at] aaanime)


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl

ModPerl asp RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.