MooseX...nBuilt(3pm)

πŸ“¦
version 0.53 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– MooseX::Storage::Traits::OnlyWhenBuilt(3pm) πŸ’–

okay bestie, so this is a page from the User Contributed Perl Documentation, and it's literally called MooseX::Storage::Traits::OnlyWhenBuilt(3pm). yes the manual name is doing the absolute most, but she's iconic for it. πŸŽ€


✨ NAME ✨

MooseX::Storage::Traits::OnlyWhenBuilt β€” a custom trait to bypass serialization. yes, she bypasses it. she's got main character energy and she does not have time. πŸ’…


🌸 VERSION 🌸

version 0.53


πŸ¦‹ SYNOPSIS πŸ¦‹

{   package Point;
    use Moose;
    use MooseX::Storage;

    with Storage( traits => [qw|OnlyWhenBuilt|] );

    has 'x' => (is => 'rw', lazy_build => 1 );
    has 'y' => (is => 'rw', predicate => '_has_y' );
    has 'z' => (is => 'rw', builder => '_build_z' );

    sub _build_x { 3 }
    sub _build_y { expensive_computation() }
    sub _build_z { 3 }

}

my $p = Point->new( 'x' => 4 );

# the result of ->pack will contain:
# { x => 4, z => 3 }
$p->pack;

πŸ‘‘ DESCRIPTION πŸ‘‘

so, sometimes you have an attribute and you're just like... bestie, no. do not put that in the serialization if it hasn't been built yet. 🫢

if you invoke Storage() the way the SYNOPSIS shows you (it's giving cargo-cult, and honestly? valid), then only the attributes that have already been built get serialized. and by "built" we mean, like, the ones where the predicate returns 'true'. βœ…

the whole point? it avoids any potentially expensive computations. we are NOT doing expensive math for no reason, periodt. πŸ’€

lowkey the SYNOPSIS is a whole vibe and you can absolutely just copy-paste it into your own code. she says so herself β€” it "can be easily cargo-culted." πŸ’–

πŸŽ€ SUPPORT πŸŽ€

bugs? yeah, you can submit those through the RT bug tracker:

https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Storage

or if email is more your thing, slide into: bug-MooseX-Storage@rt.cpan.org ✨

there's also a mailing list for the users of this distribution, right here:

http://lists.perl.org/list/moose.html

and there's an irc channel too, for all the distribution users, at #moose on irc.perl.org (that's irc://irc.perl.org/#moose if you're fancy). come hang out, the group chat is poppin' πŸ’¬


🌈 AUTHORS 🌈

look at these absolute legends, no cap:

  • Chris Prather <chris.prather@iinteractive.com>
  • Stevan Little <stevan.little@iinteractive.com>
  • Χ™Χ•Χ‘Χœ Χ§Χ•Χ’'מן (Yuval Kogman) <nothingmuch@woobling.org>

this software is copyright (c) 2007 by Infinity Interactive, Inc.

and it's free software β€” you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. slay. πŸŽ‰


okay that's the whole page bestie, you ate that. go forth and don't build stuff you don't need to build. πŸ’…βœ¨

this was version 0.53, from perl v5.36.0, dated 2022-10-16 β€” love u, bye! πŸ¦‹πŸ’–

πŸ“¦ where this page comes from