in reply to use constant and exporter

Your EXPORT_OK statement is incorrect. It should look like this:
our @EXPORT_OK = @{ $EXPORT_TAGS{'all'} };
The extra "qw" around it messes it up. I tried your example after making that correction (in perl 5.6.1, also defining each one on one line) and the constants imported correctly.

Replies are listed 'Best First'.
Re: Re: use constant and exporter
by Flame (Deacon) on Jan 28, 2003 at 04:52 UTC
    Ok, the code now reads:
    package MyPackage; use Data::Dumper; use 5.006; #use Data::Validate::OO::Tests; use Tests; #use constant { # VALID => 1, # INVALID => 2, # ERROR => 0, # }; use constant VALID => 1; use constant INVALID => 2; use constant ERROR => 0; use strict; use warnings; require Exporter; use AutoLoader qw(AUTOLOAD); our @ISA = qw(Exporter); our %EXPORT_TAGS = ( 'all' => ['VALID','INVALID','ERROR'], 'codes' => ['VALID','INVALID','ERROR'], ); our @EXPORT_OK = @{ $EXPORT_TAGS{'all'} }; our @EXPORT = qw(); #Intentionally left blank our $VERSION = v0.0.1;
    And I'm testing it with this:
    use MyPackage qw(:all); use Data::Dumper; use strict; use warnings; print STDOUT VALID;


    It still yields the same error...



    My code doesn't have bugs, it just develops random features.

    Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)

      I took your example exactly Flame, except that I commented out the "use Tests" (I don't have that module) and the "use Autoloader" (it causes errors if the package isn't installed, and I was testing it from the current directory). The example worked with no problem.

      (It also works with MyPackage::VALID, but I wouldn't call that an import.)

      I'm wondering if perhaps you aren't testing the package you think you are. Is the right copy of MyPackage.pm in your @INC path first? Did you reinstall the package after making the changes?

        The package is in the same directory as the one I'm testing this in. It's part of my testing as I write mypackage (named, for now, Data::Validate::OO). (Reference: Data Validation Tests, further references linked to from there.)

        I'll see what happens if I remove a few lines here and there...



        My code doesn't have bugs, it just develops random features.

        Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)

      use MyPackage qw(:all); use Data::Dumper; use strict; use warnings; print STDOUT MyPackage::VALID;

      Untested.

      John J Reiser
      newrisedesigns.com

        Well that does work, but I was hopeing to actually be able to export it...



        My code doesn't have bugs, it just develops random features.

        Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)