Re: Question about open()

2008-02-11 Thread Perrin Harkins
On Feb 10, 2008 12:37 PM, Mag Gam [EMAIL PROTECTED] wrote:
 I am trying to change DocumentRoot because, currently I am using open()  to
 load templates for my website. I have header, menu, footer in 3 seperate
 files, and I generate content like that. It works fine now, just not too
 dynamic when I want to move the stuff around. I have
 open(/var/www/perl/header.file) hardcoded, which is a pain. I just want
 open (header.file).

 If I do open(header.file) its trying to read from DocumentRoot ie.
 /var/www/header.inc, which does not exist.

That's not related to DocumentRoot.  The open() command opens files
relative to your current working directory.  If you use
ModPerl::RegsitryPreFork, that will be the same directory your script
is in.  Alternatively, you can chdir() to the directory you want.
What you're trying to do right now with DocumentRoot should be done
with chdir() instead.

- Perrin


Re: Question about open()

2008-02-10 Thread Mag Gam
I am taking the Apache2::Request method, and will integrate the DB solution
as Chandra mentioned.



#!/usr/bin/perl -w
use strict;
use CGI;
use Apache2::Request;
use Data::Dumper;

print Content-type: text/html\n\n;
my Apache2::Request $r = shift;
my $docroot = $r-document_root('/var/www/html/perl');
print $docroot;

For some reason, its still defaulting to /var/www/html. I need it to goto
/var/www/html/perl

Any thoughts?




On Feb 7, 2008 5:14 PM, Chandrakumar Muthaiah [EMAIL PROTECTED]
wrote:


 Perrin Harkins wrote:
  On Feb 6, 2008 10:06 PM, Mag Gam [EMAIL PROTECTED] wrote:
 
  Currently, when I open a file I have to use the
  absolute  path (/var/www/appname/top.inc). Is it possible for me to use
 just
  'top.inc'?
 
 
  You can either use DocumentRoot
  (
 http://perl.apache.org/docs/2.0/api/Apache2/RequestUtil.html#C_document_root_
 )
  or use ModPerl::RegistryPreFork which will chdir to the directory your
  script is in just like a normal CGI script does.  That would let you
  use files relative to the script.
 
  - Perrin
 

 Few quirks with document root. Your application may not be hosted under
 document root. you may have all your templates and customizations some
 where else.

 I think better option would be to define the template/support files
 location in Directory Configuration or in a Database configuration
 table. That would be more staple solution.

 in your .htaccess or on the Location/Directory Configuration put a line
 that says

 PerlSetVar AppsSupportFiles /home/httpd/support/site1/template


 and access this parameter from your $r-dir_config('AppsSupportFiles')


 I think this may be more customizable and scalable solution to your
 problem

 -Chandra



Re: Question about open()

2008-02-10 Thread Perrin Harkins
On Feb 10, 2008 12:24 PM, Mag Gam [EMAIL PROTECTED] wrote:
 my $docroot = $r-document_root('/var/www/html/perl');

Why are you trying to change the DocumentRoot?

- Perrin


Re: Question about open()

2008-02-10 Thread Mag Gam
Thanks for the quick response Perrin.

I am trying to change DocumentRoot because, currently I am using open()  to
load templates for my website. I have header, menu, footer in 3 seperate
files, and I generate content like that. It works fine now, just not too
dynamic when I want to move the stuff around. I have
open(/var/www/perl/header.file) hardcoded, which is a pain. I just want
open (header.file).

If I do open(header.file) its trying to read from DocumentRoot ie.
/var/www/header.inc, which does not exist.





On Feb 10, 2008 12:32 PM, Perrin Harkins [EMAIL PROTECTED] wrote:

 On Feb 10, 2008 12:24 PM, Mag Gam [EMAIL PROTECTED] wrote:
  my $docroot = $r-document_root('/var/www/html/perl');

 Why are you trying to change the DocumentRoot?

 - Perrin



Re: Question about open()

2008-02-10 Thread Foo JH

I do keep my templates in other directories also.

1. If your directories are relative to the document root, and you can 
take advantage of this fact by rendering a variable to remember the 
template path.
2. If your template directories have nothing in common with the document 
root, then you can set the variable via SetPerlVar within http.conf. 
That takes the 'hard' out of your code. :)





Mag Gam wrote:

Thanks for the quick response Perrin.
 
I am trying to change DocumentRoot because, currently I am using 
open()  to load templates for my website. I have header, menu, footer 
in 3 seperate files, and I generate content like that. It works fine 
now, just not too dynamic when I want to move the stuff around. I have 
open(/var/www/perl/header.file) hardcoded, which is a pain. I just 
want open (header.file).
 
If I do open(header.file) its trying to read from DocumentRoot ie. 
/var/www/header.inc, which does not exist.
 
 



 
On Feb 10, 2008 12:32 PM, Perrin Harkins [EMAIL PROTECTED] 
mailto:[EMAIL PROTECTED] wrote:


On Feb 10, 2008 12:24 PM, Mag Gam [EMAIL PROTECTED]
mailto:[EMAIL PROTECTED] wrote:
 my $docroot = $r-document_root('/var/www/html/perl');

Why are you trying to change the DocumentRoot?

- Perrin






Re: Question about open()

2008-02-07 Thread Perrin Harkins
On Feb 6, 2008 10:06 PM, Mag Gam [EMAIL PROTECTED] wrote:
 Currently, when I open a file I have to use the
 absolute  path (/var/www/appname/top.inc). Is it possible for me to use just
 'top.inc'?

You can either use DocumentRoot
(http://perl.apache.org/docs/2.0/api/Apache2/RequestUtil.html#C_document_root_)
or use ModPerl::RegistryPreFork which will chdir to the directory your
script is in just like a normal CGI script does.  That would let you
use files relative to the script.

- Perrin


Re: Question about open()

2008-02-07 Thread Chandrakumar Muthaiah


Perrin Harkins wrote:

On Feb 6, 2008 10:06 PM, Mag Gam [EMAIL PROTECTED] wrote:
  

Currently, when I open a file I have to use the
absolute  path (/var/www/appname/top.inc). Is it possible for me to use just
'top.inc'?



You can either use DocumentRoot
(http://perl.apache.org/docs/2.0/api/Apache2/RequestUtil.html#C_document_root_)
or use ModPerl::RegistryPreFork which will chdir to the directory your
script is in just like a normal CGI script does.  That would let you
use files relative to the script.

- Perrin
  


Few quirks with document root. Your application may not be hosted under 
document root. you may have all your templates and customizations some 
where else.


I think better option would be to define the template/support files 
location in Directory Configuration or in a Database configuration 
table. That would be more staple solution.


in your .htaccess or on the Location/Directory Configuration put a line 
that says


PerlSetVar AppsSupportFiles /home/httpd/support/site1/template


and access this parameter from your $r-dir_config('AppsSupportFiles')


I think this may be more customizable and scalable solution to your problem

-Chandra


Re: Question about open()

2008-02-07 Thread brett lee

Another option:

my $HEADER= $ENV{DOCUMENT_ROOT}/header.shtml;

- Original Message 
From: Roberto C. Sánchez [EMAIL PROTECTED]
To: modperl@perl.apache.org
Sent: Wednesday, February 6, 2008 8:10:08 PM
Subject: Re: Question about open()


On 
Wed, 
Feb 
06, 
2008 
at 
10:06:05PM 
-0500, 
Mag 
Gam 
wrote:
 
Hi 
All,
 
 
I 
have 
been 
using 
mod_perl, 
and 
I 
have 
several 
perl-cgi 
files 
that 
use 
the
 
open(). 
I 
use 
this 
function 
to 
open/include 
my 
header, 
footer, 
basically 
a
 
poor 
man 
template 
system. 
Currently, 
when 
I 
open 
a 
file 
I 
have 
to 
use 
the
 
absolute  
path 
(/var/www/appname/top.inc). 
Is 
it 
possible 
for 
me 
to 
use 
just
 
'top.inc'? 
I 
think 
it 
trying 
to 
read 
from 
DocumentRoot, 
which 
is 
causing 
the
 
issue. 
Has 
anyone 
ever 
faced 
this?
 
I 
just 
set 
something 
like 
this 
in 
global.asa:

my 
$base_dir 
= 
cwd 
. 
'/';

Then 
I 
can 
make 
the 
$base_dir 
available 
globally 
and 
just 
use 
that
anywhere 
I 
need 
to 
refer 
to 
an 
on 
disk 
file.

Regards,

-Roberto

-- 
Roberto 
C. 
Sánchez
http://people.connexer.com/~roberto
http://www.connexer.com





  

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 



Question about open()

2008-02-06 Thread Mag Gam
Hi All,

I have been using mod_perl, and I have several perl-cgi files that use the
open(). I use this function to open/include my header, footer, basically a
poor man template system. Currently, when I open a file I have to use the
absolute  path (/var/www/appname/top.inc). Is it possible for me to use just
'top.inc'? I think it trying to read from DocumentRoot, which is causing the
issue. Has anyone ever faced this?

TIA


Re: Question about open()

2008-02-06 Thread Roberto C . Sánchez
On Wed, Feb 06, 2008 at 10:06:05PM -0500, Mag Gam wrote:
 Hi All,
 
 I have been using mod_perl, and I have several perl-cgi files that use the
 open(). I use this function to open/include my header, footer, basically a
 poor man template system. Currently, when I open a file I have to use the
 absolute  path (/var/www/appname/top.inc). Is it possible for me to use just
 'top.inc'? I think it trying to read from DocumentRoot, which is causing the
 issue. Has anyone ever faced this?
 
I just set something like this in global.asa:

my $base_dir = cwd . '/';

Then I can make the $base_dir available globally and just use that
anywhere I need to refer to an on disk file.

Regards,

-Roberto

-- 
Roberto C. Sánchez
http://people.connexer.com/~roberto
http://www.connexer.com


signature.asc
Description: Digital signature


Re: Question about open()

2008-02-06 Thread Roberto C . Sánchez
On Wed, Feb 06, 2008 at 10:47:08PM -0500, Mag Gam wrote:
 What is global.asa?
 
 Sorry, I am somewhat new at this...
 
My mistake.  I am using Apache::ASP (which is built on mod_perl) for
my pages.  Sorry for the confusion.

Regards,

-Roberto

-- 
Roberto C. Sánchez
http://people.connexer.com/~roberto
http://www.connexer.com


signature.asc
Description: Digital signature