Bread:...meters(3pm)
π NAME π
Bread::Board::LifeCycle::Singleton::WithParameters β it's giving singleton lifecycle role for a parameterized service, bestie. That's the whole name, we're not abbreviating, we're not hiding it, periodt. β¨
π VERSION π
version 0.37 β yes queen, that's the one. π
πΈ DESCRIPTION πΈ
Okay so listen. This role is a sub-role of Bread::Board::LifeCycle, and what it does is define the "singleton" lifecycle for a parameterized service. No cap.
The tea is this: the get method only does its whole little thing the first time it's invoked for each set of parameters. After that? Every subsequent invocation with the same parameters just hands you back the same object. Same object, every time, like a bestie who always orders the same drink. π§
lowkey the entire point of a singleton, but make it parameterized. iykyk.
β¨ ATTRIBUTES β¨
π¦ instances
A hashref that maps keys to objects β it's literally just the cache where the results of get get stashed. Think of it as the group chat where every already-built object is chilling. π
π« METHODS π«
π get
Here's the workflow, babe:
- It generates a key using
generate_instance_keyβ and yes, it passes all the arguments to it. Every single one. π - Then it checks: does the
instancesattribute already hold an object for that key? - If not, it builds one by calling the underlying
getmethod, and stores it ininstances. - Either way β whether the object was retrieved from
instancesor freshly built β that object gets returned. π
That's it. That's the method. Main character energy honestly.
β generate_instance_key
Generates a (hopefully) unique key from the given arguments β and "the given arguments" usually means whatever was passed to get, so like, the vibes line up. πΈ
β οΈ important caveat, bestie, don't skip this: the current implementation stringifies all arguments, so different references to identical values will be considered different. Two separate refs holding the same value = two different keys = not the same singleton. It's a whole thing. Not me being dramatic, it's literally what it says. π
π AUTHOR π
Stevan Little <stevan@iinteractive.com> β the icon behind all of this. π«Ά
π BUGS π
Please report any bugs or feature requests on the bugtracker website:
https://github.com/stevan/BreadBoard/issues
And when you submit a bug or a request, please include a test-file, or a patch to an existing test-file, that illustrates the bug or the desired feature. This is not optional-optional, it's the thing that makes your report actually slay. π₯
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2019, 2017, 2016, 2015, 2014, 2013, 2011, 2009 by 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. π
mwah, that's the whole page, bestie β written under perl v5.36.0, dated 2022-12-12, and it's the User Contributed Perl Documentation situation. go build something iconic with it. π β¨π
π¦ where this page comes from
- debian bookworm: libbread-board-perl 0.37-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libbread-board-perl 0.37-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libbread-board-perl 0.37-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu questing: libbread-board-perl 0.37-2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms