1MooseX::Object::PluggabUlsee(r3)Contributed Perl DocumenMtoaotsieoXn::Object::Pluggable(3)
2
3
4

NAME

6           MooseX::Object::Pluggable - Make your classes pluggable
7

SYNOPSIS

9           package MyApp;
10           use Moose;
11
12           with 'MooseX::Object::Pluggable';
13
14           ...
15
16           package MyApp::Plugin::Pretty;
17           use Moose::Role;
18
19           sub pretty{ print "I am pretty" }
20
21           1;
22
23           #
24           use MyApp;
25           my $app = MyApp->new;
26           $app->load_plugin('Pretty');
27           $app->pretty;
28

DESCRIPTION

30       This module is meant to be loaded as a role from Moose-based classes it
31       will add five methods and four attributes to assist you with the
32       loading and handling of plugins and extensions for plugins. I
33       understand that this may pollute your namespace, however I took great
34       care in using the least ambiguous names possible.
35

How plugins Work

37       Plugins and extensions are just Roles by a fancy name. They are loaded
38       at runtime on demand and are instance, not class based. This means that
39       if you have more than one instance of a class they can all have
40       different plugins loaded. This is a feature.
41
42       Plugin methods are allowed to "around", "before", "after" their
43       consuming classes, so it is important to watch for load order as
44       plugins can and will overload each other. You may also add attributes
45       through has.
46
47       Please note that when you load at runtime you lose the ability to wrap
48       "BUILD" and roles using "has" will not go through compile time checks
49       like "required" and <default>.
50
51       Even though "override" will work , I STRONGLY discourage it's use and a
52       warning will be thrown if you try to use it.  This is closely linked to
53       the way multiple roles being applied is handled and is not likely to
54       change. "override" bevavior is closely linked to inheritance and thus
55       will likely not work as you expect it in multiple inheritance
56       situations. Point being, save yourself the headache.
57

How plugins are loaded

59       When roles are applied at runtime an anonymous class will wrap your
60       class and "$self->blessed" and "ref $self" will no longer return the
61       name of your object, they will instead return the name of the anonymous
62       class created at runtime.  See "_original_class_name".
63

Usage

65       For a simple example see the tests included in this distribution.
66

Attributes

68   _plugin_ns
69       String. The prefix to use for plugin names provided. MyApp::Plugin is
70       sensible.
71
72   _plugin_app_ns
73       ArrayRef, Accessor automatically dereferences into array on a read
74       call.  By default will be filled with the class name and it's
75       prescedents, it is used to determine which directories to look for
76       plugins as well as which plugins take presedence upon namespace
77       collitions. This allows you to subclass a pluggable class and still use
78       it's plugins while using yours first if they are available.
79
80   _plugin_locator
81       An automatically built instance of Module::Pluggable::Object used to
82       locate available plugins.
83
84   _original_class_name
85       Because of the way roles apply "$self->blessed" and "ref $self" will no
86       longer return what you expect. Instead, upon instantiation, the name of
87       the class instantiated will be stored in this attribute if you need to
88       access the name the class held before any runtime roles were applied.
89

Public Methods

91   load_plugins @plugins
92   load_plugin $plugin
93       Load the apropriate role for $plugin.
94

Private Methods

96       There's nothing stopping you from using these, but if you are using
97       them for anything thats not really complicated you are probably doing
98       something wrong.
99
100   _role_from_plugin $plugin
101       Creates a role name from a plugin name. If the plugin name is prepended
102       with a "+" it will be treated as a full name returned as is. Otherwise
103       a string consisting of $plugin  prepended with the "_plugin_ns" and the
104       first valid value from "_plugin_app_ns" will be returned. Example
105
106          #assuming appname MyApp and C<_plugin_ns> 'Plugin'
107          $self->_role_from_plugin("MyPlugin"); # MyApp::Plugin::MyPlugin
108
109   _load_and_apply_role @roles
110       Require $role if it is not already loaded and apply it. This is the
111       meat of this module.
112
113   _build_plugin_app_ns
114       Automatically builds the _plugin_app_ns attribute with the classes in
115       the class presedence list that are not part of Moose.
116
117   _build_plugin_locator
118       Automatically creates a Module::Pluggable::Object instance with the
119       correct search_path.
120
121   meta
122       Keep tests happy. See Moose
123

SEE ALSO

125       Moose, Moose::Role, Class::Inspector
126

AUTHOR

128       Guillermo Roditi, <groditi@cpan.org>
129

BUGS

131       Holler?
132
133       Please report any bugs or feature requests to
134       "bug-moosex-object-pluggable at rt.cpan.org", or through the web
135       interface at
136       http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-Object-Pluggable
137       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-Object-
138       Pluggable>.  I will be notified, and then you'll automatically be
139       notified of progress on your bug as I make changes.
140

SUPPORT

142       You can find documentation for this module with the perldoc command.
143
144           perldoc MooseX-Object-Pluggable
145
146       You can also look for information at:
147
148       ·   AnnoCPAN: Annotated CPAN documentation
149
150           http://annocpan.org/dist/MooseX-Object-Pluggable
151           <http://annocpan.org/dist/MooseX-Object-Pluggable>
152
153       ·   CPAN Ratings
154
155           http://cpanratings.perl.org/d/MooseX-Object-Pluggable
156           <http://cpanratings.perl.org/d/MooseX-Object-Pluggable>
157
158       ·   RT: CPAN's request tracker
159
160           http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-Object-Pluggable
161           <http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-Object-Pluggable>
162
163       ·   Search CPAN
164
165           http://search.cpan.org/dist/MooseX-Object-Pluggable
166           <http://search.cpan.org/dist/MooseX-Object-Pluggable>
167

ACKNOWLEDGEMENTS

169       #Moose - Huge number of questions
170       Matt S Trout <mst@shadowcatsystems.co.uk> - ideas / planning.
171       Stevan Little - EVERYTHING. Without him this would have never happened.
172       Shawn M Moore - bugfixes
173
175       Copyright 2007 Guillermo Roditi.  All Rights Reserved.  This is free
176       software; you may redistribute it and/or modify it under the same terms
177       as Perl itself.
178
179
180
181perl v5.12.0                      2009-04-27      MooseX::Object::Pluggable(3)
Impressum