Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Contact Us
Online Help
Domain Status
Man Pages

Virtual Servers

Topology Map

Server Agreement
Year 2038

USA Flag



Man Pages
MooseX::Singleton(3) User Contributed Perl Documentation MooseX::Singleton(3)

MooseX::Singleton - Turn your Moose class into a singleton

version 0.30

    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;

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.

A singleton class will have the following additional methods:

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.

This method can be called only once per class. It explicitly initializes the singleton object with the given arguments.

This clears the existing singleton instance for the class. Obviously, this is meant for use only inside the class itself.

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.

Anders Nor Berle <>

Ricardo SIGNES <>

Bugs may be submitted through the RT bug tracker <> (or <>).
There is also a mailing list available for users of this distribution, at <>.
There is also an irc channel available for users of this distribution, at "#moose" on "" <irc://>.

Shawn M Moore <>

Dave Rolsky <>
Karen Etheridge <>
Ricardo SIGNES <>
Kaare Rasmussen <>
Anders Nor Berle <>
Jonathan Rockway <>
Hans Dieter Pearcey <>

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.
2016-11-23 perl v5.28.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.