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

Mailing List Archive: ModPerl: ASP

nested includes revisited, w/workaround

 

 

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


ivan-asp at 420

Dec 30, 2004, 3:47 PM

Post #1 of 3 (2138 views)
Permalink
nested includes revisited, w/workaround

Hi,

Nested includes don't work as you would expect (well, at least they
don't work as *I* expected :). Given files

/PATH/A
/PATH/DIR/B
/PATH/DIR/C

Say file A includes "DIR/B". This works fine.

Say file B includes "C". This works fine when file B is accessed
directly, but fails when it is included in A as above. Apache::ASP
considers the "current directory" to be /PATH, not /PATH/DIR

This was brought up a few months ago by by Marko Friedeman, and although
Josh said it was supposed to work this way, I would ask that perhaps the
issue could be reconsidered. I was bitten badly by this while
refactoring a monolithic page into many smaller files using includes. I
believe the current behaviour is rather counter-intuititve.

As a workaround, I'm using an include wrapper that looks sort of like
this (irrelevant code excluded):

sub include {
my $file = shift;
my $shift = 0;
if ( $file =~ m(^([^/].*)/[^/]+) ) {
unshift @{$Response->{asp}{includes_dir}}, "./$1";
$shift = 1;
}
my $ref = $Response->TrapInclude($file, @_);
shift @{$Response->{asp}{includes_dir}} if $shift;
$$ref;
}

This lets my code work the way I want, though perhaps a more proper
implementation would consider the "current directory" to be that of the
currently executing include rather than muck about with the includes_dir
path.

Any thoughts appriciated, even if its just "go away and use Mason if you
want that behaviour". :)

--
_ivan
Open-source billing, ticketing and provisioning
for ISPs, VoIP providers and online businesses
http://www.sisd.com/freeside/

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


josh at chamas

Dec 31, 2004, 1:32 PM

Post #2 of 3 (1986 views)
Permalink
Re: nested includes revisited, w/workaround [In reply to]

ivan-asp [at] 420 wrote:
> Hi,
>
> Nested includes don't work as you would expect (well, at least they
> don't work as *I* expected :). Given files
>
> /PATH/A
> /PATH/DIR/B
> /PATH/DIR/C
>

I believe your goal really is to really refactor includes elsewhere,
in which case we already have a mechanism for this. Includes can
be found in Global or IncludesDir directorys, so if you configure
these setting, they will pick up includes in your search path. See:

http://apache-asp.org/config.html#IncludesDir

In your case you might want to set /PATH/DIR to be part of your IncludesDir.

I think really refactoring of these includes should put them into a path
not browsable from the web, so should be ideally outside your main script
area, not under it.

Could this take care of your issue possibly?

Regards,

Josh

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


ivan-asp at 420

Jan 3, 2005, 7:18 PM

Post #3 of 3 (1977 views)
Permalink
Re: nested includes revisited, w/workaround [In reply to]

On Fri, Dec 31, 2004 at 01:32:04PM -0800, Josh Chamas wrote:
> ivan-asp [at] 420 wrote:
> >Hi,
> >
> >Nested includes don't work as you would expect (well, at least they
> >don't work as *I* expected :). Given files
> >
> >/PATH/A
> >/PATH/DIR/B
> >/PATH/DIR/C
> >
>
> I believe your goal really is to really refactor includes elsewhere,

No, that's not my goal, that's a way of avoiding the problem. I'm happy
with my directory structure. I'm aware of the available workarounds and
my post even included one.

The problem is the "action-at-a-distance" when using nested includes,
in which includes behave differently depending on where they're called
from.

> I think really refactoring of these includes should put them into a path
> not browsable from the web, so should be ideally outside your main script
> area, not under it.

This doesn't work for me as I don't have this clear distinction between
"includes" and "top-level pages browseable from the web".

--
_ivan
Open-source billing, ticketing and provisioning
for ISPs, VoIP providers and online businesses
http://www.sisd.com/freeside/

---------------------------------------------------------------------
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.