Linux SoftwareProgrammingLibrariesSub::Exporter::Tutorial 0.970

Sub::Exporter::Tutorial 0.970


Sub::Exporter::Tutorial is a friendly guide to exporting with Sub::Exporter. What's an Exporter? When you use a module, first i
Developer:   Ricardo SIGNES
      more software by author →
Price:  0.00
License:   Perl Artistic License
File size:   34K
Language:   
OS:   
Rating:   0 /5 (0 votes)
Your vote:  
enlarge screenshot


Sub::Exporter::Tutorial is a friendly guide to exporting with Sub::Exporter.

What's an Exporter?

When you use a module, first it is required, then its import method is called. The Perl documentation tells us that the following two lines are equivalent:

use Module LIST;

BEGIN { require Module; Module->import(LIST); }

The import method is the module's exporter.

The Basics of Sub::Exporter

Sub::Exporter builds a custom exporter which can then be installed into your module. It builds this method based on configuration passed to its setup_exporter method.

A very basic use case might look like this:

package Addition;
use Sub::Exporter;
Sub::Exporter::setup_exporter({ exports => [ qw(plus) ]});

sub plus { my ($x, $y) = @_; return $x + $y; }

This would mean that when someone used your Addition module, they could have its plus routine imported into their package:

use Addition qw(plus);

my $z = plus(2, 2); # this works, because now plus is in the main package

That syntax to set up the exporter, above, is a little verbose, so for the simple case of just naming some exports, you can write this:

use Sub::Exporter -setup => { exports => [ qw(plus) ] };
...which is the same as the original example -- except that now the exporter is built and installed at compile time. Well, that and you typed less.

Using Export Groups

You can specify whole groups of things that should be exportable together. These are called groups. Exporter calls these tags. To specify groups, you just pass a groups key in your exporter configuration:

package Food;
use Sub::Exporter -setup => {
exports => [ qw(apple banana beef fluff lox rabbit) ],
groups => {
fauna => [ qw(beef lox rabbit) ],
flora => [ qw(apple banana) ],
}
};

Now, to import all that delicious foreign meat, your consumer needs only to write:

use Food qw(:fauna);
use Food qw(-fauna);

Either one of the above is acceptable. A colon is more traditional, but barewords with a leading colon can't be enquoted by a fat arrow. We'll see why that matters later on.

Groups can contain other groups. If you include a group name (with the leading dash or colon) in a group definition, it will be expanded recursively when the exporter is called. The exporter will not recurse into the same group twice while expanding groups.

There are two special groups: all and default. The all group is defined by default, and contains all exportable subs. You can redefine it, if you want to export only a subset when all exports are requested. The default group is the set of routines to export when nothing specific is requested. By default, there is no default group.

Requirements:
  • Perl
    tags sub exporter  the exporter  exporter setup  use sub  you can  apple banana  lox rabbit  use food  default group  groups you  the same  exporter sub  import method  

    Download Sub::Exporter::Tutorial 0.970


     http://ftp.casaafacerilor.ro/mirrors/CPAN/authors/id/R/RJ/RJBS/Sub-Exporter-0.970.tar.gz


    Authors software

    Net::Delicious::Simple 0.01 (by Ricardo SIGNES)
    Net::Delicious::Simple is a Net::Delicious for backups.

    SYNOPSIS

    use Net::Delicious::Simple;
    my $del = Net::Delicious->new(u

    Math::TotalBuilder::Common 1.10 (by Ricardo SIGNES)

    Math::TotalBuilder 1.10 (by Ricardo SIGNES)
    Math::TotalBuilder is a Perl module to build a whole total out of valued pieces.

    SYNOPSIS

    use Math::TotalBuilder;

    my %lsd

    Sub::Exporter::Tutorial 0.970 (by Ricardo SIGNES)
    Sub::Exporter::Tutorial is a friendly guide to exporting with Sub::Exporter.

    What's an Exporter?

    When you use a module, first i

    Sub::Exporter 0.970 (by Ricardo SIGNES)
    Sub::Exporter is a sophisticated exporter for custom-built routines.

    SYNOPSIS

    Sub::Exporter must be used in two places


    Similar software

    Sub::Exporter::Tutorial 0.970 (by Ricardo SIGNES)
    Sub::Exporter::Tutorial is a friendly guide to exporting with Sub::Exporter.

    What's an Exporter?

    When you use a module, first i

    Exporter::Easy 0.16 (by Fergal Daly)
    Exporter::Easy is a Perl module that takes the drudgery out of Exporting symbols.

    SYNOPSIS

    In module YourModule.pm:
    package

    Sub::Exporter 0.970 (by Ricardo SIGNES)
    Sub::Exporter is a sophisticated exporter for custom-built routines.

    SYNOPSIS

    Sub::Exporter must be used in two places

    BBDB::Export 0.012 (by wu)
    BBDB::Export is a Perl module to export data from The Insidious Big Brother Database.

    SYNOPSIS

    use BBDB::Export;

    # expor

    Password Exporter 1.0.4 (by Justin Scott)
    Password Exporter is a Thunderbird extension that allows you to export and import your saved passwords and rejected sites between com

    Test::Builder 0.64 (by chromatic and Michael G Schwern)
    Test::Builder is a backend for building test libraries.

    SYNOPSIS

    package My::Test::Module;
    use Test::Builder;
    require E

    PSA::Test::Builder 0.49_01 (by chromatic and Michael G Schwern)
    PSA::Test::Builder is a backend for building test libraries.

    SYNOPSIS

    package My::Test::Module;
    use PSA::Test::Builder;

    JasperReports 1.2.8 (by Teodor Danciu)

    Class::ObjectTemplate 0.7 (by Jason E. Stewart)

    GENE Graph Export Engine 0.3 (by Martin Vysny)
    GENE Graph Export Engine is an advanced XML exporter.

    GENE Graph Export Engine is a complex convertor/framework for multi-namespac


    Other software in this category

    zlib 1.2.3 (by Jean-loup Gailly)
    zlib is designed to be a free, general-purpose, legally unencumbered, lossless data-compression library for use on virtually any comp

    libjpeg v6b (by Independent JPEG Group)
    libjpeg is a library for handling the JPEG (JFIF) image format

    OpenSSL 0.9.7c (by The OpenSSL Project Team)
    The OpenSSL Project is a collaborative effort to develop a robust, commercial-grade, full-featured, and Open Source toolkit implement

    libxml2 2.6.27 (by DV)
    Libxml2 is the XML C parser and toolkit developed for the Gnome project (but usable outside of the Gnome platform), libxml2 library i

    GNU C library 2.4 (by Andreas Jaeger)
    GNU C library (glibc) is one of the most important components of GNU Hurd and most modern Linux distributions.

    GNU C library is us

  •     search


    Featured Software

    jEdit 4.3 pre8
    jEdit is an Open Source text editor written in Java

    Opera 9.02
    Surf the Internet in a safer, faster, and easier way with Opera browser

    GNU Aspell 0.60.4
    GNU Aspell is a Free and Open Source spell checker designed to eventually replace Ispell


    Subscribe in Rojo
    Google Reader
    Add to My Yahoo!

    Add to My AOL
    Subscribe with Bloglines
    Subscribe in NewsGator Online
    Add 'nixbit linux software' to Newsburst from CNET News.com
    del.icio.us nixbit linux software


    Top tags