1MooseX::NonMoose(3) User Contributed Perl Documentation MooseX::NonMoose(3)
2
3
4
6 MooseX::NonMoose - easy subclassing of non-Moose classes
7
9 version 0.15
10
12 package Term::VT102::NBased;
13 use Moose;
14 use MooseX::NonMoose;
15 extends 'Term::VT102';
16
17 has [qw/x_base y_base/] => (
18 is => 'ro',
19 isa => 'Int',
20 default => 1,
21 );
22
23 around x => sub {
24 my $orig = shift;
25 my $self = shift;
26 $self->$orig(@_) + $self->x_base - 1;
27 };
28
29 # ... (wrap other methods)
30
31 no Moose;
32 # no need to fiddle with inline_constructor here
33 __PACKAGE__->meta->make_immutable;
34
35 my $vt = Term::VT102::NBased->new(x_base => 0, y_base => 0);
36
38 "MooseX::NonMoose" allows for easily subclassing non-Moose classes with
39 Moose, taking care of the annoying details connected with doing this,
40 such as setting up proper inheritance from Moose::Object and installing
41 (and inlining, at "make_immutable" time) a constructor that makes sure
42 things like "BUILD" methods are called. It tries to be as non-intrusive
43 as possible - when this module is used, inheriting from non-Moose
44 classes and inheriting from Moose classes should work identically,
45 aside from the few caveats mentioned below. One of the goals of this
46 module is that including it in a Moose::Exporter-based package used
47 across an entire application should be possible, without interfering
48 with classes that only inherit from Moose modules, or even classes that
49 don't inherit from anything at all.
50
51 There are several ways to use this module. The most straightforward is
52 to just "use MooseX::NonMoose;" in your class; this should set up
53 everything necessary for extending non-Moose modules.
54 MooseX::NonMoose::Meta::Role::Class and
55 MooseX::NonMoose::Meta::Role::Constructor can also be applied to your
56 metaclasses manually, either by passing a "-traits" option to your "use
57 Moose;" line, or by applying them using Moose::Util::MetaRole in a
58 Moose::Exporter-based package. MooseX::NonMoose::Meta::Role::Class is
59 the part that provides the main functionality of this module; if you
60 don't care about inlining, this is all you need to worry about.
61 Applying MooseX::NonMoose::Meta::Role::Constructor as well will provide
62 an inlined constructor when you immutabilize your class.
63
64 "MooseX::NonMoose" allows you to manipulate the argument list that gets
65 passed to the superclass constructor by defining a "FOREIGNBUILDARGS"
66 method. This is called with the same argument list as the "BUILDARGS"
67 method, but should return a list of arguments to pass to the superclass
68 constructor. This allows "MooseX::NonMoose" to support superclasses
69 whose constructors would get confused by the extra arguments that Moose
70 requires (for attributes, etc.)
71
73 · Allow for constructors with names other than "new".
74
76 · The reference that the non-Moose class uses as its instance type
77 must match the instance type that Moose is using. Moose's default
78 instance type is a hashref, but other modules exist to make Moose
79 use other instance types. MooseX::InsideOut is the most general
80 solution - it should work with any class. For globref-based classes
81 in particular, MooseX::GlobRef will also allow Moose to work. For
82 more information, see the "032-moosex-insideout" and
83 "033-moosex-globref" tests bundled with this dist.
84
85 · Completely overriding the constructor in a class using
86 "MooseX::NonMoose" (i.e. using "sub new { ... }") currently doesn't
87 work, although using method modifiers on the constructor should
88 work identically to normal Moose classes.
89
90 · "MooseX::NonMoose" currently assumes in several places that the
91 superclass constructor will be called "new". This may be made
92 configurable in the future.
93
95 No known bugs.
96
97 Please report any bugs through RT: email "bug-moosex-nonmoose at
98 rt.cpan.org", or browse to
99 http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-NonMoose
100 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-NonMoose>.
101
103 · "How do I make non-Moose constructors work with Moose?" in
104 Moose::Cookbook::FAQ
105
106 · MooseX::Alien
107
108 serves the same purpose, but with a radically different (and far
109 more hackish) implementation.
110
112 You can find this documentation for this module with the perldoc
113 command.
114
115 perldoc MooseX::NonMoose
116
117 You can also look for information at:
118
119 · AnnoCPAN: Annotated CPAN documentation
120
121 http://annocpan.org/dist/MooseX-NonMoose
122 <http://annocpan.org/dist/MooseX-NonMoose>
123
124 · CPAN Ratings
125
126 http://cpanratings.perl.org/d/MooseX-NonMoose
127 <http://cpanratings.perl.org/d/MooseX-NonMoose>
128
129 · RT: CPAN's request tracker
130
131 http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-NonMoose
132 <http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-NonMoose>
133
134 · Search CPAN
135
136 http://search.cpan.org/dist/MooseX-NonMoose
137 <http://search.cpan.org/dist/MooseX-NonMoose>
138
140 Jesse Luehrs <doy at tozt dot net>
141
143 This software is copyright (c) 2010 by Jesse Luehrs.
144
145 This is free software; you can redistribute it and/or modify it under
146 the same terms as the Perl 5 programming language system itself.
147
148
149
150perl v5.12.2 2010-08-20 MooseX::NonMoose(3)