KiokuD...::Lazy(3pm)

πŸ“¦
version 0.57 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu questing

✨ NAME ✨

KiokuDB::Meta::Attribute::Lazy β€” the trait that makes your attributes load lazily, bestie πŸ’€βœ¨

(it's a Perl 3pm page, from the User Contributed Perl Documentation collection, if you were wondering where you wandered into 🫢)


🌸 VERSION 🌸

version 0.57 β€” yes queen, that's the one πŸ‘‘


πŸŽ€ SYNOPSIS πŸŽ€

okay so picture this: you're in your class, right? and you want bar to be lazy. boom. here's the whole vibe:

# in your class:

package Foo;
use KiokuDB::Class;

has bar => (
    traits => [qw(KiokuDB::Lazy)],
    isa => "Bar",
    is  => "ro",
);

and then, like, later on:

# Later:

my $foo = $dir->lookup($id);

# bar is not yet loaded, it will be lazily fetched during this call:
$foo->bar;

see how bar is just sitting there not loaded yet? iconic. it gets lazily fetched during that call. the way that accessor does its job... πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so this is a Moose::Meta::Attribute trait, and what it does is give you lazy loading on a per field basis for objects stored in KiokuDB. per field!! you pick and choose, no commitment, we love that for you 🌈

here's the thing β€” instead of doing the whole proxy-object song and dance with AUTOLOAD, overloading, or similar hacks (πŸ’€ not the hacks), you just declaratively specify which attributes you want to make lazy. that's it. and it gets done cleanly through the MOP. clean girl aesthetic, but for metaprogramming ✨

how's it actually work under the hood? so glad you asked. it uses a placeholder object, KiokuDB::Thunk, which holds references to the ID and the linker. then KiokuDB::Meta::Instance knows to swap that placeholder out for the actual loaded object whenever it gets fetched from the object by an accessor. like a glow-up but automatic 🧚


πŸ’– AUTHOR πŸ’–

Yuval Kogman <nothingmuch@woobling.org> β€” shoutout to the icon who wrote this 🫢


This software is copyright (c) 2014 by Yuval Kogman, Infinity Interactive.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


okay that's the whole page, no cap. this was KiokuD...::Lazy(3pm) (aka KiokuDB::Meta::Attribute::Lazy), built with perl v5.34.0 and dated 2022-05-23 🌸 mwah, go make some lazy attributes, you got this bestie πŸ’œπŸŽ€

πŸ“¦ where this page comes from