++ed by:
EGOR DOHERTY SSCAFFIDI ARISTOTLE DAMS

5 PAUSE user(s)

Damien Krotkine
and 1 contributors

NAME

MooX::LvalueAttribute - Provides Lvalue accessors to Moo class attributes

VERSION

version 0.16

SYNOPSIS

From a Moo class

  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

From a Moo role

  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

DESCRIPTION

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"; 

ATTRIBUTE SPECIFICATION

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).

NOTE ON IMPLEMENTATION

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.

AUTHOR

Damien "dams" Krotkine

COPYRIGHT AND LICENSE

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.