-
-
07 Nov 2021 03:41:58 UTC
- Distribution: Moose
- Module version: 2.2201
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues (71)
- Testers (2641 / 3 / 1)
- Kwalitee
Bus factor: 3- 92.11% Coverage
- License: perl_5
- Perl: v5.8.3
- Activity
24 month- Tools
- Download (881.54KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 142 contributors-
Stevan Little
-
Dave Rolsky
-
Jesse Luehrs
-
Shawn M Moore
-
יובל קוג'מן (Yuval Kogman)
-
Florian Ragwitz
-
Hans Dieter Pearcey
-
Chris Prather
-
Matt S Trout
-
Upasana Shukla
-
Graham Knop
-
Tomas Doran
-
Ricardo Signes
-
Guillermo Roditi
-
John Napiorkowski
-
Aankhen
-
Todd Hepler
-
Jonathan Rockway
-
Gerda Shank
-
Perlover
-
Shlomi Fish
-
Brad Bowman
-
Justin Hunter
-
Kent Fredric
-
Paul Driver
-
Anders Nor Berle
-
Brian Manning
-
gfx
-
Jay Hannah
-
Lars Dɪᴇᴄᴋᴏᴡ 迪拉斯
-
Leon Brocard
-
Olivier Mengué
-
Rafael Kitover
-
Christian Hansen
-
Cory Watson
-
Dagfinn Ilmari Mannsåker
-
Paul Jamieson Fenwick
-
Robert Buels
-
Dan Dascalescu
-
Marcel Grünauer
-
Scott McWhirter
-
Ævar Arnfjörð Bjarmason
-
Daisuke Maki (lestrrat)
-
Dylan William Hardison
-
Patrick Donelan
-
Stefan O'Rear
-
Tokuhiro Matsuno
-
Ash Berlin
-
Chris Weyl
-
Eric Wilhelm
-
Jess Robinson
-
Marc Mims
-
Marcus Ramberg
-
Mark Allen
-
Mateu X Hunter
-
matthof
-
Robert 'phaylon' Sedlacek
-
Zachary Lome
-
Aran Clary Deltac
-
Chip
-
Christopher J. Madsen
-
Curtis Jewell
-
Evan Carroll
-
Mark A. Stratman
-
Mark Fowler
-
Matthew Horsfall
-
mauke
-
Michael LaGrasta
-
Michael Rykov
-
Mike Whitaker
-
Moritz Onken
-
Nelo Onyiah
-
Nick Perez
-
Robert Boone
-
Robin V
-
rodrigolive
-
shelling
-
Thomas Sibley
-
Tom Hukins
-
Wallace Reis
-
Aaron Cohen
-
Adam J. Foxson
-
Adam Kennedy
-
Andy Jack
-
Anirvan Chatterjee
-
Ansgar Burchardt
-
A. Sinan Unur
-
Ben Hutton
-
Brendan Byrd
-
Chad Granum
-
Chankey Pathak
-
Chia-liang Kao
-
Christian Walde (Mithaldu)
-
chromatic
-
Dann
-
Dave Romano
-
David Leadbeater
-
David Steinbrunner
-
dmaestro
-
E. Choroba
-
franck cuny
-
Frew Schmidt
-
gregor herrmann
-
hakim
-
Henry Van Styn
-
James Marca
-
Jason May
-
Jay Allen
-
Jay Kuri
-
Jeff Bisbee
-
Jens Berthold
-
Jesse Vincent
-
joel
-
John Douglas Porter
-
John Goulah
-
Justin DeVuyst
-
Kang-min Liu
-
Leon Timmermans
-
Mark O Grady
-
Matt Kraai
-
Michael Schout
-
Nathan Gray
-
Olaf Alders
-
Olof Johansson
-
Paul Cochrane
-
Paweł Murias
-
Pedro Melo
-
Peter Shangov
-
Philippe Bruhat (BooK)
-
Philipp Gortan
-
Phillip Smith
-
Piotr Roszatycki
-
pktm
-
rouzier
-
Sam Vilain
-
sherrardb
-
Simon Reinhardt
-
sue spence
-
Tuomas Jormola
-
wickline
-
Yanick Champoux
-
Zoffix Znet
- Dependencies
- Carp
- Class::Load
- Class::Load::XS
- Data::OptList
- Devel::GlobalDestruction
- Devel::OverloadInfo
- Devel::StackTrace
- Dist::CheckConflicts
- Eval::Closure
- List::Util
- MRO::Compat
- Module::Runtime
- Module::Runtime::Conflicts
- Package::DeprecationManager
- Package::Stash
- Package::Stash::XS
- Params::Util
- Scalar::Util
- Sub::Exporter
- Sub::Util
- Try::Tiny
- parent
- strict
- warnings
- Reverse dependencies
- CPAN Testers List
- Dependency graph
- NAME
- VERSION
- SYNOPSIS
- DESCRIPTION
- METHODS
- IMPORTING AND init_meta
- METACLASS TRAITS
- BUGS
- AUTHORS
- COPYRIGHT AND LICENSE
NAME
Moose::Exporter - make an import() and unimport() just like Moose.pm
VERSION
version 2.2201
SYNOPSIS
package MyApp::Moose; use Moose (); use Moose::Exporter; use Some::Random (); Moose::Exporter->setup_import_methods( with_meta => [ 'has_rw', 'sugar2' ], as_is => [ 'sugar3', \&Some::Random::thing, 'Some::Random::other_thing' ], also => 'Moose', ); sub has_rw { my ( $meta, $name, %options ) = @_; $meta->add_attribute( $name, is => 'rw', %options, ); } # then later ... package MyApp::User; use MyApp::Moose; has 'name' => ( is => 'ro' ); has_rw 'size'; thing; other_thing; no MyApp::Moose;
DESCRIPTION
This module encapsulates the exporting of sugar functions in a
Moose.pm
-like manner. It does this by building customimport
andunimport
methods for your module, based on a spec you provide.It also lets you "stack" Moose-alike modules so you can export Moose's sugar as well as your own, along with sugar from any random
MooseX
module, as long as they all useMoose::Exporter
. This feature exists to let you bundle a set of MooseX modules into a policy module that developers can use directly instead of using Moose itself.To simplify writing exporter modules,
Moose::Exporter
also importsstrict
andwarnings
into your exporter module, as well as into modules that use it.METHODS
This module provides two public methods:
Moose::Exporter->setup_import_methods(...)
When you call this method,
Moose::Exporter
builds customimport
andunimport
methods for your module. Theimport
method will export the functions you specify, and can also re-export functions exported by some other module (likeMoose.pm
). If you pass any parameters for Moose::Util::MetaRole, theimport
method will also call Moose::Util::MetaRole::apply_metaroles and Moose::Util::MetaRole::apply_base_class_roles as needed, after making sure the metaclass is initialized.The
unimport
method cleans the caller's namespace of all the exported functions. This includes any functions you re-export from other packages. However, if the consumer of your package also imports those functions from the original package, they will not be cleaned.Note that if any of these methods already exist, they will not be overridden, you will have to use
build_import_methods
to get the coderef that would be installed.This method accepts the following parameters:
with_meta => [ ... ]
This list of function names only will be wrapped and then exported. The wrapper will pass the metaclass object for the caller as its first argument.
Many sugar functions will need to use this metaclass object to do something to the calling package.
as_is => [ ... ]
This list of function names or sub references will be exported as-is. You can identify a subroutine by reference, which is handy to re-export some other module's functions directly by reference (
\&Some::Package::function
).If you do export some other package's function, this function will never be removed by the
unimport
method. The reason for this is we cannot know if the caller also explicitly imported the sub themselves, and therefore wants to keep it.trait_aliases => [ ... ]
This is a list of package names which should have shortened aliases exported, similar to the functionality of aliased. Each element in the list can be either a package name, in which case the export will be named as the last namespace component of the package, or an arrayref, whose first element is the package to alias to, and second element is the alias to export.
also => $name or \@names
This is a list of modules which contain functions that the caller wants to export. These modules must also use
Moose::Exporter
. The most common use case will be to export the functions fromMoose.pm
. Functions specified bywith_meta
oras_is
take precedence over functions exported by modules specified byalso
, so that a module can selectively override functions exported by another module.Moose::Exporter
also makes sure all these functions get removed whenunimport
is called.meta_lookup => sub { ... }
This is a function which will be called to provide the metaclass to be operated upon by the exporter. This is an advanced feature intended for use by package generator modules in the vein of MooseX::Role::Parameterized in order to simplify reusing sugar from other modules that use
Moose::Exporter
. This function is used, for example, to select the metaclass to bind to functions that are exported using thewith_meta
option.This function will receive one parameter: the class name into which the sugar is being exported. The default implementation is:
sub { Class::MOP::class_of(shift) }
Accordingly, this function is expected to return a metaclass.
You can also provide parameters for Moose::Util::MetaRole::apply_metaroles and Moose::Util::MetaRole::apply_base_class_roles. Specifically, valid parameters are "class_metaroles", "role_metaroles", and "base_class_roles".
Moose::Exporter->build_import_methods(...)
Returns three code refs, one for
import
, one forunimport
and one forinit_meta
.Accepts the additional
install
option, which accepts an arrayref of method names to install into your exporting package. The valid options areimport
andunimport
. Callingsetup_import_methods
is equivalent to callingbuild_import_methods
withinstall => [qw(import unimport)]
except that it doesn't also return the methods.The
import
method is built using Sub::Exporter. This means that it can take a hashref of the form{ into => $package }
to specify the package it operates on.Used by
setup_import_methods
.IMPORTING AND init_meta
If you want to set an alternative base object class or metaclass class, see above for details on how this module can call Moose::Util::MetaRole for you.
If you want to do something that is not supported by this module, simply define an
init_meta
method in your class. Theimport
method thatMoose::Exporter
generates for you will call this method (if it exists). It will always pass the caller to this method via thefor_class
parameter.Most of the time, your
init_meta
method will probably just callMoose->init_meta
to do the real work:sub init_meta { shift; # our class name return Moose->init_meta( @_, metaclass => 'My::Metaclass' ); }
METACLASS TRAITS
The
import
method generated byMoose::Exporter
will allow the user of your module to specify metaclass traits in a-traits
parameter passed as part of the import:use Moose -traits => 'My::Meta::Trait'; use Moose -traits => [ 'My::Meta::Trait', 'My::Other::Trait' ];
These traits will be applied to the caller's metaclass instance. Providing traits for an exporting class that does not create a metaclass for the caller is an error.
BUGS
See "BUGS" in Moose for details on reporting bugs.
AUTHORS
Stevan Little <stevan@cpan.org>
Dave Rolsky <autarch@urth.org>
Jesse Luehrs <doy@cpan.org>
Shawn M Moore <sartak@cpan.org>
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
Karen Etheridge <ether@cpan.org>
Florian Ragwitz <rafl@debian.org>
Hans Dieter Pearcey <hdp@cpan.org>
Chris Prather <chris@prather.org>
Matt S Trout <mstrout@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2006 by Infinity Interactive, Inc.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Module Install Instructions
To install Moose, copy and paste the appropriate command in to your terminal.
cpanm Moose
perl -MCPAN -e shell install Moose
For more information on module installation, please visit the detailed CPAN module installation guide.