MooseX::SlurpyConstructor - Assign all unknown arguments to attribute in object constructor.
package ASDF; use Moose; use MooseX::SlurpyConstructor; has fixed => ( is => 'ro', ); has slurpy => ( is => 'ro', slurpy => 1, ); package main; ASDF->new({ fixed => 100, unknown1 => "a", unknown2 => [ 1..3 ] })->dump; # returns: # $VAR1 = bless( { # 'slurpy' => { # 'unknown2' => [ # 1, # 2, # 3 # ], # 'unknown1' => 'a' # }, # 'fixed' => 100 # }, 'ASDF' );
Including this module within Moose-based classes, and declaring an attribute as 'slurpy' will allow capturing of all unknown constructor arguments in the given attribute.
When composing a class, an error will be raised if more than one attribute of the class is marked as 'slurpy'. Also, at object instatiation time, an error will be raised if the class being instantiated uses this one, but does not declare a slurpy attribute.
The opposite of this module, making constructors die on unknown arguments. Note that if both of these are used together, SlurpyConstructor will take precedence and strict constructor explosions will never occour.
Mark Morgan <makk384@gmail.com>
<makk384@gmail.com>
Thanks to the folks from moose mailing list and IRC channels for helping me find my way around some of the Moose bits I didn't know of before writing this module.
As usual, send bugs or feature requests to bug-moosex-slurpyconstructor@rt.cpan.org or through web interface http://rt.cpan.org.
bug-moosex-slurpyconstructor@rt.cpan.org
Copyright 2009 Mark Morgan, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install MooseX::SlurpyConstructor, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::SlurpyConstructor
CPAN shell
perl -MCPAN -e shell install MooseX::SlurpyConstructor
For more information on module installation, please visit the detailed CPAN module installation guide.