File Coverage

blib/lib/MooseX/Singleton/Role/Object.pm
Criterion Covered Total %
statement 16 16 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 24 26 92.3


line stmt bran cond sub pod time code
1             package MooseX::Singleton::Role::Object;
2 7     7   2410 use Moose::Role;
  7         18408  
  7         24  
3 7     7   25619 use Carp qw( confess );
  7         10  
  7         1462  
4              
5             our $VERSION = '0.30';
6              
7 12     12 0 23866 sub instance { shift->new }
8              
9             sub initialize {
10 3     3 0 1967 my ( $class, @args ) = @_;
11              
12 3         10 my $existing = $class->meta->existing_singleton;
13 3 100       160 confess "Singleton is already initialized" if $existing;
14              
15 2         10 return $class->new(@args);
16             }
17              
18             override new => sub {
19             my ( $class, @args ) = @_;
20              
21             my $existing = $class->meta->existing_singleton;
22             confess "Singleton is already initialized" if $existing and @args;
23              
24             # Otherwise BUILD will be called repeatedly on the existing instance.
25             # -- rjbs, 2008-02-03
26             return $existing if $existing and !@args;
27              
28             return super();
29             };
30              
31             sub _clear_instance {
32 1     1   4 my ($class) = @_;
33 1         5 $class->meta->clear_singleton;
34             }
35              
36 7     7   33 no Moose::Role;
  7         8  
  7         27  
37              
38             1;
39              
40             # ABSTRACT: Object class role for MooseX::Singleton
41              
42             __END__
43              
44             =pod
45              
46             =encoding UTF-8
47              
48             =head1 NAME
49              
50             MooseX::Singleton::Role::Object - Object class role for MooseX::Singleton
51              
52             =head1 VERSION
53              
54             version 0.30
55              
56             =head1 DESCRIPTION
57              
58             =for Pod::Coverage *EVERYTHING*
59              
60             This just adds C<instance> as a shortcut for C<new>.
61              
62             =head1 SUPPORT
63              
64             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Singleton>
65             (or L<bug-MooseX-Singleton@rt.cpan.org|mailto:bug-MooseX-Singleton@rt.cpan.org>).
66              
67             There is also a mailing list available for users of this distribution, at
68             L<http://lists.perl.org/list/moose.html>.
69              
70             There is also an irc channel available for users of this distribution, at
71             L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>.
72              
73             =head1 AUTHOR
74              
75             Shawn M Moore <code@sartak.org>
76              
77             =head1 COPYRIGHT AND LICENSE
78              
79             This software is copyright (c) 2007 by Shawn M Moore.
80              
81             This is free software; you can redistribute it and/or modify it under
82             the same terms as the Perl 5 programming language system itself.
83              
84             =cut