MooseX::Singleton(3pm)

MooseX::Singleton3pm

Turn your moose class into a singleton

Usage

    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;

Version

version 0.30

Overview

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" to "use MooseX::Singleton". This module uses metaclass roles to do its magic, so it should cooperate with most other "MooseX" 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" and "instance". However, calling "new" directly will probably be deprecated in a future release. Instead, call "initialize" or "instance" as appropriate.

Some code stolen from

Anders Nor Berle <[email protected]>

And patches from

Ricardo SIGNES <[email protected]>

Support

Bugs may be submitted through the RT bug tracker <https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Singleton> (or [email protected] <mailto:[email protected]>).

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" on "irc.perl.org" <irc://irc.perl.org/#moose>.

Contributors

•

Dave Rolsky <[email protected]>

•

Karen Etheridge <[email protected]>

•

Ricardo SIGNES <[email protected]>

•

Kaare Rasmussen <[email protected]>

•

Anders Nor Berle <[email protected]>

•

Jonathan Rockway <[email protected]>

•

Hans Dieter Pearcey <[email protected]>

Releases

8 releases since Debian 6.0 (Squeeze); the text changed 3 times.

  1. 6.0
  2. 7–8
  3. 9–11
  4. 12–13

Author

Shawn M Moore <[email protected]>

From libmoosex-singleton-perl 0.30-2 in Debian 13 (Trixie). Parsed by carta from the page's man source.