MooX::LvalueAttribute - Provides Lvalue accessors to Moo class attributes
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:
you can use:
$object->name = "Foo";
To enable Lvalue access to your attribute, simply use
MooX::LvalueAttribute in the class or role, and add:
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.
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.