.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "MooseX::Object::Pluggable 3pm" .TH MooseX::Object::Pluggable 3pm "2015-01-18" "perl v5.20.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" MooseX::Object::Pluggable \- Make your classes pluggable .SH "VERSION" .IX Header "VERSION" version 0.0014 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& package MyApp; \& use Moose; \& \& with \*(AqMooseX::Object::Pluggable\*(Aq; \& \& ... \& \& package MyApp::Plugin::Pretty; \& use Moose::Role; \& \& sub pretty{ print "I am pretty" } \& \& 1; \& \& # \& use MyApp; \& my $app = MyApp\->new; \& $app\->load_plugin(\*(AqPretty\*(Aq); \& $app\->pretty; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module is meant to be loaded as a role from Moose-based classes. It will add five methods and four attributes to assist you with the loading and handling of plugins and extensions for plugins. I understand that this may pollute your namespace, however I took great care in using the least ambiguous names possible. .SH "How plugins Work" .IX Header "How plugins Work" Plugins and extensions are just Roles by a fancy name. They are loaded at runtime on demand and are instance, not class based. This means that if you have more than one instance of a class they can all have different plugins loaded. This is a feature. .PP Plugin methods are allowed to \f(CW\*(C`around\*(C'\fR, \f(CW\*(C`before\*(C'\fR, \f(CW\*(C`after\*(C'\fR their consuming classes, so it is important to watch for load order as plugins can and will overload each other. You may also add attributes through \f(CW\*(C`has\*(C'\fR. .PP Please note that when you load at runtime you lose the ability to wrap \f(CW\*(C`BUILD\*(C'\fR and roles using \f(CW\*(C`has\*(C'\fR will not go through compile time checks like \f(CW\*(C`required\*(C'\fR and \f(CW\*(C`default\*(C'\fR. .PP Even though \f(CW\*(C`override\*(C'\fR will work, I \fB\s-1STRONGLY\s0\fR discourage its use and a warning will be thrown if you try to use it. This is closely linked to the way multiple roles being applied is handled and is not likely to change. \f(CW\*(C`override\*(C'\fR behavior is closely linked to inheritance and thus will likely not work as you expect it in multiple inheritance situations. Point being, save yourself the headache. .SH "How plugins are loaded" .IX Header "How plugins are loaded" When roles are applied at runtime an anonymous class will wrap your class and \&\f(CW\*(C`$self\->blessed\*(C'\fR, \f(CW\*(C`ref $self\*(C'\fR and \f(CW\*(C`$self\->meta\->name\*(C'\fR will no longer return the name of your object; they will instead return the name of the anonymous class created at runtime. See \f(CW\*(C`_original_class_name\*(C'\fR. .SH "Usage" .IX Header "Usage" For a simple example see the tests included in this distribution. .SH "Attributes" .IX Header "Attributes" .SS "_plugin_ns" .IX Subsection "_plugin_ns" String. The prefix to use for plugin names provided. \f(CW\*(C`MyApp::Plugin\*(C'\fR is sensible. .SS "_plugin_app_ns" .IX Subsection "_plugin_app_ns" An ArrayRef accessor that automatically dereferences into array on a read call. By default it will be filled with the class name and its precedents. It is used to determine which directories to look for plugins as well as which plugins take precedence upon namespace collisions. This allows you to subclass a pluggable class and still use its plugins while using yours first if they are available. .SS "_plugin_locator" .IX Subsection "_plugin_locator" An automatically built instance of Module::Pluggable::Object used to locate available plugins. .SS "_original_class_name" .IX Subsection "_original_class_name" Because of the way roles apply, \f(CW\*(C`$self\->blessed\*(C'\fR, \f(CW\*(C`ref $self\*(C'\fR and \f(CW\*(C`$self\->meta\->name\*(C'\fR will no longer return what you expect. Instead, upon instantiation, the name of the class instantiated will be stored in this attribute if you need to access the name the class held before any runtime roles were applied. .SH "Public Methods" .IX Header "Public Methods" .ie n .SS "load_plugins @plugins" .el .SS "load_plugins \f(CW@plugins\fP" .IX Subsection "load_plugins @plugins" .ie n .SS "load_plugin $plugin" .el .SS "load_plugin \f(CW$plugin\fP" .IX Subsection "load_plugin $plugin" Load the appropriate role for \f(CW$plugin\fR. .SH "Private Methods" .IX Header "Private Methods" There's nothing stopping you from using these, but if you are using them for anything that's not really complicated you are probably doing something wrong. .ie n .SS "_role_from_plugin $plugin" .el .SS "_role_from_plugin \f(CW$plugin\fP" .IX Subsection "_role_from_plugin $plugin" Creates a role name from a plugin name. If the plugin name is prepended with a \f(CW\*(C`+\*(C'\fR it will be treated as a full name returned as is. Otherwise a string consisting of \f(CW$plugin\fR prepended with the \f(CW\*(C`_plugin_ns\*(C'\fR and the first valid value from \f(CW\*(C`_plugin_app_ns\*(C'\fR will be returned. Example .PP .Vb 2 \& #assuming appname MyApp and C<_plugin_ns> \*(AqPlugin\*(Aq \& $self\->_role_from_plugin("MyPlugin"); # MyApp::Plugin::MyPlugin .Ve .ie n .SS "_load_and_apply_role @roles" .el .SS "_load_and_apply_role \f(CW@roles\fP" .IX Subsection "_load_and_apply_role @roles" Require \f(CW$role\fR if it is not already loaded and apply it. This is the meat of this module. .SS "_build_plugin_app_ns" .IX Subsection "_build_plugin_app_ns" Automatically builds the _plugin_app_ns attribute with the classes in the class precedence list that are not part of Moose. .SS "_build_plugin_locator" .IX Subsection "_build_plugin_locator" Automatically creates a Module::Pluggable::Object instance with the correct search_path. .SS "meta" .IX Subsection "meta" Keep tests happy. See Moose .SH "SEE ALSO" .IX Header "SEE ALSO" Moose, Moose::Role, Class::Inspector .SH "BUGS" .IX Header "BUGS" Holler? .PP Please report any bugs or feature requests to \&\f(CW\*(C`bug\-MooseX\-Object\-Pluggable at rt.cpan.org\*(C'\fR, or through the web interface at . I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. .SH "SUPPORT" .IX Header "SUPPORT" You can find documentation for this module with the perldoc command. .PP .Vb 1 \& perldoc MooseX\-Object\-Pluggable .Ve .PP You can also look for information at: .IP "\(bu" 4 AnnoCPAN: Annotated \s-1CPAN\s0 documentation .Sp .IP "\(bu" 4 \&\s-1CPAN\s0 Ratings .Sp .IP "\(bu" 4 \&\s-1RT: CPAN\s0's request tracker .Sp .IP "\(bu" 4 Search \s-1CPAN\s0 .Sp .SH "ACKNOWLEDGEMENTS" .IX Header "ACKNOWLEDGEMENTS" .IP "#Moose \- Huge number of questions" 4 .IX Item "#Moose - Huge number of questions" .PD 0 .IP "Matt S Trout \- ideas / planning." 4 .IX Item "Matt S Trout - ideas / planning." .IP "Stevan Little \- \s-1EVERYTHING.\s0 Without him this would have never happened." 4 .IX Item "Stevan Little - EVERYTHING. Without him this would have never happened." .IP "Shawn M Moore \- bugfixes" 4 .IX Item "Shawn M Moore - bugfixes" .PD .SH "AUTHOR" .IX Header "AUTHOR" Guillermo Roditi .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2007 by Guillermo Roditi . .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" .IP "\(bu" 4 Karen Etheridge .IP "\(bu" 4 Shawn M Moore .IP "\(bu" 4 Yuval Kogman .IP "\(bu" 4 Robert Boone .IP "\(bu" 4 David Steinbrunner .IP "\(bu" 4 Todd Hepler