-
-
23 Nov 2016 04:47:31 UTC
- Distribution: MooseX-Singleton
- Module version: 0.30
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues (8)
- Testers (3967 / 2 / 0)
- Kwalitee
Bus factor: 3- 95.71% Coverage
- License: perl_5
- Perl: v5.6.0
- Activity
24 month- Tools
- Download (33.61KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 7 contributors-
Shawn M Moore
-
Dave Rolsky
-
Ricardo SIGNES
-
Kaare Rasmussen
-
Anders Nor Berle
-
Jonathan Rockway
-
Hans Dieter Pearcey
- NAME
- VERSION
- SYNOPSIS
- DESCRIPTION
- METHODS
- SOME CODE STOLEN FROM
- AND PATCHES FROM
- SUPPORT
- AUTHOR
- CONTRIBUTORS
- COPYRIGHT AND LICENSE
NAME
MooseX::Singleton - Turn your Moose class into a singleton
VERSION
version 0.30
SYNOPSIS
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;
DESCRIPTION
A singleton is a class that has only one instance in an application.
MooseX::Singleton
lets you easily upgrade (or downgrade, as it were) your Moose class to a singleton.All you should need to do to transform your class is to change
use Moose
touse MooseX::Singleton
. This module uses metaclass roles to do its magic, so it should cooperate with most otherMooseX
modules.METHODS
A singleton class will have the following additional methods:
Singleton->instance
This returns the singleton instance for the given package. This method does not accept any arguments. If the instance does not yet exist, it is created with its defaults values. This means that if your singleton requires arguments, calling
instance
will die if the object has not already been initialized.Singleton->initialize(%args)
This method can be called only once per class. It explicitly initializes the singleton object with the given arguments.
Singleton->_clear_instance
This clears the existing singleton instance for the class. Obviously, this is meant for use only inside the class itself.
Singleton->new
This method currently works like a hybrid of
initialize
andinstance
. However, callingnew
directly will probably be deprecated in a future release. Instead, callinitialize
orinstance
as appropriate.SOME CODE STOLEN FROM
Anders Nor Berle <debolaz@gmail.com>
AND PATCHES FROM
Ricardo SIGNES <rjbs@cpan.org>
SUPPORT
Bugs may be submitted through the RT bug tracker (or bug-MooseX-Singleton@rt.cpan.org).
There is also a mailing list available for users of this distribution, at http://lists.perl.org/list/moose.html.
There is also an irc channel available for users of this distribution, at
#moose
onirc.perl.org
.AUTHOR
Shawn M Moore <code@sartak.org>
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>
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.
Module Install Instructions
To install MooseX::Singleton, copy and paste the appropriate command in to your terminal.
cpanm MooseX::Singleton
perl -MCPAN -e shell install MooseX::Singleton
For more information on module installation, please visit the detailed CPAN module installation guide.