line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::DeclareX::Plugin::singleton; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
BEGIN { |
4
|
1
|
|
|
1
|
|
28485
|
$MooseX::DeclareX::Plugin::singleton::AUTHORITY = 'cpan:TOBYINK'; |
5
|
1
|
|
|
|
|
21
|
$MooseX::DeclareX::Plugin::singleton::VERSION = '0.003'; |
6
|
|
|
|
|
|
|
} |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
467
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
with 'MooseX::DeclareX::Plugin'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use MooseX::Declare 0 (); |
12
|
|
|
|
|
|
|
use Moose::Util (); |
13
|
|
|
|
|
|
|
use MooseX::Singleton::Role::Object 0 (); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub _callback |
16
|
|
|
|
|
|
|
{ |
17
|
|
|
|
|
|
|
my $caller = shift; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Moose::Util::MetaRole::apply_metaroles( |
20
|
|
|
|
|
|
|
for => $caller, |
21
|
|
|
|
|
|
|
class_metaroles => { |
22
|
|
|
|
|
|
|
class => ['MooseX::Singleton::Role::Meta::Class'], |
23
|
|
|
|
|
|
|
instance => ['MooseX::Singleton::Role::Meta::Instance'], |
24
|
|
|
|
|
|
|
constructor => ['MooseX::Singleton::Role::Meta::Method::Constructor'], |
25
|
|
|
|
|
|
|
}, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
Moose::Util::MetaRole::apply_base_class_roles( |
28
|
|
|
|
|
|
|
for => $caller, |
29
|
|
|
|
|
|
|
roles => ['MooseX::Singleton::Role::Object'], |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub plugin_setup |
34
|
|
|
|
|
|
|
{ |
35
|
|
|
|
|
|
|
my ($class, $kw) = @_; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
if ($kw->isa('MooseX::DeclareX::Keyword::class')) |
38
|
|
|
|
|
|
|
{ |
39
|
|
|
|
|
|
|
$kw->register_feature(singleton => sub { |
40
|
|
|
|
|
|
|
my ($self, $ctx, $package) = @_; |
41
|
|
|
|
|
|
|
$ctx->add_early_cleanup_code_parts( |
42
|
|
|
|
|
|
|
"MooseX::DeclareX::Plugin::singleton::_callback(q[$package])" |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
}); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__END__ |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 NAME |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
MooseX::DeclareX::Plugin::singleton - shiny syntax for MooseX::Singleton |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 SYNOPSIS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
class Logger is singleton |
60
|
|
|
|
|
|
|
{ |
61
|
|
|
|
|
|
|
method log ($str) { |
62
|
|
|
|
|
|
|
...; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Logger->instance->log("here we are!"); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 DESCRIPTION |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This distribution extends MooseX::DeclareX with a new plugin: |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=over |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item C<< is singleton >> |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Marks a class as a singleton, providing C<< instance >> and C<< initialize >> |
77
|
|
|
|
|
|
|
methods as per L<MooseX::Singleton>. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=back |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 BUGS |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
B<Known issue:> you may occasionally get errors about inlining the constructor. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Please report any bugs to |
86
|
|
|
|
|
|
|
L<http://rt.cpan.org/Dist/Display.html?Queue=MooseX-DeclareX-Plugin-singleton>. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 SEE ALSO |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
L<MooseX::DeclareX>, L<MooseX::Singleton>. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 AUTHOR |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Toby Inkster E<lt>tobyink@cpan.orgE<gt>. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Toby Inkster. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
101
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTIES |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
106
|
|
|
|
|
|
|
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
107
|
|
|
|
|
|
|
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
108
|
|
|
|
|
|
|
|