line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bread::Board::LifeCycle::Session; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:GSG'; |
4
|
|
|
|
|
|
|
our $VERSION = '0.90'; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
7536
|
use Moose::Role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
7
|
1
|
|
|
1
|
|
4300
|
use Module::Runtime (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
15
|
|
8
|
1
|
|
|
1
|
|
16
|
use namespace::autoclean; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
11
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $FLUSHER_ROLE = 'Bread::Board::Container::Role::WithSessions'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Bread::Board::LifeCycle::Singleton'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
### XXX: Lifecycle consumption happens after service construction, |
15
|
|
|
|
|
|
|
### so we have pick a method that would get called after |
16
|
|
|
|
|
|
|
### construction. The 'get' method is pretty hot, so this should |
17
|
|
|
|
|
|
|
### be done as fast as possible. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
before get => sub { |
20
|
|
|
|
|
|
|
my $self = shift; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Assume we've already done this if an instance exists |
23
|
|
|
|
|
|
|
return if $self->has_instance; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Module::Runtime::require_module($FLUSHER_ROLE); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my @containers = ($self->get_root_container); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Traverse the sub containers and apply the WithSessions role |
30
|
|
|
|
|
|
|
while (my $container = shift @containers) { |
31
|
|
|
|
|
|
|
push @containers, values %{$container->sub_containers}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Class::MOP::class_of($FLUSHER_ROLE)->apply($container) |
34
|
|
|
|
|
|
|
unless $container->meta->does_role($FLUSHER_ROLE); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
1; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
__END__ |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=pod |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=encoding UTF-8 |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 NAME |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Bread::Board::LifeCycle::Session |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 VERSION |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
version 0.90 |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 SYNOPSIS |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
use Bread::Board; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $c = container 'Reports' => as { |
59
|
|
|
|
|
|
|
service generic_report => ( |
60
|
|
|
|
|
|
|
class => 'Report', |
61
|
|
|
|
|
|
|
lifecycle => 'Session', |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
}; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub dispatch { |
66
|
|
|
|
|
|
|
# ... dispatch code ... |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $services_flushed = $c->flush_session_instances; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 DESCRIPTION |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
This implements a short-term "Session" lifecycle for Bread::Board. Services with this lifecycle will exist as a singleton until they |
74
|
|
|
|
|
|
|
are flushed with the L<flush_session_instances|Bread::Board::Container::Role::WithSessions/flush_session_instances> method. The idea is |
75
|
|
|
|
|
|
|
that this method would be called at the end of a web request, but a "session" could be defined as any sort of short-term cycle. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
The L<Bread::Board::Container::Role::WithSessions> role is applied to all containers that exist in or around the service. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This module is similar to L<Bread::Board::LifeCycle::Request>, but has no connections to L<OX>. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 AUTHOR |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Brendan Byrd C<< <BBYRD@CPAN.org> >> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Thanks to Grant Street Group L<http://www.grantstreet.com> for funding development of this code. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Thanks to Steve Grazzini (C<< <GRAZZ@CPAN.org> >>) for discussion of the concept. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Copyright 2015 Grant Street Group |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
96
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
97
|
|
|
|
|
|
|
copy of the full license at: |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
L<http://www.perlfoundation.org/artistic_license_2_0> |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
102
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
103
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
104
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
107
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
108
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
111
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
114
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
115
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
116
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
117
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
118
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
119
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
120
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
123
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
124
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
125
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
126
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
127
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
128
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
129
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |