You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Scott Alexander <sc...@musiciansfriend.com> on 2000/06/23 02:08:06 UTC

using a module to contain settings.

I'm working on creating a site that is completely done in mod perl.

The area that I'm running into problems with is using a single 
module to store configuration information. ie where images are 
stored. oracle settings, color codes etc.  All the settings that are 
valid accross the entire site.

The way i've been trying to do this is to create a module 
Mf7::Globals and then store the data inside.
I then have an Initialize_globals function that I run to reset all the 
variables at the begining of a request.

I thought I should be able to access them using 
$Mf7::Globals::imgserver but this just errors out with unitialized 
variable.

So what method are you guys using to store sitewide variables?

Scott

Re: using a module to contain settings.

Posted by Scott Alexander <sc...@musiciansfriend.com>.
On 23 Jun 2000, at 13:27, Perrin Harkins wrote:
> On Fri, 23 Jun 2000, Scott Alexander wrote:
> Okay, this is an easy one.  You are declaring $imgserver as a lexical (my)
> variable.  When Perl finishes executing this file, lexical variables go
> out of scope.  You can fix this by making it a real global like $VERSION,
> either with a use vars or with fully-qualified variable names.  You could
> still use lexicals if you create subroutine closures to provide access to
> them, but I think using globals is simpler.
ok.  switching them to a use vars section did the trick.

> > > Incidentally, the MF site is pretty fast.  Is it running on mod_perl now?
> > Yep. Mod_perl and Apache::Registry saved us from having to get a 
> > ton of new hardware.
> You should submit something for the "success stories" and "sites running
> mod_perl" pages on http://perl.apache.org/.  You might get a few free
> clicks for your trouble.
In the two months since we brought this site live,  the four of us 
doing the programming really haven't had enough time to do that.  
Hopefully we can get to posting a bit about it soon.

Scott

Re: using a module to contain settings.

Posted by Scott Alexander <sc...@musiciansfriend.com>.
On 23 Jun 2000, at 14:45, Craig McLane wrote:
> You could also export the variables (in which case @EXPORT_OK is
> preferable to @EXPORT).  It still needs to be a global variable, but you
> won't need to refer to it with a fully qualified name.
This is how we did the current site, and while it worked,  i'd rather 
have it be a single use statement at the root and then just have to 
qualify them later.

Scott


Re: using a module to contain settings.

Posted by Craig McLane <cm...@citysearch.com>.
You could also export the variables (in which case @EXPORT_OK is
preferable to @EXPORT).  It still needs to be a global variable, but you
won't need to refer to it with a fully qualified name.

Craig



On Fri, 23 Jun 2000, Perrin Harkins wrote:

> On Fri, 23 Jun 2000, Scott Alexander wrote:
> 
> > package Mf7::Globals;
> > use strict;
> > use vars qw($VERSION);
> > 	my (
> > 	$imgserver,
> > 	);
> > $VERSION = '0.01';
> > sub Initialize_globals {
> > $imgserver = 'http://www.musiciansfriend.com';
> > }
> > 1;
> 
> Okay, this is an easy one.  You are declaring $imgserver as a lexical (my)
> variable.  When Perl finishes executing this file, lexical variables go
> out of scope.  You can fix this by making it a real global like $VERSION,
> either with a use vars or with fully-qualified variable names.  You could
> still use lexicals if you create subroutine closures to provide access to
> them, but I think using globals is simpler.
> 
> > > Incidentally, the MF site is pretty fast.  Is it running on mod_perl now?
> > Yep. Mod_perl and Apache::Registry saved us from having to get a 
> > ton of new hardware.
> 
> You should submit something for the "success stories" and "sites running
> mod_perl" pages on http://perl.apache.org/.  You might get a few free
> clicks for your trouble.
> 
> - Perrin
> 


Re: using a module to contain settings.

Posted by Perrin Harkins <pe...@primenet.com>.
On Fri, 23 Jun 2000, Scott Alexander wrote:

> package Mf7::Globals;
> use strict;
> use vars qw($VERSION);
> 	my (
> 	$imgserver,
> 	);
> $VERSION = '0.01';
> sub Initialize_globals {
> $imgserver = 'http://www.musiciansfriend.com';
> }
> 1;

Okay, this is an easy one.  You are declaring $imgserver as a lexical (my)
variable.  When Perl finishes executing this file, lexical variables go
out of scope.  You can fix this by making it a real global like $VERSION,
either with a use vars or with fully-qualified variable names.  You could
still use lexicals if you create subroutine closures to provide access to
them, but I think using globals is simpler.

> > Incidentally, the MF site is pretty fast.  Is it running on mod_perl now?
> Yep. Mod_perl and Apache::Registry saved us from having to get a 
> ton of new hardware.

You should submit something for the "success stories" and "sites running
mod_perl" pages on http://perl.apache.org/.  You might get a few free
clicks for your trouble.

- Perrin


Re: using a module to contain settings.

Posted by Scott Alexander <sc...@musiciansfriend.com>.
On 22 Jun 2000, at 17:51, Perrin Harkins wrote:
> On Thu, 22 Jun 2000, Scott Alexander wrote:
> > I then have an Initialize_globals function that I run to reset all the
> > variables at the begining of a request.
> Why would you reset all of your configuration globals at the beginning of
> a request?
Safety more then anything else.  This just makes sure that If 
anything gets changed in the previous request,  it doesn't affect the 
other requests.
 
> > I thought I should be able to access them using
> > $Mf7::Globals::imgserver but this just errors out with unitialized
> > variable.
> That should work.  Maybe you could post a little code snippet?  You are
> using actual global variables in Mf7::Globals, right?
np. I removed everything but the imgserver variable out of it.  
otherwise it was/is pretty big.
package Mf7::Globals;
use strict;
use vars qw($VERSION);
	my (
	$imgserver,
	);
$VERSION = '0.01';
sub Initialize_globals {
$imgserver = 'http://www.musiciansfriend.com';
}
1;
__END__
 
then a test i've been running:
#!/usr/local/bin/perl -w
use Mf7::Globals;
use strict;
Mf7::Globals::Initialize_globals();
print "$Mf7::Globals::imgserver\n";

This sends :
Use of uninitialized value in concatenation (.) 
at test.file line 5.


If it came down to it,  I can make the change as 
this code isn't near going live yet, but i'd 
prefer to keep them referenced this way since 
I've already made it through all the files(29) 
and updated all of them to be 
$Mf7::Globals::varname.

> Incidentally, the MF site is pretty fast.  Is it running on mod_perl now?
Yep. Mod_perl and Apache::Registry saved us from having to get a 
ton of new hardware.  I don't remember my exact benchmarks, but 
we were hitting huge loads on the code base before Mod_perl with 
just a couple of hits(it was in development, so we were just testing) 
 once we moved to mod perl,  we only had one real questionable 
time where our load hit 160.  Once we brought in the second box 
though,  our load has been nothing.

Scott


Re: using a module to contain settings.

Posted by Ian Kallen <sp...@salon.com>.
I've taken a liking to setting up a centralized config that puts various
package globals where I want them

# contents of Foo::Config
{
  package Foo::Zip;
  use vars qw($got $no $guitar $strings);
  $got='ernie';
  $no='ball';
  $guitar='or';
  $strings='markly';
}

{
  package Foo::Zap;
  use vars qw($bang $boom $bash);
  # etc
}

I'll likely use constant.pm next time I rev the code instead of using
vars.
-Ian


Scott Alexander wrote:
> 
> I'm working on creating a site that is completely done in mod perl.
> 
> The area that I'm running into problems with is using a single
> module to store configuration information. ie where images are
> stored. oracle settings, color codes etc.  All the settings that are
> valid accross the entire site.
> 
> The way i've been trying to do this is to create a module
> Mf7::Globals and then store the data inside.
> I then have an Initialize_globals function that I run to reset all the
> variables at the begining of a request.
> 
> I thought I should be able to access them using
> $Mf7::Globals::imgserver but this just errors out with unitialized
> variable.
> 
> So what method are you guys using to store sitewide variables?
> 
> Scott

--
Salon Internet 				http://www.salon.com/
  Manager, Software and Systems "Livin' La Vida Unix!"
Ian Kallen <id...@salon.com> / AIM: iankallen / Fax: (415) 354-3326

Re: using a module to contain settings.

Posted by Ged Haywood <ge...@jubileegroup.co.uk>.
Hi all,

On Thu, 22 Jun 2000, Frank Wiles wrote:

> Where I work we store them as PerlSetVar's in the Apache config, we
> store all implementation specific things in there such as the page
> title, the URL to the module we are using, database user and
> password, etc, etc.

Like Frank I've used PerlSetVar, adding mod_macro to configure
multiple sites which have similar features (holiday travel business).

73,
Ged.



Re: using a module to contain settings.

Posted by Frank Wiles <fr...@wiles.org>.
 .------[ Scott Alexander wrote (2000/06/22 at 17:08:06) ]------
 | 
 |  So what method are you guys using to store sitewide variables?
 |  
 `-------------------------------------------------

	Where I work we store them as PerlSetVar's in the Apache config,
	we store all implementation specific things in there such as the
	page title, the URL to the module we are using, database user and
	password, etc, etc.  

	This makes for *VERY* portable modules, I would definately suggest
	it over using a separate module for this. 

 -------------------------------
  Frank Wiles <fr...@wiles.org>
  http://frank.wiles.org
 -------------------------------


Re: using a module to contain settings.

Posted by Peter Schoenster <bo...@errorcode.com>.
----- Original Message -----
From: Scott Alexander <sc...@musiciansfriend.com>

> The area that I'm running into problems with is using a single
> module to store configuration information. ie where images are
> stored. oracle settings, color codes etc.  All the settings that are
> valid accross the entire site.

Take a look here:

http://perl.apache.org/guide/porting.html#Configuration_Files_Writing_Dy

You might want to post the relevant code since you sound like you are doing
just like I do.

Peter


Re: using a module to contain settings.

Posted by Perrin Harkins <pe...@primenet.com>.
On Thu, 22 Jun 2000, Scott Alexander wrote:

> The way i've been trying to do this is to create a module Mf7::Globals
> and then store the data inside.

That should work fine.

> I then have an Initialize_globals function that I run to reset all the
> variables at the begining of a request.

Why would you reset all of your configuration globals at the beginning of
a request?

> I thought I should be able to access them using
> $Mf7::Globals::imgserver but this just errors out with unitialized
> variable.

That should work.  Maybe you could post a little code snippet?  You are
using actual global variables in Mf7::Globals, right?

Incidentally, the MF site is pretty fast.  Is it running on mod_perl now?

- Perrin


Re: using a module to contain settings.

Posted by Stas Bekman <st...@stason.org>.
On Thu, 22 Jun 2000, Scott Alexander wrote:

> I'm working on creating a site that is completely done in mod perl.
> 
> The area that I'm running into problems with is using a single 
> module to store configuration information. ie where images are 
> stored. oracle settings, color codes etc.  All the settings that are 
> valid accross the entire site.
> 
> The way i've been trying to do this is to create a module 
> Mf7::Globals and then store the data inside.
> I then have an Initialize_globals function that I run to reset all the 
> variables at the begining of a request.
> 
> I thought I should be able to access them using 
> $Mf7::Globals::imgserver but this just errors out with unitialized 
> variable.
> 
> So what method are you guys using to store sitewide variables?

http://thingy.kcilink.com/modperlguide/perl/Using_the_Perl_Aliasing_Feature_.html
http://thingy.kcilink.com/modperlguide/porting/Writing_Configuration_Files.html
http://thingy.kcilink.com/modperlguide/config/PerlSetVar_PerlSetEnv_and_PerlP.html

_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide 
mailto:stas@stason.org   http://perl.org     http://stason.org/TULARC
http://singlesheaven.com http://perlmonth.com http://sourcegarden.org