NAME

Marlin::Role::Antlers - a more Moose-like syntax for Marlin::Role

SYNOPSIS

package Local::CoolerDump 2.0 {
  use Marlin::Role::Antlers;
  
  requires "dump";
  
  has emoji => sub { "✨" };
  
  around dump => sub ( $next_method, $self, @args ) {
    my $emoji = $self->emoji;
    my $dump  = $self->$next_method( @args );
    return $emoji . $dump . $emoji;
  };
}

package Local::CoolWidget 1.0 {
  use Marlin::Antlers;
  extends 'Local::Widget 1.0';
  with 'Local::CoolerDump 2.0';
}

my $w = Local::CoolWidget->new( name => 'Foo' );
print $w->dump, "\n";

DESCRIPTION

Marlin::Role::Antlers provides Moose-like has, with, etc keywords for Marlin::Role.

It also exports everything from Types::Common and Marlin::Util. This will give you true, false, ro, rw, rwp, etc for free, plus a whole bunch of type constraints, signature_for, etc.

Everything is exported lexically.

Marlin::Role::Antlers also enables strict and warnings, plus switches on the following Perl features: signatures, postderef, lexical_subs, current_sub, evalbytes, fc, say, state, unicode_eval, and unicode_strings. It requires Perl 5.20, so you don't need to worry about whether modern Perl syntax features like // are supported.

Significant differences from Moose::Role and Moo::Role are noted below.

Keywords

requires METHODS

List methods that this role requires any classes that compose it to provide.

has ATTRIBUTE => ( SPEC )

Much like Moose and Moo's has keyword, but defaults to is => 'ro', so you don't get repetitive strain injury typing that out each time.

Example:

has foo => (
  is           => 'rw',
  isa          => Int,
  clearer      => true,
  predicate    => true,
  lazy         => true,
  default      => 0,
);

Note that it's possible to declare multiple attributes at the same time, as long as they share a spec.

has [ 'foo', 'bar', 'baz' ] => (
  is           => 'rw',
  isa          => Int,
);

Moose and Moo allow that too!

has ATTRIBUTE => CODEREF

Shortcut for a lazy builder.

Example:

has foo => sub { 0 };

Moose and Moo don't allow that.

has ATTRIBUTE => TYPE

Shortcut for a read-only attribute with a type constraint.

Example:

has foo => Int;

Moose and Moo don't allow that.

has ATTRIBUTE

Shortcut for a read-only attribute with no special options.

Example:

has "foo";

Moose and Moo don't allow that.

with ROLES

Compose other roles into your role.

Example:

with "Local::MyTrait 1.0", "Local::YourTrait";

Marlin doesn't allow you to alias or exclude methods like Moose does. Moose's syntax for including version numbers is slightly different. Moo doesn't allow version numbers to be included in the list.

before METHODNAME => CODEREF

Installs a "before" method modifier.

See Role::Tiny.

after METHODNAME => CODEREF

Installs an "after" method modifier.

See Role::Tiny.

around METHODNAME => CODEREF

Installs an "around" method modifier.

See Role::Tiny.

__FINALIZE__

You can call this function at the end of your role to finalize it. Think of it like Moose's __PACKAGE__->meta->make_immutable.

However, Marlin::Role::Antlers will automatically run it at the end of the lexical scope, so it is very rare you'd need to do it manually. (The only reason would be if you're defining several roles in the same file and don't want to wrap them in {...}.)

Import Options

You can customize your role using the following option:

use Marlin::Role::Antlers { x => [ ':XYZ', \%xyz_opts ] };

The x option is used to load Marlin extensions. Each item on the array is an extension to load and can optionally be followed by a hashref of options to pass to the extension.

BUGS

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

SEE ALSO

Marlin::Antlers.

Marlin::Role, Moose::Role, Moo::Role.

AUTHOR

Toby Inkster <tobyink@cpan.org>.

COPYRIGHT AND LICENCE

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