MooseX::MungeHas - munge your "has" (works with Moo, Moose and Mouse)
package Foo::Bar; use Moose; use MooseX::MungeHas "is_ro"; has foo => (); # read-only has bar => (is => "rw"); # read-write
MooseX::MungeHas alters the behaviour of the attributes of your Moo, Moose or Mouse based class. It manages to support all three because it doesn't attempt to do anything smart with metathingies; it simply installs a wrapper for has that munges the attribute specification hash before passing it on to the original has function.
has
When you use MooseX::MungeHas you must provide a list of mungers you want it to apply. The following are currently pre-defined:
use MooseX::MungeHas
is_ro
is_rw
is_rwp
is_lazy
These mungers supply defaults for the is option.
is
Although only Moo supports is => "rwp" and is => "lazy", MooseX::MungeHas supplies an implementation of both for Moose or Mouse.
is => "rwp"
is => "lazy"
always_coerce
Automatically provides coerce => 1 if the type constraint provides coercions. (Unless you've explicitly specified coerce => 0.)
coerce => 1
coerce => 0
Although Moo expects coerce to be a coderef, MooseX::MungeHas supplies an implementation of coerce => 0|1 for Type::Tiny type constraints.
coerce => 0|1
eq_1
Makes builder => 1, clearer => 1, predicate => 1, and trigger => 1 do what you mean.
builder => 1
clearer => 1
predicate => 1
trigger => 1
no_isa
Switches off isa checks for attributes, unless they coerce.
isa
simple_isa
Loosens type constraints if they don't coerce, and if it's likely to make them significantly faster. (Loosening Int to Num won't speed it up.)
Int
Num
Only works if you're using Type::Tiny constraints.
If these predefined mungers don't float your boat, then you can provide additional mungers using coderefs:
use MooseX::MungeHas "no_isa", sub { # Make constructor ignore private attributes $_{init_arg} = undef if /^_/; };
Within coderefs, the name of the attribute being processed is available in the $_ variable, and the specification hash is available as %_.
$_
%_
You may provide multiple coderefs. Mungers provided as coderefs are executed after named ones, but are otherwise executed in the order specified.
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=MooseX-MungeHas.
Moo, Mouse, Moose, MooseX::AttributeShortcuts, MooseX::InlineTypes, Type::Tiny::Manual.
Similar: MooseX::HasDefaults, MooseX::Attributes::Curried, MooseX::Attribute::Prototype and MooseX::AttributeDefaults.
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2013 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
To install MooseX::MungeHas, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::MungeHas
CPAN shell
perl -MCPAN -e shell install MooseX::MungeHas
For more information on module installation, please visit the detailed CPAN module installation guide.