1MooseX::Singleton(3pm)User Contributed Perl DocumentationMooseX::Singleton(3pm)
2
3
4

NAME

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

VERSION

9       version 0.30
10

SYNOPSIS

12           package MyApp;
13           use MooseX::Singleton;
14
15           has env => (
16               is      => 'rw',
17               isa     => 'HashRef[Str]',
18               default => sub { \%ENV },
19           );
20
21           package main;
22
23           delete MyApp->env->{PATH};
24           my $instance = MyApp->instance;
25           my $same = MyApp->instance;
26

DESCRIPTION

28       A singleton is a class that has only one instance in an application.
29       "MooseX::Singleton" lets you easily upgrade (or downgrade, as it were)
30       your Moose class to a singleton.
31
32       All you should need to do to transform your class is to change "use
33       Moose" to "use MooseX::Singleton". This module uses metaclass roles to
34       do its magic, so it should cooperate with most other "MooseX" modules.
35

METHODS

37       A singleton class will have the following additional methods:
38
39   Singleton->instance
40       This returns the singleton instance for the given package. This method
41       does not accept any arguments. If the instance does not yet exist, it
42       is created with its defaults values. This means that if your singleton
43       requires arguments, calling "instance" will die if the object has not
44       already been initialized.
45
46   Singleton->initialize(%args)
47       This method can be called only once per class. It explicitly
48       initializes the singleton object with the given arguments.
49
50   Singleton->_clear_instance
51       This clears the existing singleton instance for the class. Obviously,
52       this is meant for use only inside the class itself.
53
54   Singleton->new
55       This method currently works like a hybrid of "initialize" and
56       "instance". However, calling "new" directly will probably be deprecated
57       in a future release. Instead, call "initialize" or "instance" as
58       appropriate.
59

SOME CODE STOLEN FROM

61       Anders Nor Berle <debolaz@gmail.com>
62

AND PATCHES FROM

64       Ricardo SIGNES <rjbs@cpan.org>
65

SUPPORT

67       Bugs may be submitted through the RT bug tracker
68       <https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Singleton>
69       (or bug-MooseX-Singleton@rt.cpan.org <mailto:bug-MooseX-
70       Singleton@rt.cpan.org>).
71
72       There is also a mailing list available for users of this distribution,
73       at <http://lists.perl.org/list/moose.html>.
74
75       There is also an irc channel available for users of this distribution,
76       at "#moose" on "irc.perl.org" <irc://irc.perl.org/#moose>.
77

AUTHOR

79       Shawn M Moore <code@sartak.org>
80

CONTRIBUTORS

82       ·   Dave Rolsky <autarch@urth.org>
83
84       ·   Karen Etheridge <ether@cpan.org>
85
86       ·   Ricardo SIGNES <rjbs@cpan.org>
87
88       ·   Kaare Rasmussen <kaare@jasonic.dk>
89
90       ·   Anders Nor Berle <berle@cpan.org>
91
92       ·   Jonathan Rockway <jon@jrock.us>
93
94       ·   Hans Dieter Pearcey <hdp@weftsoar.net>
95
97       This software is copyright (c) 2007 by Shawn M Moore.
98
99       This is free software; you can redistribute it and/or modify it under
100       the same terms as the Perl 5 programming language system itself.
101
102
103
104perl v5.30.1                      2020-01-30            MooseX::Singleton(3pm)
Impressum