Aspect...gleton(3pm)

πŸ“¦
version 1.04 Β· 3 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

Aspect::Library::Singleton β€” bestie, it's a singleton aspect. That's the whole vibe. ✨

(Oh and hi, you're reading the Aspect::Library::Singleton(3pm) page from the User Contributed Perl Documentation, iykyk πŸ’…)


πŸ¦‹ SYNOPSIS πŸ¦‹

use Aspect;
use Aspect::Singleton;

aspect Singleton => 'Foo::new';

my $f1 = Foo->new;
my $f2 = Foo->new;

# Both $f1 and $f2 refer to the same object

Like… look at that. Two new calls, one object. Main character energy fr fr. πŸŽ€


✨ DESCRIPTION ✨

Okay so it's a reusable aspect that forces singleton behavior on a constructor. And how do you tell it which constructor? With a pointcut spec β€” that's a string, a regexp, or a code ref. Pick your fighter. πŸ’–

Now, it's slightly different from Class::Singleton β€” you can peep that one over here: <http://search.cpan.org/~abw/Class-Singleton/Singleton.pm>. Here's the tea β˜•:

  • No specific name requirement on the constructor, not for the external interface and not for the implementation. Like, Class::Singleton makes clients use instance(), and makes subclasses override _new_instance(). Meanwhile with aspects, you can change the cardinality of your objects without touching the clients, and without touching the objects themselves either. Obsessed. 😌
  • No need to inherit from anything β€” just use pointcuts to specify the constructors you want to memoize. Instead of pulling singleton behavior from a base class, you're pushing it in with the aspect. It's giving glow-up, not genetics. πŸ’…
  • No package variable or method gets added to the caller's namespace. Clean. Pristine. Nothing left behind. 🧚
Heads up bestie: this is just a special case of memoizing. That's it, that's the note. πŸ’œ

πŸ‘‘ AUTHORS πŸ‘‘

  • Adam Kennedy <adamk@cpan.org>
  • Marcel GrΓΌnauer <marcel@cpan.org>
  • Ran Eilam <eilara@cpan.org>

Three icons. We stan. 🫢


Copyright 2001 by Marcel GrΓΌnauer.

Some parts copyright 2009 - 2013 Adam Kennedy.

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


okay that's the whole page, no cap. this was perl v5.36.0, dated 2023-07-02, and yes the title is still Aspect...gleton(3pm) β€” they truncated it for the header, it's giving mysterious πŸ’€. love u, go make some singletons, periodt. πŸŒˆπŸ’–βœ¨
πŸ“¦ where this page comes from