Click here to get back home

AppConfig: how to reset object?

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
AppConfig: how to reset object? Jeff Boes 10-01-2004
Posted by Jeff Boes on October 1, 2004, 9:20 am
Please log in for more thread options
Hmm, I just found, much to my surprise, that an AppConfig object retains state
for *absent* parameters. E.g.,

my $cfg = AppConfig->new();
$cfg->define('foo');
$cfg->define('bar');
$cfg->args([qw(--foo --bar)]);
if ($cfg->foo) { print "yesn"; }
$cfg->args([qw(--bar)]);
if ($cfg->foo) { print "yesn"; }

This will print "yes" twice; I had thought that the second "args" method would
start with a fresh state.

Is there some way (besides recreating the object with "new") to reset the state
so all config variables are undefined? I suppose I could write one myself using
"varlist", but it seems like it ought to be already in there, somewhere.

--
Jeff Boes vox 269.226.9550 ext 24
Database Engineer fax 269.349.9076
Nexcerpt, Inc. http://www.nexcerpt.com
...Nexcerpt... Extend your Expertise


Posted by Ted Zlatanov on October 4, 2004, 3:10 pm
Please log in for more thread options
On Fri, 01 Oct 2004, jboes@qtm.net wrote:

> Hmm, I just found, much to my surprise, that an AppConfig object retains state
> for *absent* parameters. E.g.,
>
>$cfg->args([qw(--bar)]);
> if ($cfg->foo) { print "yesn"; }
>
> This will print "yes" twice; I had thought that the second "args" method would
> start with a fresh state.

Your first statement and the example are not the same. args() is not
documented to remove parameters, only to read new ones in.

> Is there some way (besides recreating the object with "new") to reset the
>         state
> so all config variables are undefined? I suppose I could write one myself using
> "varlist", but it seems like it ought to be already in there, somewhere.

Use new() or access the internal hash directly (not recommended). I
think that if you are removing parameters, you are probably not using
AppConfig properly - it's not a general purpose data storage solution,
only a configuration parameter parsing module.

Ted


Similar ThreadsPosted
Is there a better way to reset CGI object for AJAX POSTDATA? December 21, 2007, 6:10 pm
AppConfig September 17, 2006, 11:37 am
AppConfig failure with ARGCOUNT_LIST May 22, 2007, 10:33 am
Module install problem - AppConfig October 19, 2005, 2:04 pm
RFC: Bridge AppConfig and Config::Model November 22, 2007, 7:33 am
AppConfig loading undef values into ARGCOUNT_LIST March 22, 2007, 2:54 pm
Can't find loadable object November 19, 2004, 1:05 pm
ANNOUNCE: Rose::DB::Object March 21, 2005, 4:24 pm
Can't locate loadable object August 4, 2005, 12:18 am
Set::Object installation Problem October 14, 2006, 6:04 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap