Home: General Discussions: General Questions:
Contolling lib behavior using environment variables



gknopp
New User

Feb 21, 2007, 1:17 PM


Views: 7305
Contolling lib behavior using environment variables

I'll looking for folks opinion on whether the behavior of a module used in a script should ever be indirectly contolled using environment variables and not by the script itself.

I contend this is bad design and that all parameters whether they're retrieved from the enviroment or set on the command line should always pass through the script, where upon the script tells the modules what parameters settings to use.

Other folks contend that this requires more coding and maintenance at the script level. They believe that controlling behavior at the module level promotes better code reuse and thus a better design.

What's your opinion?


ProBulletin
Novice

Feb 23, 2007, 9:31 AM


Views: 7297
Re: [gknopp] Contolling lib behavior using environment variables

Could you give an example?


Regards,
Paul Wilson
ProBulletin Board: http://www.probulletin.com/


gknopp
New User

Feb 23, 2007, 10:23 AM


Views: 7295
Re: [ProBulletin] Contolling lib behavior using environment variables

One piece of information that I failed to include in my mail message was that these scripts are used to test a product.

> ./test.pl x=10

Sol'n 1
--------------------------
===test.pl===
...
$x=get_param("x");
$mylib_obj->myfunc(x=>$x);
...

===mylib.pm===
...
sub myfunc {
my($self,$x)=@_;
...
}

OR

Sol'n 2
---------------------
===test.pl===
...
$mylib_obj->myfunc();
...


===mylib===
...
$x=get_param("x");
sub myfunc {
my ($self)=@_;
...
}