MooseX...ngleton(3pm)
π MooseX::Singleton β turn your Moose class into a singleton, bestie β¨
okay so first things first: this is MooseX::Singleton, version 0.30, and it lives in the Perl world (user-contributed docs, iykyk). slay.
πΈ NAME πΈ
MooseX::Singleton β literally turns your Moose class into a singleton. no cap.
π VERSION π
version 0.30 β that's the vibe check and she passed.
β¨ SYNOPSIS β¨
okay so here's the whole mood, copied exactly because code is sacred:
package MyApp;
use MooseX::Singleton;
has env => (
is => 'rw',
isa => 'HashRef[Str]',
default => sub { \%ENV },
);
package main;
delete MyApp->env->{PATH};
my $instance = MyApp->instance;
my $same = MyApp->instance;
see how $instance and $same are the same object? that's the whole point, bestie. one instance, main character energy, periodt. π
π¦ DESCRIPTION π¦
so a singleton is a class that has only one instance in an application β like there can only be one of her, and honestly? she ate.
MooseX::Singleton lets you easily upgrade (or downgrade, as it were π) your Moose class to a singleton. the way that you don't even have to do much:
all you should need to do to transform your class is to change use Moose to use MooseX::Singleton. that's it. that's the whole transformation. iconic.
and because this module uses metaclass roles to do its magic, it should cooperate with most other MooseX modules β so no drama, she plays nice with the group chat. π«Ά
π METHODS π
a singleton class will have the following additional methods (bestie got some new tricks, obsessed):
π Singleton->instance
this returns the singleton instance for the given package. it does not accept any arguments β don't come at her with args, she's not about that life.
if the instance does not yet exist, it is created with its default values. but plot twist π«’: this means that if your singleton requires arguments, calling instance will die if the object has not already been initialized. so likeβ¦ initialize her first, or she will literally perish.
π Singleton->initialize(%args)
this method can be called only once per class β one shot, one opportunity, no do-overs. it explicitly initializes the singleton object with the given arguments. use it wisely, queen. π
π Singleton->_clear_instance
this clears the existing singleton instance for the class. and obviously, this is meant for use only inside the class itself β it's private, it's giving lore, don't touch it from the outside, k? π
π Singleton->new
this method currently works like a hybrid of initialize and instance β a little bit of both, a collab, if you will. β¨
β οΈ but heads up: callingnewdirectly will probably be deprecated in a future release. so instead, callinitializeorinstanceas appropriate. future-proof your code, bestie, it's self-care. π
π SOME CODE STOLEN FROM π
Anders Nor Berle <debolaz@gmail.com> β shoutout, we love a contributor. π«Ά
πΈ AND PATCHES FROM πΈ
Ricardo SIGNES <rjbs@cpan.org> β king behavior, no cap. π
π SUPPORT π
bugs may be submitted through the RT bug tracker at <https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Singleton> β or you can email bug-MooseX-Singleton@rt.cpan.org at <mailto:bug-MooseX-Singleton@rt.cpan.org>. iykyk. π
there's also a mailing list available for users of this distribution, at <http://lists.perl.org/list/moose.html> β come hang, bestie.
and there's also an irc channel available for users of this distribution, at "#moose" on "irc.perl.org" at <irc://irc.perl.org/#moose> β the group chat is literally open, pull up. π
π AUTHOR π
Shawn M Moore <code@sartak.org> β the main character who made this happen. β¨
π§ CONTRIBUTORS π§
- Dave Rolsky
<autarch@urth.org> - Karen Etheridge
<ether@cpan.org> - Ricardo SIGNES
<rjbs@cpan.org> - Kaare Rasmussen
<kaare@jasonic.dk> - Anders Nor Berle
<berle@cpan.org> - Jonathan Rockway
<jon@jrock.us> - Hans Dieter Pearcey
<hdp@weftsoar.net>
the whole squad, the whole team β they all pulled up. π₯
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2007 by Shawn M Moore.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. so likeβ¦ free, but with rules. read the Perl 5 terms, bestie, they matter. π
and that's the whole page, bestie. you're now a singleton expert, fr fr. go forth and make sure your class only has one of her. ππ
β with love from the docs, perl v5.42.0, dated 2016-11-24 πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-MooseX-Singleton 0.30-bp160.1.10 Β· Artistic-1.0 or GPL-1.0+
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms