1MooseX::StrictConstructUosre(r3)Contributed Perl DocumenMtoaotsieoXn::StrictConstructor(3)
2
3
4
6 MooseX::StrictConstructor - Make your object constructors blow up on
7 unknown attributes
8
10 version 0.21
11
13 package My::Class;
14
15 use Moose;
16 use MooseX::StrictConstructor;
17
18 has 'size' => ( is => 'ro' );
19
20 # then later ...
21
22 # this blows up because color is not a known attribute
23 My::Class->new( size => 5, color => 'blue' );
24
26 Simply loading this module makes your constructors "strict". If your
27 constructor is called with an attribute init argument that your class
28 does not declare, then it calls "Moose->throw_error()". This is a great
29 way to catch small typos.
30
31 Subverting Strictness
32 You may find yourself wanting to have your constructor accept a
33 parameter which does not correspond to an attribute.
34
35 In that case, you'll probably also be writing a "BUILD()" or
36 "BUILDARGS()" method to deal with that parameter. In a "BUILDARGS()"
37 method, you can simply make sure that this parameter is not included in
38 the hash reference you return. Otherwise, in a "BUILD()" method, you
39 can delete it from the hash reference of parameters.
40
41 sub BUILD {
42 my $self = shift;
43 my $params = shift;
44
45 if ( delete $params->{do_something} ) {
46 ...
47 }
48 }
49
51 Please report any bugs or feature requests to
52 "bug-moosex-strictconstructor@rt.cpan.org", or through the web
53 interface at <http://rt.cpan.org>. I will be notified, and then you'll
54 automatically be notified of progress on your bug as I make changes.
55
56 Bugs may be submitted at
57 <https://github.com/moose/MooseX-StrictConstructor/issues>.
58
59 I am also usually active on IRC as 'autarch' on "irc://irc.perl.org".
60
62 The source code repository for MooseX-StrictConstructor can be found at
63 <https://github.com/moose/MooseX-StrictConstructor>.
64
66 If you'd like to thank me for the work I've done on this module, please
67 consider making a "donation" to me via PayPal. I spend a lot of free
68 time creating free software, and would appreciate any support you'd
69 care to offer.
70
71 Please note that I am not suggesting that you must do this in order for
72 me to continue working on this particular software. I will continue to
73 do so, inasmuch as I have in the past, for as long as it interests me.
74
75 Similarly, a donation made in this way will probably not make me work
76 on this software much more, unless I get so many donations that I can
77 consider working on free software full time (let's all have a chuckle
78 at that together).
79
80 To donate, log into PayPal and send money to autarch@urth.org, or use
81 the button at <http://www.urth.org/~autarch/fs-donation.html>.
82
84 Dave Rolsky <autarch@urth.org>
85
87 • Jesse Luehrs <doy@tozt.net>
88
89 • Karen Etheridge <ether@cpan.org>
90
91 • Ricardo Signes <rjbs@cpan.org>
92
94 This software is Copyright (c) 2007 - 2017 by Dave Rolsky.
95
96 This is free software, licensed under:
97
98 The Artistic License 2.0 (GPL Compatible)
99
100 The full text of the license can be found in the LICENSE file included
101 with this distribution.
102
103
104
105perl v5.34.0 2021-07-22 MooseX::StrictConstructor(3)