# perldoc > Exporter

---
type: CommandReference
command: Exporter
mode: perldoc
section: ""
source: perldoc
---

## Quick Reference

- `use Exporter; our @ISA = qw(Exporter);` — set up module to export via inheritance  
- `use Exporter 'import';` — get import method without inheritance  
- `our @EXPORT = qw(func $scalar);` — default exports  
- `our @EXPORT_OK = qw(func2);` — optional exports  
- `use Module qw(:DEFAULT :tag !symbol /pattern/);` — specialized import lists  
- `$package->export_to_level($level, $package, @what);` — export from custom import method  
- `use Module 1.09;` — version checking via import  

## Name

Exporter — Implements default import method for modules

## Synopsis

In module:

perl
package YourModule;
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(munge frobnicate);
Or without inheritance:

perl
package YourModule;
use Exporter 'import';
our @EXPORT_OK = qw(munge frobnicate);
In user code:

perl
use YourModule qw(frobnicate);
frobnicate($left, $right);
## Options

### Export Variables

- `@EXPORT` — list of symbols exported by default. Do not export method names or variables; prefer `@EXPORT_OK`.  
- `@EXPORT_OK` — list of symbols that can be exported on request.  
- `%EXPORT_TAGS` — hash of tag names to array references of symbol names; facilitates grouped imports. Tag names must also appear in `@EXPORT` or `@EXPORT_OK`.  
- `@EXPORT_FAIL` — list of symbols that cannot be exported (e.g., platform‑dependent constants). Triggers `export_fail` method.

### Methods

- `import` — called automatically on `use`; implements export logic.  
- `export_to_level($where, $package, @what)` — export symbols to a caller level above the current package; used in custom `import` methods.  
- `export_fail(@failed_symbols)` — called when symbols from `@EXPORT_FAIL` are requested; returns list of symbols that still fail. Override for custom handling.  
- `export_tags(@tags)` — adds symbols from named tags in `%EXPORT_TAGS` to `@EXPORT`.  
- `export_ok_tags(@tags)` — adds symbols from named tags to `@EXPORT_OK`.  
- `require_version($version)` — delegates to `VERSION`; used for version checking (historical, now `UNIVERSAL::VERSION`).

### Specialized Import List Syntax

In `use Module qw(...)`:

- `!name` — exclude name  
- `:DEFAULT` — all symbols from `@EXPORT`  
- `:tag` — all symbols from `$EXPORT_TAGS{tag}`  
- `/pattern/` — all symbols in `@EXPORT` and `@EXPORT_OK` matching pattern  

A leading `!` deletes matching names. If the first specification is a deletion, `:DEFAULT` is implied. Patterns typically need anchoring (e.g., `/^EXIT/`).

### Best Practices

- Use `BEGIN { require Exporter; @ISA = qw(Exporter); ... }` to avoid compile‑time pitfalls.  
- Prefer `use base` or `use parent` over manual `@ISA` setup.  
- Never export variable names (`$svar`, `%hvar`); provide accessor methods instead.  
- Use `@EXPORT_OK` over `@EXPORT`; avoid polluting the user’s namespace.

## Examples

### Basic Module Setup

perl
package YourModule;
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT    = qw(func1 $scalar);
our @EXPORT_OK = qw(func2 @array);
### Using import Without Inheritance

perl
package YourModule;
use Exporter 'import';
our @EXPORT_OK = qw(munge);
### Specialized Import Lists

perl
use Module qw(:DEFAULT :T2 !B3 A3);
use Socket qw(!/^[AP]F_/ !SOMAXCONN !SOL_SOCKET);
### Exporting From Custom import Method

perl
package A;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw($b);
sub import {
    $A::b = 1;
    A->export_to_level(1, @_);
}
### Version Checking

perl
use YourModule 1.09;
### AUTOLOADed Constants Workaround

perl
BEGIN { SO_LINGER }   # force AUTOLOAD before optimization
## See Also

- [Exporter::Easy](https://www.chedong.com/phpMan.php/perldoc/Exporter%3A%3AEasy/markdown)  
- [Exporter::Lite](https://www.chedong.com/phpMan.php/perldoc/Exporter%3A%3ALite/markdown)  
- [Exporter::Renaming](https://www.chedong.com/phpMan.php/perldoc/Exporter%3A%3ARenaming/markdown)  
- [Exporter::Tidy](https://www.chedong.com/phpMan.php/perldoc/Exporter%3A%3ATidy/markdown)  
- [Sub::Exporter](https://www.chedong.com/phpMan.php/perldoc/Sub%3A%3AExporter/markdown) / [Sub::Installer](https://www.chedong.com/phpMan.php/perldoc/Sub%3A%3AInstaller/markdown)  
- [Perl6::Export](https://www.chedong.com/phpMan.php/perldoc/Perl6%3A%3AExport/markdown) / [Perl6::Export::Attrs](https://www.chedong.com/phpMan.php/perldoc/Perl6%3A%3AExport%3A%3AAttrs/markdown)