NAME

Marlin::Manual::ClassOptions - class-wide options

DESCRIPTION

Marlin::Manual::Beginning introduced some class-wide options: -extends for indicating a base class or parent class, and -with for composing roles.

Marlin::Manual::BetterMethods> introduced -modifiers.

These options which don't declare a specific attribute start with a leading hyphen, and there are more of them! This part of the manual lists the other class-wide options and goes into more detail on the options that have already been mentioned.

-base or -parents or -isa or -extends

Sets the base class (or classes) of your class.

Example: Inheitance

package Employee {
  use Marlin -base => 'Person', qw( employee_id payroll_number );
}

Note that multiple inheritance is supported, though roles may be a better way of structuring your code.

Example: Multiple Inheitance

package FlyingCar {
  use Marlin -extends => [ 'Car', 'Plane' ];
}

# Better?
package FlyingCar {
  use Marlin -extends => 'Car', -with => 'Flight';
}

Marlin currently only supports inheriting from other Marlin classes, or from Class::XSConstructor, Class::Tiny, Moo, Moose, and Mouse classes. Other base classes may work, especially if they use blessed hashref instances and don't do anything fancy in their constructor.

Marlin can inherit from classes built with Mite, provided that the MOP option was enabled (see Mite::Manual::MOP) and Moose is available. (Mite doesn't expose attribute metadata, so Marlin needs to force the class to "upgrade itself" to a Moose class.)

You can include version numbers:

Example: Inheitance with Version Numbers

package Employee 1.0 {
  use Marlin -base => 'Person 2.000', ...;
}

You can technically manually set your @ISA, but must do it before Marlin creates your class; otherwise Marlin won't be able to see any attribute definitions in parent classes.

package Employee {
  use Person 1.0;
  BEGIN { @ISA = ( 'Person' ) };
  use Marlin qw( employee_id payroll_number );
}

I don't know why you'd want to do that though.

-with or -roles or -does

Composes roles into your class.

package Payable {
  use Marlin::Role -requires => ['payroll_number'];
}

package Employee {
  use Marlin
    -extends => ['Person'],
    -with    => ['Payable'],
    qw( employee_id payroll_number );
}

Marlin classes can accept roles built with Marlin::Role, Role::Tiny, Moo::Role, Moose::Role, or Mouse::Role.

Like -base, you can include version numbers.

-this or -self or -class

Specifies the name of your class. If you don't include this, it will just use caller, which is normally what you want.

The following are roughly equivalent:

package Person {
  use Marlin 'name!';
}

use Marlin -this => 'Person', 'name!';

The main difference is what scope any lexical subs Marlin creates will end up in. (And if your version of Perl is too old to support lexical subs, the "scope" they will be installed in is actually the caller package!)

-constructor

Tells Marlin to use a constructor name other than new:

package Person {
  use Marlin -constructor => 'create', 'name!';
}

my $bob = Person->create( name => 'Bob' );

It can sometimes be useful to name your constructor something like _new if you wish to create your own new method wrapping it.

-strict or -strict_constructor

Tells Marlin to build a constructor like MooX::StrictConstructor or MooseX::StrictConstructor, which will reject unknown arguments.

Since version 0.007000, this is the default.

-sloppy or -sloppy_constructor or -loose or -loose_constructor

Switches off the strict constructor.

Option introduced in version 0.007000. This was previously the default.

-mods or -modifiers

Exports the before, after, around, and fresh method modifiers from Class::Method::Modifiers, but lexical versions of them.

In Marlin::Role, doesn't import fresh.

SEE ALSO

Marlin::Manual::Comparison - comparing Marlin with other OO frameworks.

Marlin, Marlin::Util.

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.