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>

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