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

MooseX::Role::Parameterized::Extending(3)		User Contributed Perl Documentation		 MooseX::Role::Parameterized::Extending(3)

NAME
MooseX::Role::Parameterized::Extending - extending MooseX::Role::Parameterized roles DESCRIPTION
There are heaps of useful modules in the "MooseX" namespace that you can use to make your roles more powerful. However, they do not always work out of the box with MooseX::Role::Parameterized, but it's fairly straight-forward to achieve the functionality you desire. MooseX::Role::Parameterized was designed to be as extensible as the rest of Moose, and as such it is possible to apply custom traits to both the parameterizable role or the ordinary roles they generate. In this example, we will look at applying the fake trait "MooseX::MagicRole" to a parameterizable role. First we need to define a new metaclass for our parameterizable role. package MyApp::Meta::Role::Parameterizable; use Moose; extends 'MooseX::Role::Parameterized::Meta::Role::Parameterizable'; with 'MooseX::MagicRole'; This is a class (observe that it uses Moose, not Moose::Role) which extends the class which governs parameterizable roles. MooseX::Role::Parameterized::Meta::Role::Parameterizable is the metaclass that packages using MooseX::Role::Parameterized receive by default. Note that the class we are extending, MooseX::Role::Parameterized::Meta::Role::Parameterizable, is entirely distinct from the similarly- named class which governs the ordinary roles that parameterized roles generate. An instance of MooseX::Role::Parameterized::Meta::Role::Parameterized represents a role with its parameters already bound. Now we can take advantage of our new subclass by specifying that we want to use "MyApp::Meta::Role::Parameterizable" as our metaclass when importing MooseX::Role::Parameterized: package MyApp::Role; use MooseX::Role::Parameterized -metaclass => 'MyApp::Meta::Role::Parameterizable'; role { ... } And there you go! "MyApp::Role" now has the "MooseX::MagicRole" trait applied. perl v5.18.2 2012-08-14 MooseX::Role::Parameterized::Extending(3)
Man Page