RE: requre,use, modules, namespace...I'm confused...
I have same question.And my solution: 1.In httpd.conf PerlAddVar conf /home/httpd/site1/cgi-bin/configure.cgi PerlAddVar conf /home/httpd/site2/cgi-bin/configure.cgi PerlAddVar conf /home/httpd/site3/cgi-bin/configure.cgi 2.In your test.cgi use vars qw(%conf); my $site = $ENV{'HTTP_HOST'}; # get site1,site2,etc. ($site) = ($site =~ /^\/(.*?)\.some\.dom\/cgi-bin\/i); use Apache; my $r = Apache-request(); my @conf_file = $r-dir_config-get('conf'); foreach (@conf_file) { # import all site configuration file require; } no strict qw(refs); # import configure variable # call by $conf{'SOME_VAR'}; *conf = \%{${conf::.$site.::conf}}; 3.In your site1 configure.cgi,use ref of hash package conf::site1; $conf = { # web name. 'web_name' = 'site1', # Parent web link. 'web_link' = 'http://site1.some.dom/', } # in different configure.cgi,have different configure variable and package. And ,Please referer http://perl.apache.org/guide/,and thanks stas and other. -Original Message- From: swade [mailto:[EMAIL PROTECTED]] Sent: 2001Äê7ÔÂ2ÈÕ 13:18 To: [EMAIL PROTECTED] Subject: requre,use, modules, namespace...I'm confused... Hi, I've read the docs on traps in using require and use, etc in mod_perl...I'm confused heres what I'm trying to figure out... lets say I have 3 sites on 1 box. so I have /home/httpd/site1 /home/httpd/site2 /home/httpd/site3 each of them host the same scripts. so if my script is test.cgi /home/httpd/site1/cgi-bin/test.cgi /home/httpd/site2/cgi-bin/test.cgi etc Now without mod_perl I have a file called configure.cgi in /home/httpd/site1/cgi-bin/configure.cgi etc...for other sites. each configure script is setup differently according to the site. usually I would do, require configure.cgi in the test.cgi script; but it's my understanding this won't work in mod_perl what I'm trying to do is figure out how to have test.cgi the same...and pull what it needs from the configure file. So that when I update test.cgi I can ftp it to all the sites without having to change it for each site. For the life of me I cannot figure out how it's done in mod_perl without having namespace problems... I read that you should use a module, but then I understand you cannot have modules with the same name. I read you could also give package name in the configure.cgi script..like package config; Will that have the same namespace problem? Is there some info on how to do this someone could point me to? thanks, shawn
In module require configuration file
Hi all: In mod-perl,my module (mymodule.pm) will read config var from a file ( require conf.pm).I put the require in my new() function. In one instance,they will work well. But ,I will run two or more instance (the two conf.pm is different.),the mymodule.pm will have error.Because it require conf.pm and maybe get other conf.pm. I am test false in redhat 7,the apache is 1.3.14 and mod-perl is 1.24. And re-compile apache 1.3.20 and mod-perl 1.25,and test false also. But I am test in Mandrake 8 ,the apache is 1.3.19 and mod-perl is 1.25.The two instance has worked! I wonder,why redhat un-support two instance and Mandrake is well? Thanks and sorry for my english. The sample code: = #!/usr/bin/perl # mymodule.pm Package mymodule; sub new { my $type = shift; my $self = {}; require ./conf.pm; bless $self,$type; } = #!/usr/bin/perl # conf.pm # configuration file one package conf; use strict; use vars qw($conf); # defined configure variable $conf = { # web name. 'web_name' = 'foo.com', } #!/usr/bin/perl # conf.pm # configuration file two package conf; use strict; use vars qw($conf); # defined configure variable $conf = { # web name. 'web_name' = 'foo.com', } = #!/usr/bin/perl # mycgi.pl use mymodule; my $m = mymodule-new(); print $conf::conf-{'web_name'}; ==
: In module require configuration file
Sorry.I find ,require different configuration file in module is impossibility. Have a mistake ,my mandrake box run in cgi environment as a result of apache configure. So ,in mod-perl,I dont find any way require different configuration. -ÔʼÓʼþ- ·¢¼þÈË: Wang Xingyu ÍõÐËÓî [ÉϺ£] ·¢ËÍʱ¼ä: 2001Äê6ÔÂ5ÈÕ 15:22 ÊÕ¼þÈË: [EMAIL PROTECTED] Ö÷Ìâ: In module require configuration file Hi all: In mod-perl,my module (mymodule.pm) will read config var from a file ( require conf.pm).I put the require in my new() function. In one instance,they will work well. But ,I will run two or more instance (the two conf.pm is different.),the mymodule.pm will have error.Because it require conf.pm and maybe get other conf.pm. I am test false in redhat 7,the apache is 1.3.14 and mod-perl is 1.24. And re-compile apache 1.3.20 and mod-perl 1.25,and test false also. But I am test in Mandrake 8 ,the apache is 1.3.19 and mod-perl is 1.25.The two instance has worked! I wonder,why redhat un-support two instance and Mandrake is well? Thanks and sorry for my english. The sample code: = #!/usr/bin/perl # mymodule.pm Package mymodule; sub new { my $type = shift; my $self = {}; require ./conf.pm; bless $self,$type; } = #!/usr/bin/perl # conf.pm # configuration file one package conf; use strict; use vars qw($conf); # defined configure variable $conf = { # web name. 'web_name' = 'foo.com', } #!/usr/bin/perl # conf.pm # configuration file two package conf; use strict; use vars qw($conf); # defined configure variable $conf = { # web name. 'web_name' = 'foo.com', } = #!/usr/bin/perl # mycgi.pl use mymodule; my $m = mymodule-new(); print $conf::conf-{'web_name'}; ==
: e?: In module require configuration file [frig]
TKS, Why use Data::Dumper ? -原始邮件- 发件人: Jamie LeTual [mailto:[EMAIL PROTECTED]] 发送时间: 2001年6月6日 11:53 收件人: Wang Xingyu íõÐËóî [éϺ£]; [EMAIL PROTECTED] 主题: Re: ′e?′: In module require configuration file [frig] typos, sorry. Damned cut and paste Jamie LeTual wrote: How about this: #=== mymodule.pm = package mymodule; use strict; sub new { my $type = shift; my $conf = shift; my $self = { conf = require $conf }; bless $self, $type; return $self; } 1; #=== conf.pl = { web_name = 'foo.com' }; - #=== conf.pm = + #=== somefile.pl = #!/usr/bin/perl use strict; use Data::Dumper; use mymodule; - my $m = mymodule-new('conf.pm'); + my $m = mymodule-new('conf.pl'); print Dumper($m); ... -- -[sent from home]--- | Jamie LeTual |Email : [EMAIL PROTECTED] | | Programmeur Errant |Phone : (514) 523-0940 | | |PGP : http://people.hbe.ca/~jamie | |__||
: : In module require configuration file
Maybe I should use ''PerlSetVar''. I will think it. -ÔʼÓʼþ- ·¢¼þÈË: Mike Christine [mailto:[EMAIL PROTECTED]] ·¢ËÍʱ¼ä: 2001Äê6ÔÂ6ÈÕ 11:49 ÊÕ¼þÈË: Wang Xingyu ÍõÐËÓî [ÉϺ£]; [EMAIL PROTECTED] Ö÷Ìâ: Re: ´ð¸´: In module require configuration file and also http:// thingy.kcilink.com/modperlguide/perl/Using_Non_Hardcoded_Confi guratio.html - Original Message - From: Wang Xingyu ÍõÐËÓî [ÉϺ£] [EMAIL PROTECTED] To: Wang Xingyu ÍõÐËÓî [ÉϺ£] [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Tuesday, June 05, 2001 9:15 PM Subject: ´ð¸´: In module require configuration file Sorry.I find ,require different configuration file in module is impossibility. Have a mistake ,my mandrake box run in cgi environment as a result of apache configure. So ,in mod-perl,I dont find any way require different configuration. -?-¨º?¨®¨º?t- ¡¤¡é?t¨¨?: Wang Xingyu ¨ª?D?¨®? [¨¦?o¡ê] ¡¤¡é?¨ª¨º¡À??: 2001?¨º6??5¨¨? 15:22 ¨º??t¨¨?: [EMAIL PROTECTED] ?¡Â¨¬a: In module require configuration file Hi all: In mod-perl,my module (mymodule.pm) will read config var from a file ( require conf.pm).I put the require in my new() function. In one instance,they will work well. But ,I will run two or more instance (the two conf.pm is different.),the mymodule.pm will have error.Because it require conf.pm and maybe get other conf.pm. I am test false in redhat 7,the apache is 1.3.14 and mod-perl is 1.24. And re-compile apache 1.3.20 and mod-perl 1.25,and test false also. But I am test in Mandrake 8 ,the apache is 1.3.19 and mod-perl is 1.25.The two instance has worked! I wonder,why redhat un-support two instance and Mandrake is well? Thanks and sorry for my english. The sample code: = #!/usr/bin/perl # mymodule.pm Package mymodule; sub new { my $type = shift; my $self = {}; require ./conf.pm; bless $self,$type; } = #!/usr/bin/perl # conf.pm # configuration file one package conf; use strict; use vars qw($conf); # defined configure variable $conf = { # web name. 'web_name' = 'foo.com', } #!/usr/bin/perl # conf.pm # configuration file two package conf; use strict; use vars qw($conf); # defined configure variable $conf = { # web name. 'web_name' = 'foo.com', } = #!/usr/bin/perl # mycgi.pl use mymodule; my $m = mymodule-new(); print $conf::conf-{'web_name'}; ==