Questions tagged [perl-exporter]

The Exporter module implements an import method which allows a module to export functions and variables to its users' namespaces. Many modules use Exporter rather than implementing their own import method because Exporter provides a highly flexible interface, with an implementation optimised for the common case.

Introduction

The Exporter module implements an import method which allows a module to export functions and variables to its users' namespaces.

Many modules use Exporter rather than implementing their own import method because Exporter provides a highly flexible interface, with an implementation optimised for the common case.

Perl automatically calls the import method when processing a use statement for a module. Modules and use are documented in perlfunc and perlmod. Understanding the concept of modules and how the use statement operates is important to understanding the Exporter.

Usage

The arrays @EXPORT and @EXPORT_OK in a module hold lists of symbols that are going to be exported into the users name space by default, or which they can request to be exported, respectively.

The symbols can represent functions, scalars, arrays, hashes, or typeglobs. The symbols must be given by full name with the exception that the ampersand in front of a function is optional, e.g.

See more

9 questions
9
votes
1 answer

In Perl, why do I need Exporter?

I have a module called hsfSubs.pm in my perl\lib folder. I have nothing in the module but subroutines and 1; at the end. One subroutine, for example, is named pause. I have implemented no import or export routines. In my main programs, I simply say…
user1067305
  • 3,233
  • 7
  • 24
  • 29
9
votes
3 answers

What is the most efficient way to export all constants (Readonly variables) from Perl module

I am looking the most efficient and readable way to export all constants from my separate module,that is used only for storing constants. For instance use strict; use warnings; use Readonly; Readonly our $MY_CONSTANT1 =>…
CROSP
  • 4,499
  • 4
  • 38
  • 89
3
votes
2 answers

how to access variables in imported module in local scope in perl?

I am stuck while creating a perl Moose module. I have a global pm module. package XYZ; require Exporter; our @ISA = qw(Exporter); ## EDIT missed this line our @EXPORT_OK = qw($VAR); my $VAR1 = 1; our $VAR = {'XYZ' => $VAR1}; 1; I want to get $VAR…
justrajdeep
  • 855
  • 3
  • 12
  • 29
2
votes
3 answers

Perl Exporter use variables from @EXPORT_OK in a subclass

I have looked for the last few hours and I am stumped. I did see How can I share variables between a base class and subclass in Perl? but it does not answer my question I am trying to write a utility module (testing purposes at this point) for use…
Speeddymon
  • 496
  • 2
  • 20
2
votes
3 answers

How to conditionally import functions from another module and export them to the local namespace

Assume I have a module named Local that exports a subroutine subLocal via the %EXPORT_TAGS interface. This module is closely related to another module named Remote that defines subroutines the user of Local might want to import. There are two…
ardnew
  • 2,028
  • 20
  • 29
0
votes
1 answer

How to redefine sub in my own package but access the old one out of the new

I have some code file beginning like use my_pck; BEGIN { package my_pck; my(@p) = (); foreach ( keys(%my_pck::) ) { push( @p, "\$$_" ) if (defined $$_); push( @p, "\%$_" ) if (%$_); push( @p, "\@$_" ) if (@$_); …
Andy A.
  • 1,392
  • 5
  • 15
  • 28
0
votes
1 answer

Using module in the same directory. "Undefined subroutine called at"

I have test_utils.pm: package TestUtils; use strict; use warnings; use Exporter 'import'; our @EXPORT = qw / print_diagnostic /; sub print_diagnostic { } And I'd like to call print_diagnostic from my main script tester.pl which…
Alexey
  • 1,198
  • 1
  • 15
  • 35
0
votes
1 answer

Want to access a hash from a named list of constants which are located in a separate perl module

I am trying to figure out how to access an error from a list of errors (a constant list). By access I mean that I have a new() method which outputs/creates an error that is posted. My new method does not match up properly with the way my list 'code'…
Paul Russell
  • 179
  • 10
0
votes
1 answer

Perl Export Suggestions

I am working with a new program that needs to interface with perl. The example code suggests that all of the methods will be exported to the global namespace like below: use BGPmon::Fetch; my $ret = init_bgpdata(); my $ret = connect_bgpdata(); my…
Tyler Scott
  • 1,046
  • 17
  • 33