Hello All,

I'm having some trouble with a module where I need to implement a change. 
Basically, this module defines constants that other modules will use at a 
later time.

I need to detect parameters in the import() sub (that's the requested 
change) and, if the case, redefine some of those constants.

I'm trying with evals but all I'm getting is a warning about "constant 
redefined", AND the constant is not really changing (it keeps its previous 
value).

Is there a way to correctly redefine a constant at import() time?

Here is a simple example of the scene:

Script.pl
-----------------
use strict;
use warnings;
use myModule constantA => 'foo';
-----------------

myModule.pm
-----------------
package myModule;
use strict;
use warnings;
use constant constantA => 'bar';

sub import {
    my %params = @_;
    if ($params{constantA}) {
        # This should change constantA from 'bar' to 'foo'
        eval 'use constant constantA => \''.$params{constantA}.'\'';
        warn $@ if $@;
    }
}
-----------------

Any comments are highly appreciated.

Thanks in advance,

Paco Zarabozo



_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to