Re: [yapcom] Some thoughts about PATH_INFO

[prev] [thread] [next] [lurker] [Date index for 2003/12/6]

From: Shlomi Fish
Subject: Re: [yapcom] Some thoughts about PATH_INFO
Date: 21:12 on 06 Dec 2003
--Boundary-00=_5oi0/D6PLWPM3UF
Content-Type: text/plain;
  charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On Saturday 06 December 2003 18:19, jon@xxxxxx.xx.xx wrote:
> > Hi all!
> >
> > First of all, I think we should retrieve the path info by using the
> > CGI.pm interface:
> >
> > http://search.cpan.org/~lds/CGI.pm-3.00/CGI.pm#FETCHING_ENVIRONMENT_VA
> > RIABLES
> >
> > (look for path_info()).
>
> I can't see why I would want to import an entire module, or even a
> function to retrieve a single variable already available to my
> script.
>

Like Richard said, the CGI.pm instance is already available in 
CGI::Application in the $self->query() variable.

> > Secondly, I'm not sure we need the CGI_PATH config variable, as we can
> > determine it from the $q->script_name() (that uses $ENV{SCRIPT_NAME}),
> > and together with PATH_INFO (as is commonly found throughout the code)
> > from the $ENV{REQUEST_URI} variable (which does not seem to have a
> > CGI.pm equivalent).
>
> The reason for the cg_path variable will become apparent when I
> finish adding "skins" to the site, which will allow you to switch
> between different templates, which will require different PATH_INFO's
> like:
>
> foo/BLUE/index
>
> and
>
> foo/FRENCH/index
>

I still don't see why it will necessitate the CGI_PATH variable. 

> > Otherwise, I think we should reduce the number of absolute links to a
> > minimum and use relative links instead. We can do this by calculating
> > the relative distance between two URLS and using ../ where
> > appropriate.
>
> This is not as easy as it seems. Could you be more specific as to how
> this works when your PATH_INFO has '/'s in it?
>

I'm attaching here a function that does just that, albeit it may need some 
adaptation. Basically, what you do is:

1. Split the URLs into components.

2. Remove identical beginning components.

3. Map the components of the source URL to ".."

4. Join the ..'s followed by the remaining dest components with /'s.

Regards,

	Shlomi Fish

---------------------------------------------------------------------
Shlomi Fish      shlomif@xxxx.xxx.xx
Homepage: http://t2.technion.ac.il/~shlomif/

I don't believe in fairies. Oops! A fairy died.
I don't believe in fairies. Oops! Another fairy died.



--Boundary-00=_5oi0/D6PLWPM3UF
Content-Type: text/x-perl;
  charset="utf-8";
  name="get_rel_url.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="get_rel_url.pl"

sub get_relative_url
{
    my $base = shift;
    my $to = shift;
    my @this_url = @{$base->get_url()};
    my @other_url = @{$to->get_url()};
    my $slash_terminated = shift;

    my $ret;
    
    while(
        scalar(@this_url) &&
        scalar(@other_url) &&
        ($this_url[0] eq $other_url[0])
    )
    {
        shift(@this_url);
        shift(@other_url);
    }

    if (($base->{'mode'} eq "harddisk") && ($to->is_dir()))
    {
        push @other_url, "index.html";
    }

    $ret = "";

    if ($slash_terminated)
    {
        if ((scalar(@this_url) == 0) && (scalar(@other_url) == 0))
        {
            $ret = "./";
        }
        else
        {
            $ret .= join("/", (map { ".." } @this_url), @other_url);         
            if ($to->is_dir() && ($base->{'mode'} ne "harddisk"))
            {
                $ret .= "/";
            }
        }
    }
    else
    {
        my @components = ((map { ".." } @this_url[1..$#this_url]), @other_url);
        $ret .= ("./" . join("/", @components)); 
        if (($to->is_dir()) && ($base->{'mode'} ne "harddisk") && scalar(@components))
        {
            $ret .= "/";
        }
    }

    #if (($to->is_dir()) && (scalar(@other_url) || $slash_terminated))

    return $ret;
}


--Boundary-00=_5oi0/D6PLWPM3UF--

There's stuff above here

Generated at 21:25 on 07 Dec 2003 by mariachi 0.51