Aspect...gleton(3pm)
π 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::Singletonmakes clients useinstance(), 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 πΈ
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 wasperl v5.36.0, dated2023-07-02, and yes the title is stillAspect...gleton(3pm)β they truncated it for the header, it's giving mysterious π. love u, go make some singletons, periodt. ππβ¨
π¦ where this page comes from
- debian trixie: libaspect-perl 1.04-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libaspect-perl 1.04-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libaspect-perl 1.04-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libaspect-perl 1.04-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms