Hi,
     There are few things are missing; please check with the following code:

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

sub import {
 shift; #The first argument is class name; so eliminate it
    my %params = @_;
 if (defined($params{'constantA'})) {
  # This should change constantA from 'bar' to 'foo'
  eval 'use constant constantA => \''.$params{constantA}.'\'';
  warn $@ if $@;
  print $params{'constantA'} . "\n";
 } 
}

1;  #this return statement is essential to every module

Thanks and Regards,
G. Indra
------------------------------------------------------------
 
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
 
       
---------------------------------
 Bring your gang together - do your thing.  Start your group.
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to