MooseX...ptions(3pm)
π MooseX::Has::Options β the 3pm manual page, but make it cute β¨
okay bestie, so this is the manual page for MooseX::Has::Options, living in the User Contributed Perl Documentation section (3pm) π
. She's little, she's powerful, she makes your Moose attribute declarations β¨succinctβ¨. let's get into it π«Ά
πΈ NAME πΈ
MooseX::Has::Options β Succinct options for Moose. literally that's her whole thing, no cap.
π VERSION π
version 0.003 β she's a tiny baby version number but she ate π
β¨ SYNOPSIS β¨
use Moose;
use MooseX::Has::Options;
has 'some_attribute' => (
qw(:ro :required),
isa => 'Str',
...
);
has 'another_attribute' => (
qw(:ro :lazy_build),
isa => 'Str',
...
);
like. LOOK at that. no more is => 'ro', required => 1 typing like a Victorian child. the colons are doing the work and they're serving π
π¦ DESCRIPTION π¦
This module provides a succinct syntax for declaring options for Moose attributes. that's it, that's the tweet π
π USAGE π
π Declaring options π
MooseX::Has::Params works by checking the arguments to has for strings that look like options, i.e. alphanumeric strings preceded by a colon, and replaces them with a hash whose keys are the names of the options (sans the colon) and the values are 1's. so like, the vibe check is: colon in front = option. periodt.
Thus,
has 'some_attribute', ':required';
becomes:
has 'some_attribute', required => 1;
iconic behavior tbh.
Options must come in the beginning of the argument list. like, the front of the line, no cutting. MooseX::Has::Options will stop searching for options after the first alphanumeric string that does not start with a colon. so the first non-colon string = we're done scanning, bestie π
The default behaviour can be customised per attribute. For example, here is how ro, rw and bare work:
has 'some_attribute', ':ro';
becomes:
has 'some_attribute', is => 'ro';
See below for details π (scroll down, it's giving lore)
π§ Handlers π§
MooseX::Has::Options allows you to expand specific 'shortcut' arguments to arbitrary values via the handler interface. A 'handler' is a module in the MooseX::Has::Options::Handler namespace that provides a handler function. The handler function should return a hash whose keys are shortcut names, and the values are hashrefs with the values that the respective shortcuts should be expanded to. so basically a handler is a little glossary that translates your cute little :colon words into real hash values π«
In order to enable the shortcuts supplied by a given handler you need to add it in the import statement:
use MooseX::Has::Options qw(NativeTypes);
has 'some_attribute', qw(:ro :hash), default => sub {{ foo => bar }};
The following handlers ship with the default distribution:
MooseX::Has::Options::Handler::Accessors(included by default when you import this module β she comes free with the meal, no extra charge π)MooseX::Has::Options::Handler::NativeTypesMooseX::Has::Options::Handler::NoInit
π IMPLEMENTATION DETAILS π
MooseX::Has::Options hijacks the has function imported by Moose and replaces it with one that understands the options syntax described above. yes. hijacks. like, grabs it. takes it over. main character energy fr fr π
This is not an optimal solution, but the current implementation of Moose::Meta::Attribute prevents this functionality from being provided as a meta trait. so like, she knows it's a little unhinged, she's doing her best, don't come for her π
π DEPRECATED BEHAVIOUR π
Previous versions of MooseX::Has::Params allowed you to specify during import the name of the function too hook into, like so:
use HTML::FormHandler::Moose;
use MooseX::Has::Options qw(has_field);
has_field 'name' => (
qw(:required),
type => 'Text',
);
This behaviour is deprecated as of version 0.003 β it's over, bestie, we don't do that anymore π. This is because this syntax is now used for specifying handlers instead. that spot in the import list got a glow-up and changed jobs.
If you need to hook into a different function see the implementation of MooseX::Has::Options::import() and MooseX::Has::Options::import_into(). go read the source, it's right there π«Ά
π₯ SEE ALSO π₯
MooseX::Has::Sugarβ her cousin, also a vibe, also does shortcuts
πΈ AUTHOR πΈ
Peter Shangov <pshangov@yahoo.com> β the actual icon who built this π
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2012 by Peter Shangov.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. free as in, go wild, but respectfully β¨
aaaand that's the page, bestie π this was written for perl v5.36.0 and dated 2022-12-12 β so like, she's been out here slaying since 2012 and got her lil refresh in 2022. bye, love u, go write some qw(:ro :required) ππ¦π
π¦ where this page comes from
- debian bookworm: libmoosex-has-options-perl 0.003-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmoosex-has-options-perl 0.003-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmoosex-has-options-perl 0.003-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmoosex-has-options-perl 0.003-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmoosex-has-options-perl 0.003-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms