MooseX::HandlesConstructor - Moo[se] extension that allows for setting handle accessors with the constructor
version 0.001
package Message;
use Moo; # or Moose traits
use MooX::HandlesVia;
use MooseX::HandlesConstructor;
has header => ( is => 'rw',
default => sub { {} },
handles_via => 'Hash',
handles => {
session => [ accessor => 'session' ],
msg_type => [ accessor => 'msg_type' ]
}
);
# elsewhere...
my $msg = Message->new( msg_type => 'reply', header => { answer => 42 } );
use Data::Dumper; print Dumper $msg->header;
# $VAR1 = {
# 'answer' => 42,
# 'msg_type' => 'reply'
# };
When using Moo or Moose handles that provide an accessor handle on an attribute, it may make sense to pass the name of handles to the constructor to simplify the API. Using this module will get all curried accessor handles defined in a class and allow setting them when calling -
new()>
MooX::HandlesVia, Moose native delegation.
Zakariyya Mughal <zmughal@cpan.org>
This software is copyright (c) 2014 by Zakariyya Mughal.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.