MooX::LvalueAttribute - Provides Lvalue accessors to Moo class attributes
version 0.16
package App; use Moo; use MooX::LvalueAttribute; has name => ( is => 'rw', lvalue => 1, ); # Elsewhere my $app = App->new(name => 'foo'); $app->name = 'Bar'; print $app->name; # Bar
package MyRole; use Moo::Role; use MooX::LvalueAttribute; has name => ( is => 'rw', lvalue => 1, ); package App; use Moo; with('MyRole'); # Elsewhere my $app = App->new(name => 'foo'); $app->name = 'Bar'; print $app->name; # Bar
This modules provides Lvalue accessors to your Moo attributes. It won't break Moo's encapsulation, and will properly call any accessor method modifiers, triggers, builders and default values creation. It can be used from a Moo class or role.
It means that instead of writing:
$object->name("Foo");
you can use:
$object->name = "Foo";
To enable Lvalue access to your attribute, simply use MooX::LvalueAttribute in the class or role, and add:
MooX::LvalueAttribute
lvalue => 1,
in the attribute specification (see synopsis).
The implementation doesn't use AUTOLOAD, nor TIESCALAR. Instead, it uses a custom accessor and Variable::Magic, which is faster and cheaper than the tie / AUTOLOAD mechanisms.
Variable::Magic
Damien "dams" Krotkine
This software is copyright (c) 2013 by Damien "dams" Krotkine.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install MooX::LvalueAttribute, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooX::LvalueAttribute
CPAN shell
perl -MCPAN -e shell install MooX::LvalueAttribute
For more information on module installation, please visit the detailed CPAN module installation guide.