Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

moosex::singleton(3) [osx man page]

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

NAME
MooseX::Singleton - turn your Moose class into a singleton VERSION
version 0.29 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" 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. BUGS
Please report any bugs or feature requests to "bug-moosex-singleton@rt.cpan.org", or through the web interface at <http://rt.cpan.org>. We will be notified, and then you'll automatically be notified of progress on your bug as we make changes. SOME CODE STOLEN FROM
Anders Nor Berle <debolaz@gmail.com> AND PATCHES FROM
Ricardo SIGNES <rjbs@cpan.org> AUTHOR
Shawn M Moore <sartak@gmail.com> COPYRIGHT AND LICENSE
This software is copyright (c) 2011 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. perl v5.16.2 2011-12-08 MooseX::Singleton(3)

Check Out this Related Man Page

MakeMethods::Emulator::Singleton(3pm)			User Contributed Perl Documentation		     MakeMethods::Emulator::Singleton(3pm)

NAME
Class::MakeMethods::Emulator::Singleton - Emulate Class::Singleton SYNOPSIS
use Class::MakeMethods::Emulator::Singleton; # returns a new instance my $one = Class::MakeMethods::Emulator::Singleton->instance(); # returns same instance my $two = Class::MakeMethods::Emulator::Singleton->instance(); COMPATIBILITY
This module emulates the functionality of Class::Singleton, using Class::MakeMethods to generate similar methods. You may use it directly, as shown in the SYNOPSIS above, Furthermore, you may call "use Class::MakeMethods::Emulator::Singleton '-take_namespace';" to alias the Class::Singleton namespace to this package, and subsequent calls to the original package will be transparently handled by this emulator. To remove the emulation aliasing, call "use Class::MakeMethods::Emulator::Singleton '-release_namespace'". Caution: This affects all subsequent uses of Class::Singleton in your program, including those in other modules, and might cause unexpected effects. DESCRIPTION
A Singleton describes an object class that can have only one instance in any system. An example of a Singleton might be a print spooler or system registry. This module implements a Singleton class from which other classes can be derived. By itself, the Class::Singleton module does very little other than manage the instantiation of a single object. In deriving a class from Class::Singleton, your module will inherit the Singleton instantiation method and can implement whatever specific functionality is required. SEE ALSO
See Class::MakeMethods for general information about this distribution. See Class::MakeMethods::Emulator for more about this family of subclasses. See Class::Singleton for documentation of the original module. For a description and discussion of the Singleton class, see "Design Patterns", Gamma et al, Addison-Wesley, 1995, ISBN 0-201-63361-2. See "new" in Class::MakeMethods::Hash and "instance" in Class::MakeMethods::ClassVar for documentation of the created methods. perl v5.10.1 2004-09-06 MakeMethods::Emulator::Singleton(3pm)
Man Page