Documentation and little fixes. This one (0.03) is heading to CPAN
[gitmo/MooseX-Singleton.git] / lib / MooseX / Singleton / Meta / Class.pm
CommitLineData
109b110b 1#!/usr/bin/env perl
2package MooseX::Singleton::Meta::Class;
3use Moose;
4use MooseX::Singleton::Meta::Instance;
5
6extends 'Moose::Meta::Class';
7
8sub initialize {
9 my $class = shift;
10 my $pkg = shift;
11
12 $class->SUPER::initialize(
13 $pkg,
14 instance_metaclass => 'MooseX::Singleton::Meta::Instance',
15 @_,
16 );
17};
18
3822ace2 19override construct_instance => sub {
20 my ($class) = @_;
21 my $pkg = $class->name;
22
23 no strict 'refs';
24
25 # create exactly one instance
26 if (!defined ${"$pkg\::singleton"}) {
27 ${"$pkg\::singleton"} = super;
28 }
29
30 return ${"$pkg\::singleton"};
31};
32
109b110b 331;
34
b375b147 35__END__
36
37=pod
38
39=head1 NAME
40
41MooseX::Singleton::Meta::Class
42
43=head1 DESCRIPTION
44
45This metaclass is where the forcing of one instance occurs. The first call to
46C<construct_instance> is run normally (and then cached). Subsequent calls will
47return the cached version.
48
49=cut
50