1MooseX::NonMoose(3)   User Contributed Perl Documentation  MooseX::NonMoose(3)
2
3
4

NAME

6       MooseX::NonMoose - easy subclassing of non-Moose classes
7

VERSION

9       version 0.26
10

SYNOPSIS

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

DESCRIPTION

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
72       Not all non-Moose classes use "new" as the name of their constructor.
73       This module allows you to extend these classes by explicitly stating
74       which method is the constructor, during the call to "extends". The
75       syntax looks like this:
76
77         extends 'Foo' => { -constructor_name => 'create' };
78
79       similar to how you can already pass "-version" in the "extends" call in
80       a similar way.
81

BUGS/CAVEATS

83       ·   The reference that the non-Moose class uses as its instance type
84           must match the instance type that Moose is using. Moose's default
85           instance type is a hashref, but other modules exist to make Moose
86           use other instance types. MooseX::InsideOut is the most general
87           solution - it should work with any class. For globref-based classes
88           in particular, MooseX::GlobRef will also allow Moose to work. For
89           more information, see the "032-moosex-insideout" and
90           "033-moosex-globref" tests bundled with this dist.
91
92       ·   Modifying your class' @ISA after an initial "extends" call will
93           potentially cause problems if any of those new entries in the @ISA
94           override the constructor.  "MooseX::NonMoose" wraps the nearest
95           "new()" method at the time "extends" is called and will not see any
96           other "new()" methods in the @ISA hierarchy.
97
98       ·   Completely overriding the constructor in a class using
99           "MooseX::NonMoose" (i.e. using "sub new { ... }") currently doesn't
100           work, although using method modifiers on the constructor should
101           work identically to normal Moose classes.
102
103       Please report any bugs to GitHub Issues at
104       <https://github.com/doy/moosex-nonmoose/issues>.
105

SEE ALSO

107       ·   "How do I make non-Moose constructors work with Moose?" in
108           Moose::Manual::FAQ
109
110       ·   MooseX::Alien
111
112           serves the same purpose, but with a radically different (and far
113           more hackish) implementation.
114

SUPPORT

116       You can find this documentation for this module with the perldoc
117       command.
118
119           perldoc MooseX::NonMoose
120
121       You can also look for information at:
122
123       ·   MetaCPAN
124
125           <https://metacpan.org/release/MooseX-NonMoose>
126
127       ·   Github
128
129           <https://github.com/doy/moosex-nonmoose>
130
131       ·   RT: CPAN's request tracker
132
133           <http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-NonMoose>
134
135       ·   CPAN Ratings
136
137           <http://cpanratings.perl.org/d/MooseX-NonMoose>
138

AUTHOR

140       Jesse Luehrs <doy@tozt.net>
141
143       This software is copyright (c) 2014 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.30.0                      2019-07-26               MooseX::NonMoose(3)
Impressum