Exporter::Auto - export all public functions from your package


    package Foo;
    use Exporter::Auto;

    sub foo { }

    package main;
    use Foo;
    foo();  # <= this function was exported!


Exporter::Auto is a simple replacement for Exporter that will export all public functions from your package. If you want all functions to be exported from your module by default, then this might be the module for you. If you only want some functions exported, or want tags, or to export variables, then you should look at one of the other Exporter modules ("SEE ALSO").

Let's say you have a library module with three functions, all of which you want to export by default. With Exporter, you'd write something like:

    package MyLibrary;
    use parent 'Exporter';
    our @EXPORT = qw/ foo bar baz /;
    sub foo { ... }
    sub bar { ... }
    sub baz { ... }

Every time you add a new function, you must remember to add it to @EXPORT. Not a big hassle, but a small inconvenience.

With Exporter::Auto you just write:

    package MyLibrary;
    use Exporter::Auto;
    sub foo { ... }
    sub bar { ... }
    sub baz { ... }

When you use Exporter::Auto it automatically adds an import function to your package, so you don't need to declare your package as a subclass.

That's it. If you want anything more fancy than this, it's time for another module.



Tokuhiro Matsuno <tokuhirom AAJKLFJEF@ GMAIL COM>


This module uses magical B::Hooks::EndOfScope. If you think this module is too clever, please try Module::Functions instead.


Exporter is the grandaddy of all Exporter modules, and bundled with Perl itself, unlike the rest of the modules listed here.

Sub::Exporter is a "sophisticated exporter for custom-built routines"; it lets you provide generators that can be used to customise what gets imported when someone uses your module.

Exporter::Tiny provides the same features as Sub::Exporter, but relying only on core dependencies.

Exporter::Declare provides Moose-style functions used to define what your module exports in a declarative way.

Exporter::Lite is a lightweight exporter module, falling somewhere between Exporter::Auto and Exporter.


Copyright (C) Tokuhiro Matsuno <TOKUHIROM @ GMAIL COM

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.