NAME

Marlin::XAttribute::Lvalue - Marlin attribute extension for lvalue accessors.

SYNOPSIS

package Local::Person {
  use Marlin::Util -all;
  use Types::Common -types;
  use Marlin
    name => {
      required       => true,
      isa            => Str,
      ':Lvalue'      => true,
    };
}

my $bob = Local::Person->new( name => 'Bob' );
say $bob->name;           # "Bob"
$bob->name = "Robert";    # set a new value
say $bob->name;           # "Robert"

IMPORTING THIS MODULE

The standard way to import Marlin attribute extensions is to include them in the attribute definition hashrefs passed to use Marlin

package Local::Person {
  use Marlin::Util -all;
  use Types::Common -types;
  use Marlin
    name => {
      required       => true,
      isa            => Str,
      ':Lvalue'      => true,
    };
}

It is possible to additionally load it with use Marlin::XAttribute::Lvalue, which won't do anything, but might be useful to automatic dependency analysis.

package Local::Person {
  use Marlin::Util -all;
  use Marlin::XAttribute::Lvalue;
  use Types::Common -types;
  use Marlin
    name => {
      required       => true,
      isa            => Str,
      ':Lvalue'      => true,
    };
}

DESCRIPTION

Creates an lvalue accessor for your attribute.

If your attribute doesn't have any defaults, type constraints or coercions, triggers, or anything else to slow it down, then it will be a fairly fast lvalue accessor generated by Class::XSAccessor.

Otherwise, it will be implemented in Pure Perl, and be much slower.

You can provide a specific name for your lvalue accessor:

package Local::Person {
  use Marlin::Util -all;
  use Types::Common -types;
  use Marlin
    name => {
      required       => true,
      isa            => Str,
      ':Lvalue'      => 'moniker',
    };
}

my $alice = Local::Person->new( name => "Alice" );

$alice->moniker = 'Allie';   # Lvalue accessor
say $alice->name;            # Standard non-lvalue reader

If you don't provide a specific name, it will be created instead of your standard reader/accessor.

This extension makes no changes to your constructor.

Usage with alias_for

It should be possible to set alias_for to "Lvalue" (with a capital L).

package Local::Person {
  use Marlin::Util -all;
  use Types::Common -types;
  use Marlin
    name => {
      required       => true,
      isa            => Str,
      ':Lvalue'      => 1,
      alias          => [ qw/ moniker label / ],
      alias_for      => 'Lvalue',
   };
}

my $x = Local::Person->new( name => 'Bob' );
$x->moniker = 'Robert';
say $x->label;  # Robert

BUGS

Please report any bugs to https://github.com/tobyink/p5-marlin-xattribute-lvalue/issues.

SEE ALSO

Marlin, LV.

AUTHOR

Toby Inkster <tobyink@cpan.org>.

COPYRIGHT AND LICENCE

This software is copyright (c) 2025-2026 by Toby Inkster.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

DISCLAIMER OF WARRANTIES

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

🐟🐟