update ver
[gitmo/MooseX-Singleton.git] / lib / MooseX / Singleton.pm
CommitLineData
443f4253 1package MooseX::Singleton;
109b110b 2use Moose;
3use MooseX::Singleton::Object;
4use MooseX::Singleton::Meta::Class;
443f4253 5
553b1b2b 6our $VERSION = 0.05;
443f4253 7
109b110b 8sub import {
9 my $caller = caller;
443f4253 10
109b110b 11 Moose::init_meta($caller, 'MooseX::Singleton::Object', 'MooseX::Singleton::Meta::Class');
443f4253 12
109b110b 13 Moose->import({into => $caller});
14 strict->import;
15 warnings->import;
443f4253 16}
17
181;
19
b375b147 20__END__
21
22=pod
23
24=head1 NAME
25
26MooseX::Singleton - turn your Moose class into a singleton
27
28=head1 VERSION
29
553b1b2b 30Version 0.04, released 03 Feb 08
b375b147 31
32=head1 SYNOPSIS
33
34 package MyApp;
35 use MooseX::Singleton;
36
37 has env => (
38 is => 'rw',
39 isa => 'HashRef[Str]',
40 default => sub { \%ENV },
41 );
42
43 package main;
44
45 delete MyApp->env->{PATH};
46 my $instance = MyApp->instance;
47 my $same = MyApp->instance;
48
49=head1 DESCRIPTION
50
51A singleton is a class that has only one instance in an application.
52C<MooseX::Singleton> lets you easily upgrade (or downgrade, as it were) your
53L<Moose> class to a singleton.
54
55All you should need to do to transform your class is to change C<use Moose> to
56C<use MooseX::Singleton>. This module uses a new class metaclass and instance
57metaclass, so if you're doing metamagic you may not be able to use this.
58
59C<MooseX::Singleton> gives your class an C<instance> method that can be used to get a handle on the singleton. It's actually just an alias for C<new>.
60
61Alternatively, C<< YourPackage->method >> should just work. This includes
62accessors.
63
64=head1 TODO
65
66=over
67
68=item Always more tests and doc
69
70=item Fix speed boost
71
72C<instance> invokes C<new> every time C<< Package->method >> is called, which
73incurs a nontrivial runtime cost. I've implemented a short-circuit for this
74case, which does eliminate nearly all of the runtime cost. However, it's ugly
75and should be fixed in a more elegant way.
76
77=back
78
79=head1 BUGS
80
81All complex software has bugs lurking in it, and this module is no
82exception. If you find a bug please either email me, or add the bug
83to cpan-RT.
84
85=head1 AUTHOR
86
87Shawn M Moore E<lt>sartak@gmail.comE<gt>
88
89=head1 SOME CODE STOLEN FROM
90
91Anders Nor Berle E<lt>debolaz@gmail.comE<gt>
92
d64d5811 93=head1 AND PATCHES FROM
94
95Ricardo SIGNES E<lt>rjbs@cpan.orgE<gt>
96
b375b147 97=head1 COPYRIGHT AND LICENSE
98
99Copyright 2007 Shawn M Moore.
100
101This program is free software; you can redistribute it and/or modify it under
102the same terms as Perl itself.
103
104=cut
105