Re: Mapping to location "/"

2002-06-13 Thread md


--- Perrin Harkins <[EMAIL PROTECTED]> wrote:

> I don't really see the problem.  You can map all the
> URLs that end with 
> a certain extension to one module that does some
> work and then calls a 
> template.  

OK...the little light bulb has just come on...

I didn't realize that I could put my templates
directly in htdocs. Now I can create a template and
call it index.phtml and set DirectoryIndex to include
index.phtml and all works like I want.

Thanks!


__
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



Re: Mapping to location "/"

2002-06-13 Thread md


--- Per Einar Ellefsen <[EMAIL PROTECTED]> wrote:
> At 16:04 13.06.2002, md wrote:
 
> >What I'm really trying to do is more like the PHP
> I'm
> >replacing. I should be able to go to:
> >
> >www.someserver.com/index.phtml for a dynamic page
> >and
> >www.someserver.com/index.html for a static page.
> 
> Does PHP do that?

Yes...since both index.html and index.php are physical
files.

 
> Using HTML::Mason or Apache::ASP won't solve
> anything special. It's still 
> the same basic thing.

Except that there will by a physical file with
embedded code like PHP, so I think Mason and
Apache::ASP would be closer to what I want. However, I
don't have that option.

I'd really like to use a Location, but the request is
to keep existing directory structures (over 200
top-level directories) and the main index page needs
to be dynamic as well.
 
> Let's assess your situation a litte: why can't you
> just put your TT 
> templates into your document root, and do like with
> your PHP pages? That 
> would solve the current problem you seem to be
> facing. 

Because the templates need to be processed by a
mod_perl script and I need to map that somehow.

> Furthermore, have 
> you looked into the Apache::Template module? I think
> it's pretty close to 
> what you want.

I haven't looked at it, but I believe it's just a
wrapper to Template-Toolkit.

Thanks for the suggestions :)




__
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



Re: Mapping to location "/"

2002-06-13 Thread Perrin Harkins

md wrote:
> What I'm really trying to do is more like the PHP I'm
> replacing. I should be able to go to:
> 
> www.someserver.com/index.phtml for a dynamic page 
> and
> www.someserver.com/index.html for a static page.
> 
> I'm guessing that my best solution would be to use
> HTML::Mason or Apache::ASP instead of
> Template-Toolkit.

Why?  Just because you don't have literal files for those URLs with TT 
and with Mason or ASP you would?

I don't really see the problem.  You can map all the URLs that end with 
a certain extension to one module that does some work and then calls a 
template.  You can map individual URLs or sets of URLs to separate 
modules that do different processing and call a template.  You could 
even put the actual files there and use Apache::Template to serve them. 
  Apache::Template has a hook to add your processing code before the 
template gets run, and you can have multiple handlers that do different 
processing in different locations.

> I may try using the PerlTransHandler to change the uri
> to a location...say with
> www.someserver.com/index.phtml the uri gets changed to
> /modperl (or www.someserver.com/somedir/index.phtml
> the uri becomes /modperl/somedir) which is used in a
>  directive.

What does that get you?  I don't see why you would want to do that.

- Perrin




Re: Mapping to location "/"

2002-06-13 Thread Per Einar Ellefsen

At 16:04 13.06.2002, md wrote:

>--- Per Einar Ellefsen <[EMAIL PROTECTED]> wrote:
> > At 23:06 12.06.2002, md wrote:
>
> > I'm not quite sure about this, been wondering about
> > it, but in theory you
> > should be able to use
> > DirectoryIndex index.phtml
> > and like that you won't have to worry about "/" etc
> > anymore.
> > Try it out..
>
>And so I did...it won't work since mod_dir (as far as
>I can tell) looks for a physical file, and my
>index.phtml is virtual.

Ok, too bad.

>What I'm really trying to do is more like the PHP I'm
>replacing. I should be able to go to:
>
>www.someserver.com/index.phtml for a dynamic page
>and
>www.someserver.com/index.html for a static page.

Does PHP do that?

>I'm guessing that my best solution would be to use
>HTML::Mason or Apache::ASP instead of
>Template-Toolkit. However, I can' really do that...it
>took me a while to get the designers to use TT, and I
>doubt I can get them to change again.

Using HTML::Mason or Apache::ASP won't solve anything special. It's still 
the same basic thing.

>I may try using the PerlTransHandler to change the uri
>to a location...say with
>www.someserver.com/index.phtml the uri gets changed to
>/modperl (or www.someserver.com/somedir/index.phtml
>the uri becomes /modperl/somedir) which is used in a
> directive.

Let's assess your situation a litte: why can't you just put your TT 
templates into your document root, and do like with your PHP pages? That 
would solve the current problem you seem to be facing. Furthermore, have 
you looked into the Apache::Template module? I think it's pretty close to 
what you want.


-- 
Per Einar Ellefsen
[EMAIL PROTECTED]





Re: Mapping to location "/"

2002-06-13 Thread md


--- Per Einar Ellefsen <[EMAIL PROTECTED]> wrote:
> At 23:06 12.06.2002, md wrote:

> I'm not quite sure about this, been wondering about
> it, but in theory you 
> should be able to use
> DirectoryIndex index.phtml
> and like that you won't have to worry about "/" etc
> anymore.
> Try it out..

And so I did...it won't work since mod_dir (as far as
I can tell) looks for a physical file, and my
index.phtml is virtual.

What I'm really trying to do is more like the PHP I'm
replacing. I should be able to go to:

www.someserver.com/index.phtml for a dynamic page 
and
www.someserver.com/index.html for a static page.

I'm guessing that my best solution would be to use
HTML::Mason or Apache::ASP instead of
Template-Toolkit. However, I can' really do that...it
took me a while to get the designers to use TT, and I
doubt I can get them to change again. 

I may try using the PerlTransHandler to change the uri
to a location...say with
www.someserver.com/index.phtml the uri gets changed to
/modperl (or www.someserver.com/somedir/index.phtml
the uri becomes /modperl/somedir) which is used in a
 directive.

__
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



Re: Mapping to location "/"

2002-06-12 Thread darren chamberlain

* md <[EMAIL PROTECTED]> [2002-06-12 17:05]:
> --- darren chamberlain <[EMAIL PROTECTED]> wrote:
> > If you use a translation handler, you can just return DECLINED for
> > everything you aren't specifically handling, and let mod_dir do it's
> > thing, instead of emulating it.
> 
> I still would like to check first if there is an index.phtml template
> instead of going directly to the directory index files like
> index.html. Can I add my "virtual" index.phtml to DirectoryIndex so I
> don't have to look for it in my handler? I'm not quite clear on this
> one...but it might be once I read the guide on translation handlers :)

You can add something to the effect of:

  return DECLINED
if ($r->uri =~ /\.phtml$/ &&
-e File::Spec->catfile($r->document_root, $r->uri));
  
in there.

(darren)

-- 
Any technology indistinguishable from magic is insufficiently advanced.



Re: Mapping to location "/"

2002-06-12 Thread Per Einar Ellefsen

At 23:06 12.06.2002, md wrote:

>--- darren chamberlain <[EMAIL PROTECTED]>
>wrote:
>
> > If you use a translation handler, you can just
> > return DECLINED for
> > everything you aren't specifically handling, and let
> > mod_dir do it's
> > thing, instead of emulating it.
>
>I still would like to check first if there is an
>index.phtml template instead of going directly to the
>directory index files like index.html. Can I add my
>"virtual" index.phtml to DirectoryIndex so I don't
>have to look for it in my handler? I'm not quite clear
>on this one...but it might be once I read the guide on
>translation handlers :)

I'm not quite sure about this, been wondering about it, but in theory you 
should be able to use
DirectoryIndex index.phtml
and like that you won't have to worry about "/" etc anymore.
Try it out..


-- 
Per Einar Ellefsen
[EMAIL PROTECTED]





Re: Mapping to location "/"

2002-06-12 Thread md


--- darren chamberlain <[EMAIL PROTECTED]>
wrote:

> If you use a translation handler, you can just
> return DECLINED for
> everything you aren't specifically handling, and let
> mod_dir do it's
> thing, instead of emulating it.

I still would like to check first if there is an
index.phtml template instead of going directly to the
directory index files like index.html. Can I add my
"virtual" index.phtml to DirectoryIndex so I don't
have to look for it in my handler? I'm not quite clear
on this one...but it might be once I read the guide on
translation handlers :)
 
> I think what you want is something like this:

I'll try this...thanks.


__
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



Re: Mapping to location "/"

2002-06-12 Thread darren chamberlain

* md <[EMAIL PROTECTED]> [2002-06-12 13:15]:
> --- Per Einar Ellefsen <[EMAIL PROTECTED]> wrote:
> > Can't you just drop the  and use
> > 
> >SetHandler 
> > 
> > or something like that? Seems like it would avoid
> > some overhead for you.
> 
> True...but the files don't actually exist. The
> path/filename is used to map to a template.

You definitely want to do this in the translation phase; that's what
it's there for.  

> > However, I'm not sure if I understand what you mean
> > with
> >   $uri =~ m!.*/[^\.]+$!) {
> 
> This may not be the best regex..but what I was trying to do was to
> match something like "/directory/subdirectory" which would normally be
> redirected back to "/directory/subdirectory/index.html" (or whatever
> is set as DirectoryIndex files). I want to check for a
> "/directory/subdirectory/index.phtml" file.

If you use a translation handler, you can just return DECLINED for
everything you aren't specifically handling, and let mod_dir do it's
thing, instead of emulating it.

I think what you want is something like this:

  package Foo;  # or whatever

  use strict;
  use Apache::Constants qw(OK DECLINED);

  sub handler {
  my $r = shift;

  return DECLINED unless $r->uri =~ /\.phtml$/;

  # Figure out which template to use here
  my $template_name = get_template_name($r);
  $r->filename($template_name);

  return OK;
  }
  1;OK;

(darren)

-- 
Reisner's Rule of Conceptual Inertia:
If you think big enough, you'll never have to do it.



Re: Mapping to location "/"

2002-06-12 Thread md


--- Per Einar Ellefsen <[EMAIL PROTECTED]> wrote:
> At 19:14 12.06.2002, Per Einar Ellefsen wrote:
> >
> 
> Sorry, make that LocationMatch
> 
> >...
> >
> 
> And  of course.

That should work...thanks.

For the most part *all* .phtml pages will be doing the
same thing, taking session data and parsing out
templates. 

In some cases I may need something entirely different
as far as logic goes, like a message board or a reg
form, but still using TT and session data. That's
where I'll be using a different Location, TT Plugins
or Stas's suggestion...or any other suggestions I may
receive. HTML::Mason would probably be a closer match
to what I'm trying to do (replacing PHP), but we use
TT for everything :)

__
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



Re: Mapping to location "/"

2002-06-12 Thread Per Einar Ellefsen

At 19:14 12.06.2002, Per Einar Ellefsen wrote:
>

Sorry, make that LocationMatch

>...
>

And  of course.


-- 
Per Einar Ellefsen
[EMAIL PROTECTED]





Re: Mapping to location "/"

2002-06-12 Thread md


--- Per Einar Ellefsen <[EMAIL PROTECTED]> wrote:
> Can't you just drop the  and use
> 
>SetHandler 
> 
> or something like that? Seems like it would avoid
> some overhead for you.

True...but the files don't actually exist. The
path/filename is used to map to a template.

> However, I'm not sure if I understand what you mean
> with
>   $uri =~ m!.*/[^\.]+$!) {

This may not be the best regex..but what I was trying
to do was to match something like
"/directory/subdirectory" which would normally be
redirected back to
"/directory/subdirectory/index.html" (or whatever is
set as DirectoryIndex files). I want to check for a
"/directory/subdirectory/index.phtml" file.

> Hmm, but if you don't have a template, then you have
> nothing to serve, right?

I'd like to also have other mod_perl handlers mapped
to other Locations like normal, so for example
"/something" I may not have a corresponding template
but I would have a
.

__
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



Re: Mapping to location "/"

2002-06-12 Thread Per Einar Ellefsen

At 19:08 12.06.2002, md wrote:

>--- Aaron Ross <[EMAIL PROTECTED]> wrote:
>
> > Would
> >
> >  
> >
> >  
> >
> > do the trick?
>
>No...the files don't actually exist under htdocs since
>I'm using Template-Toolkit.

Oh, so your .phtml things are really just TT templates?
What about:


...

complete the regex with what you want.


-- 
Per Einar Ellefsen
[EMAIL PROTECTED]





Re: Mapping to location "/"

2002-06-12 Thread md


--- Aaron Ross <[EMAIL PROTECTED]> wrote:

> Would
> 
>  
> 
>  
> 
> do the trick?

No...the files don't actually exist under htdocs since
I'm using Template-Toolkit.

Thanks though.

__
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



Re: Mapping to location "/"

2002-06-12 Thread Per Einar Ellefsen

At 18:41 12.06.2002, md wrote:
>I'm replacing an exisiting PHP site with mod_perl and
>Template-Toolkit.
>
>I normally set up mod_perl to use a location like
>this:
>
>
>
>and set the handler to my mod_perl module.
>
>However, I need to map to "/" since I'm replacing a
>system where there are existing PHP files like
>www.someserver.com/index.php or
>www.someserver.com/about.php.
>
>I decided to do use
>
>
>
>to map to my main mod_perl script.
>
>The first thing it does is to check if the uri ends
>with a .phtml extension (or www.someserver.com or
>www.someserver.com/...same with subdirectories). If
>there is, I continue processing, otherwise I decline
>it and let Apache handle it.

Can't you just drop the  and use

   SetHandler 

or something like that? Seems like it would avoid some overhead for you.
However, I'm not sure if I understand what you mean with
  $uri =~ m!.*/[^\.]+$!) {

>If I have a .phtml (or a directory index) I check if I
>have a template. If I have a template TT takes over,
>if not I return DECLINED and let Apache take over.

Hmm, but if you don't have a template, then you have nothing to serve, right?

>httpd.conf
>-
>
> PerlSetVar websrc_root /usr/local/templates
>SetHandler  perl-script
> PerlHandler Test::MyModule
>
>
>Beginning of MyModule.pm
>-
># Get the uri
>my($uri, $uri2);
>$uri = $uri2 = $r->uri;
>$uri2 =~ s[^/][];  # remove the leading '/'
>
># We only want to see .phtml files, or urls that end
>with '/'
># or where the stuff past the last '/' doesn't contain
>any '.'s.
># We'll check the later two case for a template and
>then
># decline it if no template is found.
>unless ($uri =~ /\.phtml$/ or
> $uri =~ m!/$! or
> $uri =~ m!.*/[^\.]+$!) {
> return DECLINED;
>}
>
>Is this the best way to do this?

-- 
Per Einar Ellefsen
[EMAIL PROTECTED]





Re: Mapping to location "/"

2002-06-12 Thread Stas Bekman

md wrote:
> I'm replacing an exisiting PHP site with mod_perl and
> Template-Toolkit.
> 
> I normally set up mod_perl to use a location like
> this:
> 
> 
> 
> and set the handler to my mod_perl module.
> 
> However, I need to map to "/" since I'm replacing a
> system where there are existing PHP files like
> www.someserver.com/index.php or
> www.someserver.com/about.php.
> 
> I decided to do use
> 
> 
> 
> to map to my main mod_perl script. 
> 
> The first thing it does is to check if the uri ends
> with a .phtml extension (or www.someserver.com or
> www.someserver.com/...same with subdirectories). If
> there is, I continue processing, otherwise I decline
> it and let Apache handle it. 
> 
> If I have a .phtml (or a directory index) I check if I
> have a template. If I have a template TT takes over,
> if not I return DECLINED and let Apache take over.
...
> Is this the best way to do this?

you should probably use a custom PerlTransHandler handler with 
push_handlers, e.g. see:
http://modperl.com:9000/book/chapters/ch7.html#Installing_a_Custom_Response_Han
and the whole section.


__
Stas BekmanJAm_pH --> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com




Re: Mapping to location "/"

2002-06-12 Thread Aaron Ross


> 
> 
> to map to my main mod_perl script. 
> 
> The first thing it does is to check if the uri ends
> with a .phtml extension (or www.someserver.com or
> www.someserver.com/...same with subdirectories). If
> there is, I continue processing, otherwise I decline
> it and let Apache handle it. 

Would

 

 

do the trick?


-- 
Aaron Ross . Alias I, Inc.
 email . [EMAIL PROTECTED]
   web . www.alias-i.com
office . 215 545 6428
mobile . 610 517 2905