line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Singleton::Role::Meta::Class; |
2
|
7
|
|
|
7
|
|
26
|
use Moose::Role; |
|
7
|
|
|
|
|
8
|
|
|
7
|
|
|
|
|
44
|
|
3
|
7
|
|
|
7
|
|
25247
|
use MooseX::Singleton::Role::Meta::Instance; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
183
|
|
4
|
7
|
|
|
7
|
|
2543
|
use MooseX::Singleton::Role::Meta::Method::Constructor; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
375
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.30'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub existing_singleton { |
9
|
27
|
|
|
27
|
0
|
317
|
my ($class) = @_; |
10
|
27
|
|
|
|
|
65
|
my $pkg = $class->name; |
11
|
|
|
|
|
|
|
|
12
|
7
|
|
|
7
|
|
30
|
no strict 'refs'; |
|
7
|
|
|
|
|
9
|
|
|
7
|
|
|
|
|
483
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# create exactly one instance |
15
|
27
|
100
|
|
|
|
26
|
if ( defined ${"$pkg\::singleton"} ) { |
|
27
|
|
|
|
|
121
|
|
16
|
7
|
|
|
|
|
7
|
return ${"$pkg\::singleton"}; |
|
7
|
|
|
|
|
21
|
|
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
20
|
|
|
|
|
38
|
return; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub clear_singleton { |
23
|
1
|
|
|
1
|
0
|
21
|
my ($class) = @_; |
24
|
1
|
|
|
|
|
5
|
my $pkg = $class->name; |
25
|
7
|
|
|
7
|
|
22
|
no strict 'refs'; |
|
7
|
|
|
|
|
7
|
|
|
7
|
|
|
|
|
493
|
|
26
|
1
|
|
|
|
|
2
|
undef ${"$pkg\::singleton"}; |
|
1
|
|
|
|
|
7
|
|
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
override _construct_instance => sub { |
30
|
|
|
|
|
|
|
my ($class) = @_; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# create exactly one instance |
33
|
|
|
|
|
|
|
my $existing = $class->existing_singleton; |
34
|
|
|
|
|
|
|
return $existing if $existing; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $pkg = $class->name; |
37
|
7
|
|
|
7
|
|
24
|
no strict 'refs'; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
156
|
|
38
|
7
|
|
|
7
|
|
25
|
no warnings 'once'; |
|
7
|
|
|
|
|
7
|
|
|
7
|
|
|
|
|
857
|
|
39
|
|
|
|
|
|
|
return ${"$pkg\::singleton"} = super; |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
if ( $Moose::VERSION >= 1.9900 ) { |
43
|
|
|
|
|
|
|
override _inline_params => sub { |
44
|
|
|
|
|
|
|
my $self = shift; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
return |
47
|
|
|
|
|
|
|
'my $existing = do {', |
48
|
|
|
|
|
|
|
'no strict "refs";', |
49
|
|
|
|
|
|
|
'no warnings "once";', |
50
|
|
|
|
|
|
|
'\${"$class\::singleton"};', |
51
|
|
|
|
|
|
|
'};', |
52
|
|
|
|
|
|
|
'return ${$existing} if ${$existing};', |
53
|
|
|
|
|
|
|
super(); |
54
|
|
|
|
|
|
|
}; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
override _inline_extra_init => sub { |
57
|
|
|
|
|
|
|
my $self = shift; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
return '${$existing} = $instance;'; |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
7
|
|
|
7
|
|
29
|
no Moose::Role; |
|
7
|
|
|
|
|
5
|
|
|
7
|
|
|
|
|
25
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# ABSTRACT: Metaclass role for MooseX::Singleton |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=pod |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=encoding UTF-8 |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 NAME |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
MooseX::Singleton::Role::Meta::Class - Metaclass role for MooseX::Singleton |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 VERSION |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
version 0.30 |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 DESCRIPTION |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
This metaclass role makes sure that there is only ever one instance of an |
86
|
|
|
|
|
|
|
object for a singleton class. The first call to C<construct_instance> is run |
87
|
|
|
|
|
|
|
normally (and then cached). Subsequent calls will return the cached version. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=for Pod::Coverage *EVERYTHING* |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SUPPORT |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Singleton> |
94
|
|
|
|
|
|
|
(or L<bug-MooseX-Singleton@rt.cpan.org|mailto:bug-MooseX-Singleton@rt.cpan.org>). |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
There is also a mailing list available for users of this distribution, at |
97
|
|
|
|
|
|
|
L<http://lists.perl.org/list/moose.html>. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
There is also an irc channel available for users of this distribution, at |
100
|
|
|
|
|
|
|
L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 AUTHOR |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Shawn M Moore <code@sartak.org> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This software is copyright (c) 2007 by Shawn M Moore. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
111
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |