Exporte...ckStart(3)
π Exporter::Tiny::Manual::QuickStart π
okay bestie, gather round, because this is the User Contributed Perl Documentation entry for Exporter::Tiny::Manual::QuickStart β literally the quickest way to get up and running with Exporter::Tiny, no cap. π¦
β¨ NAME β¨
Exporter::Tiny::Manual::QuickStart β the quickest way to get up and running with Exporter::Tiny π
πΈ SYNOPSIS πΈ
package MyUtils;
use Exporter::Shiny qw( frobnicate );
sub frobnicate {
...; # your code here
}
1;
Now people can use your module like this:
use MyUtils "frobnicate";
frobnicate(42);
Or like this:
use MyUtils "frobnicate" => { -as => "frob" };
frob(42);
π DESCRIPTION π
See the synopsis. Yes, it's that simple. That's the whole vibe. π«Ά
π Next steps
π Default exports
Note that the module in the synopsis doesn't export anything by default. If people load MyUtils like this:
use MyUtils;
Then they haven't imported any functions. You can specify a default set of functions to be exported like this:
package MyUtils;
use Exporter::Shiny qw( frobnicate );
our @EXPORT = qw( frobnicate );
sub frobnicate { ... }
1;
Or, if you want to be a superstar rock god: π€
package MyUtils;
use Exporter::Shiny our @EXPORT = qw( frobnicate );
sub frobnicate { ... }
1;
π·οΈ Tags
You can provide tags for people to use:
package MyUtils;
use Exporter::Shiny qw( frobnicate red green blue );
our %EXPORT_TAGS = (
utils => [qw/ frobnicate /],
colours => [qw/ red green blue /],
);
sub frobnicate { ... }
sub red { ... }
sub green { ... }
sub blue { ... }
1;
And people can now import your functions like this:
use MyUtils ":colours";
Or this:
use MyUtils "-colours";
Or take advantage of the fact that Perl magically quotes barewords preceded by a hyphen:
use MyUtils -colours;
Two tags are automatically defined for you: -default (which is just the same as @EXPORT) and -all (which is the union of @EXPORT and @EXPORT_OK). If you don't like them, then you can override them:
our %EXPORT_TAGS = (
default => \@some_other_stuff,
all => \@more_stuff,
);
π§ Generators
Exporting normally just works by copying a sub from your package into your caller's package. But sometimes it's useful instead to generate a custom sub to insert into your caller's package. This is pretty easy to do.
package MyUtils;
use Exporter::Shiny qw( frobnicate );
sub _generate_frobnicate {
my ( $me, $name, $args, $globals ) = @_;
my $caller = $globals->{into};
return sub {
...; # your code here
};
}
1;
The parameter $me here is a string containing the package name which is being imported from; $caller is the destination package; $name is the name of the sub (in this case "frobnicate"); and $args is a custom argument for this function. (By convention, $args is normally a hashref.)
# The hashref { foo => 42 } is $args above.
#
use MyUtils "frobnicate" => { foo => 42 };
π Avoiding Exporter::Shiny
Exporter::Shiny is a tiny shim around Exporter::Tiny. It should mostly do what you want, but you may sometimes prefer to use Exporter::Tiny directly.
The example in the synopsis could have been written as:
package MyUtils;
use parent "Exporter::Tiny";
our @EXPORT_OK = qw( frobnicate );
sub frobnicate {
...; # your code here
}
1;
What Exporter::Shiny does is mostly just to set @EXPORT_OK for you and set up inheritance from the base class (Exporter::Tiny).
Exporter::Shiny also sets $INC{'MyUtils.pm'} for you, which in usually makes little difference, but is useful in some edge cases.
π SEE ALSO π
https://exportertiny.github.io/ β go look, it's giving documentation energy β¨
Exporter::Shiny, Exporter::Tiny.
For more advanced information, see Exporter::Tiny::Manual::Exporting.
π AUTHOR π
Toby Inkster <tobyink@cpan.org>. π
π COPYRIGHT AND LICENCE π
This software is copyright (c) 2013-2014, 2017, 2022-2025 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
π DISCLAIMER OF WARRANTIES π
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
like. no promises bestie. that's the whole disclaimer. periodt. π
and that's the tea β this was perl v5.42.0, dated 2026-01-17, from your friendly neighborhood Exporte...ckStart(3) page. mwah π
β¨
π¦ where this page comes from
- fedora 44: perl-Exporter-Tiny 1.006003-2.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms