File Coverage

blib/lib/Bread/Board/LifeCycle/Session/WithParameters.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package Bread::Board::LifeCycle::Session::WithParameters;
2              
3             our $AUTHORITY = 'cpan:GSG';
4             our $VERSION = '0.90';
5              
6 1     1   6519 use Moose::Role;
  1         3  
  1         9  
7 1     1   4519 use Module::Runtime ();
  1         2  
  1         14  
8 1     1   3 use namespace::autoclean;
  1         2  
  1         7  
9              
10             our $FLUSHER_ROLE = 'Bread::Board::Container::Role::WithSessions';
11              
12             with 'Bread::Board::LifeCycle::Singleton::WithParameters';
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 any instance exists
23             return if values $self->instances;
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::WithParameters
49              
50             =head1 VERSION
51              
52             version 0.90
53              
54             =head1 DESCRIPTION
55              
56             This lifecycle type is a flushable version of L<Bread::Board::LifeCycle::Singleton::WithParameters>. Like
57             L<Session|Bread::Board::LifeCycle::Session>, the same L<flush_session_instances|Bread::Board::Container::Role::WithSessions/flush_session_instances>
58             method is applied to all of its containers.