MooseX::NotRequired - Make Moose sub classes with non required attributes.
Version 0.12
This module allows you to create anonymous sub classes of Moose classes with all the required flags on the attributes turned off.
package SalesOrder; use Moose; has order_number => (is => 'ro', isa => 'Str', required => 1); has reference => (is => 'ro', isa => 'Str' ); has date_ordered => (is => 'ro', isa => 'DateTime', required => 1); has total_value => (is => 'ro', isa => 'Int', required => 1); has customer => (is => 'ro', isa => 'Str', required => 1); has notes => (is => 'ro', isa => 'Str'); 1; ... use MooseX::NotRequired; my $new_class = MooseX::NotRequired::make_optional_subclass('SalesOrder'); my $obj = $new_class->new(); # no blow up my $default = $new_class->new({ semi_required => undef }); # fine too ... my $second = ObjectA->new(); # blow up because required fields not present my $third = ObjectA->new({ order_number => 'a', semi_required => undef }); # blow up because semi_required must be a string.
This module exists because while you want to make use of Moose's awesome type constraints they're sometimes a little inconvenient. Rather than throw out all your restrictions because you need your class to be a little more permissive in a few scenarios, create a subclass that has some of those restrictions weakened. You can of course do this manually.
This creates an anonymous sub class that has all the required flags on the attributes removed. It also turns type constraints into Maybe constraints where possible. That generally only works for simple isa's like 'Str'.
Colin Newell, <colin.newell at gmail.com>
<colin.newell at gmail.com>
Please report any bugs or feature requests to https://github.com/colinnewell/MooseX-NotRequired/issues. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc MooseX::NotRequired
You can also look for information at:
Github request tracker (report bugs here)
https://github.com/colinnewell/MooseX-NotRequired/issues
Github source code repository
https://github.com/colinnewell/MooseX-NotRequired/
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/MooseX-NotRequired
CPAN Ratings
http://cpanratings.perl.org/d/MooseX-NotRequired
Search CPAN
http://search.cpan.org/dist/MooseX-NotRequired/
This could wouldn't be possible without the help of doy on #moose. The cool bits were written by him and the bugs/bad practice added by Colin. JJ also helped get things going again when I got stuck. The Birmingham Perl Mongers also provided input which helped refine and improve the module.
Copyright 2011-2015 OpusVL.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install MooseX::NotRequired, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::NotRequired
CPAN shell
perl -MCPAN -e shell install MooseX::NotRequired
For more information on module installation, please visit the detailed CPAN module installation guide.