Re: Exporting in two packages but one file



On 05/08/2007 03:58 AM, Martin Barth wrote:
Hi all,

I have a Package A with serveral subs in it and now I want to make a package A::Types with some constants in it.

I have A.pm with:

..some code and subs ..

package A::Type;
use constant { CONST1 => "foo", CONST2 => "bar"};
package A;

..some more code and subs..



now I wanted to use the Exporter and wrote in the "package A::Type" part of the file:

sub BEGIN {
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(CONST1 CONST2);
our %EXPORT_TAGS = ( standard => [qw(CONST1 CONST2)]);
}

but now I dont know to import the stuff. I can't do a "use A::Type qw(:standard)" because I dont have A/Type.pm
do you have any suggestions how this can be done?

thanks for the help!
Martin


Import the stuff into A first, like so:

use strict;
use warnings;

package A::Type;
use constant { CONST1 => "foo", CONST2 => "bar"};
BEGIN {
use Exporter qw/import/;
our @EXPORT = qw/CONST1 CONST2/;
}

package A;

sub BEGIN {
use Exporter;
import A::Type qw/CONST1 CONST2/;

our @ISA = qw(Exporter);
our @EXPORT_OK = qw(CONST1 CONST2);
our %EXPORT_TAGS = ( standard => [qw(CONST1 CONST2)]);
}

1;

__HTH__

.



Relevant Pages

  • Re: unexpected error with Exporter
    ... use warnings; ... is no such package, nothing is imported. ... use Exporter; ... our @ISA = qw; ...
    (comp.lang.perl.misc)
  • Re: sorting data - hash vs. list
    ... > package and @ISA and import and Exporter and so on ... the only thing a well-defined class needs is a package. ... @EXPORT and Exporter are used to import non-OO symbols - i.e. functions ... > Perl doesn't actually implement objects, ...
    (comp.lang.perl.misc)
  • Re: Maple 8 | subs and matrices
    ... The linalg package is deprecated; you really should switch to the ... LinearAlgebra package. ... For example, suppose I derive a Jacobian matrix, ... > be able to subs in the values of various parameters. ...
    (sci.math.symbolic)
  • Exporting in two packages but one file
    ... I have a Package A with serveral subs in it and now I want to make a package A::Types with some constants in it. ... our @ISA = qw; ...
    (perl.beginners)
  • Newbie created one module but cant create another
    ... package Trace; ... require Exporter; ... @ISA = qw; ... package Strings; ...
    (comp.lang.perl.modules)