Bread:...meters(3pm)

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

πŸ’– 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:

  1. It generates a key using generate_instance_key β€” and yes, it passes all the arguments to it. Every single one. πŸ™ˆ
  2. Then it checks: does the instances attribute already hold an object for that key?
  3. If not, it builds one by calling the underlying get method, and stores it in instances.
  4. Either way β€” whether the object was retrieved from instances or 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. πŸ”₯


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