MooseX:...yRequire(3)
hiii bestie ๐ welcome to the MooseX::LazyRequire(3) manual page โ yes, the one from User Contributed Perl Documentation. this is the whole โrequired attributes but make it delayedโ situation, and itโs lowkey iconic.
๐ NAME ๐
MooseX::LazyRequire โ required attributes that donโt fail until somebody actually tries to use them. itโs giving โyou had one job, and the job is to complain later.โ ๐
โจ VERSION โจ
version 0.11 โ periodt.
๐ SYNOPSIS ๐
okay so hereโs the whole vibe, bestie:
package Foo;
use Moose;
use MooseX::LazyRequire;
has foo => (
is => 'ro',
lazy_required => 1,
);
has bar => (
is => 'ro',
builder => '_build_bar',
);
sub _build_bar { shift->foo }
Foo->new(foo => 42); # succeeds, foo and bar will be 42
Foo->new(bar => 42); # succeeds, bar will be 42
Foo->new; # fails, neither foo nor bare were given
likeโฆ the comments are literally the plot. Foo->new(foo => 42) succeeds, Foo->new(bar => 42) succeeds, and Foo->new fails because neither foo nor bare were given. slay. ๐ฆ
๐ DESCRIPTION ๐
this module adds a lazy_required option to Moose attribute declarations. thatโs the whole magic trick, and it ate. โจ
the reader methods for all attributes with that option will throw an exception unless a value for the attributes was provided earlier by a constructor parameter or through a writer method. so itโs not โrequired at construction timeโ required โ itโs โrequired by the time you actually try to read itโ required. very main character energy. ๐
๐ฆ CAVEATS ๐ฆ
caveat zone, bestie โ pay attention, this part is important ๐ซถ
prior to Moose 1.9900, roles didnโt have an attribute metaclass, so this module canโt easily apply its magic to attributes defined in roles. if you want to use lazy_required in role attributes, youโll have to apply the attribute trait yourself:
has foo => (
traits => ['LazyRequire'],
is => 'ro',
lazy_required => 1,
);
with Moose 1.9900, you can use this module in roles just the same way you can in classes. so if youโre on the newer Moose, youโre chilling. ๐
๐ AUTHORS ๐
Florian Ragwitz <rafl@debian.org>Dave Rolsky <autarch@urth.org>
๐ COPYRIGHT AND LICENSE ๐
this software is copyright (c) 2009 by Florian Ragwitz.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
๐ซถ CONTRIBUTORS ๐ซถ
Karen Etheridge <ether@cpan.org>David Precious <davidp@preshweb.co.uk>Jesse Luehrs <doy@tozt.net>
and thatโs the page, bestie ๐ง source/version/date sign-off: perl v5.42.0, 2015-01-08, manual MooseX:...yRequire(3). periodt ๐
๐ฆ where this page comes from
- opensuse-leap 16.0: perl-MooseX-LazyRequire 0.11-bp160.1.2 ยท Artistic-1.0 or GPL-1.0+
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms