NAME

Marlin::XAttribute::Alias - Marlin attribute extension for attribute aliases.

SYNOPSIS

package Local::Person {
  use Marlin::Util -all;
  use Types::Common -types;
  use Marlin
    name => {
      required     => true,
      isa          => Str,
      ':Alias'     => 'moniker',
    },
    age => {
      isa          => Int,
      handles_via  => 'Num',
      handles      => {
        is_adult => [ ge => 18 ],
        is_child => [ lt => 18 ],
      },
    };
}

my $alice = Local::Person->new( name => 'Alice', age => 21 );
say $alice->moniker if $alice->is_adult;  # says "Alice"

my $bob = Local::Person->new( moniker => 'Bob', age => 12 );
say $bob->name if $bob->is_child;  # says "Bob"

DESCRIPTION

Adds constructor and accessor aliases for an attribute.

You can use an arrayref to declare multiple aliases.

use Marlin
  name => {
    required     => true,
    isa          => Str,
    ':Alias'     => [ 'moniker', 'label' ],
  }, ...;

If you also wish to provide other options, you can use a hashref.

use Marlin
  name => {
    required     => true,
    isa          => Str,
    ':Alias'     => {
      alias    => [ 'moniker', 'label' ],
      for      => 'reader',
    },
  }, ...;

The for option allows you to indicate whether these are aliases for the attribute's reader method or accessor method. By default they will be aliases for the reader, unless the attribute is => "rw", in which case the aliases will be aliases for the accessor. (In theory, it is possible to set them as aliases for a writer, predicate, or clearer, but that would be weird.)

Using this extension will force your class, plus any classes that inherit from it, to use Marlin's Pure Perl constructor instead of the XS constructor.

BUGS

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

SEE ALSO

Marlin.

AUTHOR

Toby Inkster <tobyink@cpan.org>.

COPYRIGHT AND LICENCE

This software is copyright (c) 2025 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.

🐟🐟