line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Object::Depot::Singleton; |
2
|
7
|
|
|
7
|
|
20313
|
use strictures 2; |
|
7
|
|
|
|
|
50
|
|
|
7
|
|
|
|
|
272
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=encoding utf8 |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Object::Depot::Singleton - Expose an Object::Depot as a singleton. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
See L<Object::Depot/SYNOPSIS>. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
This role rolls up an L<Object::Depot> into a singleton |
17
|
|
|
|
|
|
|
available to all code in your application. This role is ideal for |
18
|
|
|
|
|
|
|
creating global, simplified, and centralized access to shared |
19
|
|
|
|
|
|
|
resources such as connections to internal and cloud services. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
7
|
|
|
7
|
|
1309
|
use Carp qw( croak ); |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
310
|
|
24
|
7
|
|
|
7
|
|
966
|
use Object::Depot; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
206
|
|
25
|
7
|
|
|
7
|
|
41
|
use Scalar::Util qw( blessed ); |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
388
|
|
26
|
7
|
|
|
7
|
|
2274
|
use Sub::Name qw( subname ); |
|
7
|
|
|
|
|
2834
|
|
|
7
|
|
|
|
|
386
|
|
27
|
|
|
|
|
|
|
|
28
|
7
|
|
|
7
|
|
2492
|
use Role::Tiny; |
|
7
|
|
|
|
|
25189
|
|
|
7
|
|
|
|
|
51
|
|
29
|
7
|
|
|
7
|
|
4110
|
use namespace::clean; |
|
7
|
|
|
|
|
73928
|
|
|
7
|
|
|
|
|
59
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my %DEPOTS; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub import { |
34
|
3
|
|
|
3
|
|
6355
|
my $class = shift; |
35
|
|
|
|
|
|
|
|
36
|
3
|
|
|
|
|
8
|
my $target = caller(); |
37
|
3
|
|
|
|
|
9
|
$class->depot->_export( $target, @_ ); |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
8
|
return; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 CLASS ATTRIBUTES |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 depot |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
The L<Object::Depot> singleton object. Will return C<undef> if |
47
|
|
|
|
|
|
|
L</init_depot> has not yet been called. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub depot { |
52
|
3
|
|
|
3
|
1
|
7
|
my ($class) = @_; |
53
|
3
|
|
|
|
|
17
|
return %DEPOTS{ $class }; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 CLASS METHODS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 init_depot |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__PACKAGE__->init_depot( $depot ); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Takes an L<Object::Depot> object and saves it for later retrieval by |
63
|
|
|
|
|
|
|
L</depot>. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub init_depot { |
68
|
2
|
|
|
2
|
1
|
2275
|
my $class = shift; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
croak "init_depot() has already been called on $class" |
71
|
2
|
50
|
|
|
|
9
|
if $DEPOTS{ $class }; |
72
|
|
|
|
|
|
|
|
73
|
2
|
0
|
33
|
|
|
16
|
if (@_==1 and blessed($_[0]) and $_[0]->isa('Object::Depot')) { |
|
|
|
33
|
|
|
|
|
74
|
0
|
|
|
|
|
0
|
$DEPOTS{ $class } = shift; |
75
|
0
|
|
|
|
|
0
|
return; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
2
|
|
|
|
|
11
|
$DEPOTS{ $class } = Object::Depot->new( @_ ); |
79
|
|
|
|
|
|
|
|
80
|
2
|
|
|
|
|
242
|
return; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 PROXIED METHODS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
These class methods proxy to the L</depot> object. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=over |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item L<Object::Depot/fetch> |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item L<Object::Depot/store> |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item L<Object::Depot/remove> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item L<Object::Depot/create> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item L<Object::Depot/arguments> |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item L<Object::Depot/declared_keys> |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item L<Object::Depot/inject> |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item L<Object::Depot/inject_with_guard> |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item L<Object::Depot/clear_injection> |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item L<Object::Depot/injection> |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item L<Object::Depot/has_injection> |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item L<Object::Depot/add_key> |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item L<Object::Depot/alias_key> |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=back |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
foreach my $method (qw( |
120
|
|
|
|
|
|
|
fetch |
121
|
|
|
|
|
|
|
store |
122
|
|
|
|
|
|
|
remove |
123
|
|
|
|
|
|
|
create |
124
|
|
|
|
|
|
|
arguments |
125
|
|
|
|
|
|
|
declared_keys |
126
|
|
|
|
|
|
|
inject |
127
|
|
|
|
|
|
|
inject_with_guard |
128
|
|
|
|
|
|
|
clear_injection |
129
|
|
|
|
|
|
|
injection |
130
|
|
|
|
|
|
|
has_injection |
131
|
|
|
|
|
|
|
add_key |
132
|
|
|
|
|
|
|
alias_key |
133
|
|
|
|
|
|
|
)) { |
134
|
|
|
|
|
|
|
my $sub = subname( $method => sub{ |
135
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
|
|
|
0
|
1
|
|
|
|
|
|
|
0
|
1
|
|
|
|
|
|
|
0
|
1
|
|
|
|
|
|
|
0
|
1
|
|
|
|
|
|
|
0
|
1
|
|
|
|
|
|
|
0
|
1
|
|
|
|
|
|
|
0
|
1
|
|
|
|
|
|
|
0
|
1
|
|
|
|
|
|
|
0
|
1
|
|
|
|
|
|
|
0
|
1
|
|
|
|
|
|
|
0
|
1
|
|
|
|
|
|
|
0
|
1
|
|
|
136
|
0
|
|
|
|
|
|
local $Carp::CarpInternal{ (__PACKAGE__) } = 1; |
137
|
0
|
|
|
|
|
|
return $class->depot->$method( @_ ); |
138
|
|
|
|
|
|
|
}); |
139
|
|
|
|
|
|
|
|
140
|
7
|
|
|
7
|
|
4254
|
{ no strict 'refs'; *{__PACKAGE__ . "::$method"} = $sub } |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
560
|
|
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |