You are viewing a plain text version of this content. The canonical link for it is here.
Posted to asp@perl.apache.org by Joshua Chamas <jo...@chamas.com> on 2002/02/26 01:05:41 UTC

Re: Calling an Apache::ASP page from an Apache::Registry script

Andrew Ho wrote:
> 
> Hello,
> 
> Apologies if this has been asked before; I searched the archives but
> couldn't find a reference to this. It's been discussed in the context of
> MVC design a while back, but I don't have a solid answer to the following
> question: can you call an Apache::ASP page from an Apache::Registry script?
> Couched in MVC terminology, can I forward control from a .pl controller to
> a .asp template, and pass arguments in a natural way?
> ...

The safest thing to do right now would probably be to do an external
redirect to the ASP page like:

  Apache->request->header_out('Location', "script.asp?$ARGS");
  
I do not think you would be able to pull off an internal redirect,
or you might, but there might be complications if the first script
tried to read POST input on STDIN, and then the ASP script tried also, 
there would probably be a hang.

You could also call the registry/cgi as an asp script directly
and have access to the ASP API like:

 # cgi wrapper script.asp, works with inline includes ( DynamicIncludes 0 )
 <% <!--#include file="script.pl"--> %>

or

 <% do "script.pl"; %>

then the script.pl could do all the ASP API calls it likes as in:

  # script.pl
  ...
  $Server->Transfer('redirect_to.asp', @args);
  ...

If what you really want is to simply load an external ASP script 
as a template for further processing in the script.pl, and you 
only want to run script.pl as an Apache::Registry script, there
is not an API for doing this currently.

--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: Calling an Apache::ASP page from an Apache::Registry script

Posted by Perrin Harkins <pe...@elem.com>.
Andrew Ho wrote:
> I've been investigating other template systems to try to find similar
> functionality in an existing package for a non-Tellme related project and
> haven't been able to find any embedded-Perl solutions that can be called
> from a .pl and still have the benefits of template caching.

Apache::ASP doesn't seem like the best fit for this, if you really don't 
want to use pages as controllers.  You can use Text::Template (just keep 
a cache of the templates in a global hash) or Template Toolkit for this 
(yes, it does allow in-line Perl).  It also may be possible to do this 
with Mason.

- Perrin


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


Re: Calling an Apache::ASP page from an Apache::Registry script

Posted by Joshua Chamas <jo...@chamas.com>.
Andrew Ho wrote:
> 
> Hello,
> 
> AH>...can you call an Apache::ASP page from an Apache::Registry script?
> AH>Couched in MVC terminology, can I forward control from a .pl controller
> AH>to a .asp template, and pass arguments in a natural way?
> 
> JC>The safest thing to do right now would probably be to do an external
> JC>redirect to the ASP page like:
> JC>  Apache->request->header_out('Location', "script.asp?$ARGS");
> 
> Thanks for the quick response. I didn't think of the POST data reading
> conflict. A related question, is there any way to make Apache::ASP not
> initialize its $Request object by default? This is the only blocker from
> using the Apache::Request API in an Apache::ASP page.
> 

Not at this time.  If you really need it, we could probably create a config
to support this.  Otherwise, you might be able to do something like
create your own subclass off of Apache::ASP, and override your own
handler() subroutine to call something like:

package My::Apache::ASP;
sub handler {
  local *Apache::ASP::Request::new = sub { bless {}, 'Apache::ASP::Request' };
  &Apache::ASP::hander();
}
1;

I don't really know if it would work, but you could try an approach
like this.

> Specifically what I'm trying to do is to emulate $Server->Transfer but
> from an Apache::Registry script. I don't need to further process the
> Apache::ASP template in the Apache::Registry script.
> 
> I think an .asp that has <% at the top of the file and %> at the end of it
> would be similar; but I'd prefer using Apache::Registry to (1) eliminate
> the <% %> tokens and more importantly (2) continue using the
> Apache::Request interface which I'm used to.
> 

One thing I have considered doing is allowing a CGIScript 1 type of 
config to be set that would autowrap scripts in <% %> for you.
It may be that you can program Apache::Request in ASP script just fine.
I have done a lot of work to make CGI.pm based script work in ASP,
but not Apache::Request, so no gaurantees, but I know that when the 
ASP api does not support something directly, I will sometimes go
to the Apache API off of Apache->request.

> I've been investigating other template systems to try to find similar
> functionality in an existing package for a non-Tellme related project and
> haven't been able to find any embedded-Perl solutions that can be called
> from a .pl and still have the benefits of template caching. I prefer
> embedded Perl because it's so convenient for little niceties (for example,
> "Your search found <%= $n || 'no' %> document<%= $n == 1 ? '' : 's' %>.")
> that real-world HTML interfaces need.
> 

Like Perrin suggested, Template Toolkit was built to be more of a 
plugin whereever you want a template, so might work better for you.
Apache::ASP is its own enclose execution environment, and takes
more of the things for you.

-- 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: Calling an Apache::ASP page from an Apache::Registry script

Posted by Perrin Harkins <pe...@elem.com>.
Andrew Ho wrote:
> I've been investigating other template systems to try to find similar
> functionality in an existing package for a non-Tellme related project and
> haven't been able to find any embedded-Perl solutions that can be called
> from a .pl and still have the benefits of template caching.

Apache::ASP doesn't seem like the best fit for this, if you really don't 
want to use pages as controllers.  You can use Text::Template (just keep 
a cache of the templates in a global hash) or Template Toolkit for this 
(yes, it does allow in-line Perl).  It also may be possible to do this 
with Mason.

- Perrin


Re: Calling an Apache::ASP page from an Apache::Registry script

Posted by Andrew Ho <an...@tellme.com>.
Hello,

AH>...can you call an Apache::ASP page from an Apache::Registry script?
AH>Couched in MVC terminology, can I forward control from a .pl controller
AH>to a .asp template, and pass arguments in a natural way?

JC>The safest thing to do right now would probably be to do an external
JC>redirect to the ASP page like:
JC>  Apache->request->header_out('Location', "script.asp?$ARGS");

Thanks for the quick response. I didn't think of the POST data reading
conflict. A related question, is there any way to make Apache::ASP not
initialize its $Request object by default? This is the only blocker from
using the Apache::Request API in an Apache::ASP page.

JC>If what you really want is to simply load an external ASP script as a
JC>template for further processing in the script.pl, and you only want to
JC>run script.pl as an Apache::Registry script, there is not an API for
JC>doing this currently.

Specifically what I'm trying to do is to emulate $Server->Transfer but
from an Apache::Registry script. I don't need to further process the
Apache::ASP template in the Apache::Registry script.

I think an .asp that has <% at the top of the file and %> at the end of it
would be similar; but I'd prefer using Apache::Registry to (1) eliminate
the <% %> tokens and more importantly (2) continue using the
Apache::Request interface which I'm used to.

We actually wrote our own template language at Tellme a long time ago to
support specifically this paradigm, which is really convenient for simple
templates (we considered releasing it--running templates is usually as
fast as or faster than running Apache::Registry scripts--but just then,
there was a "don't write another stupid template system" flame war, so we
decided not to!). It's also super convenient for MVC style programming
(modules are the M, Apache::Registry scripts the C, templates the V).

I've been investigating other template systems to try to find similar
functionality in an existing package for a non-Tellme related project and
haven't been able to find any embedded-Perl solutions that can be called
from a .pl and still have the benefits of template caching. I prefer
embedded Perl because it's so convenient for little niceties (for example,
"Your search found <%= $n || 'no' %> document<%= $n == 1 ? '' : 's' %>.")
that real-world HTML interfaces need.

So that's what I'm looking for. :)

Humbly,

Andrew

----------------------------------------------------------------------
Andrew Ho               http://www.tellme.com/       andrew@tellme.com
Engineer                   info@tellme.com          Voice 650-930-9062
Tellme Networks, Inc.       1-800-555-TELL            Fax 650-930-9101
----------------------------------------------------------------------




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


Re: Calling an Apache::ASP page from an Apache::Registry script

Posted by Andrew Ho <an...@tellme.com>.
Hello,

AH>...can you call an Apache::ASP page from an Apache::Registry script?
AH>Couched in MVC terminology, can I forward control from a .pl controller
AH>to a .asp template, and pass arguments in a natural way?

JC>The safest thing to do right now would probably be to do an external
JC>redirect to the ASP page like:
JC>  Apache->request->header_out('Location', "script.asp?$ARGS");

Thanks for the quick response. I didn't think of the POST data reading
conflict. A related question, is there any way to make Apache::ASP not
initialize its $Request object by default? This is the only blocker from
using the Apache::Request API in an Apache::ASP page.

JC>If what you really want is to simply load an external ASP script as a
JC>template for further processing in the script.pl, and you only want to
JC>run script.pl as an Apache::Registry script, there is not an API for
JC>doing this currently.

Specifically what I'm trying to do is to emulate $Server->Transfer but
from an Apache::Registry script. I don't need to further process the
Apache::ASP template in the Apache::Registry script.

I think an .asp that has <% at the top of the file and %> at the end of it
would be similar; but I'd prefer using Apache::Registry to (1) eliminate
the <% %> tokens and more importantly (2) continue using the
Apache::Request interface which I'm used to.

We actually wrote our own template language at Tellme a long time ago to
support specifically this paradigm, which is really convenient for simple
templates (we considered releasing it--running templates is usually as
fast as or faster than running Apache::Registry scripts--but just then,
there was a "don't write another stupid template system" flame war, so we
decided not to!). It's also super convenient for MVC style programming
(modules are the M, Apache::Registry scripts the C, templates the V).

I've been investigating other template systems to try to find similar
functionality in an existing package for a non-Tellme related project and
haven't been able to find any embedded-Perl solutions that can be called
from a .pl and still have the benefits of template caching. I prefer
embedded Perl because it's so convenient for little niceties (for example,
"Your search found <%= $n || 'no' %> document<%= $n == 1 ? '' : 's' %>.")
that real-world HTML interfaces need.

So that's what I'm looking for. :)

Humbly,

Andrew

----------------------------------------------------------------------
Andrew Ho               http://www.tellme.com/       andrew@tellme.com
Engineer                   info@tellme.com          Voice 650-930-9062
Tellme Networks, Inc.       1-800-555-TELL            Fax 650-930-9101
----------------------------------------------------------------------