LifeCycle/Session/WithParameters.pm

filter: Statementstmt 100% 24 / 24 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 34 / 34 CC 4 SCAR 10.0
CC
4
Cov
100%
__ANON__
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.7
« Container/Role/WithSessions.pm ↑ Summary LifeCycle/Session.pm »
1 package Bread::Board::LifeCycle::Session::WithParameters;
2  
3 2 our $AUTHORITY = 'cpan:GSG';
4 2 our $VERSION = '0.90';
5  
6 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Module::Runtime ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $FLUSHER_ROLE = 'Bread::Board::Container::Role::WithSessions';
11  
12 2 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 4 ▶before get => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
20 4 my $self = shift;
21  
22 # Assume we've already done this if any instance exists
23 4 ▶ return if values %{$self->instances};
Branch: 1 branch
BranchTrueFalseTotal
if values %{$self->instances;} 2 2 4
24  
25 2 Module::Runtime::require_module($FLUSHER_ROLE);
26  
27 2 my @containers = ($self->get_root_container);
28  
29 # Traverse the sub containers and apply the WithSessions role
30 2 ▶ while (my $container = shift @containers) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $container = shift @containers) 2 2 4
31 2 push @containers, values %{$container->sub_containers};
32  
33 2 ▶ Class::MOP::class_of($FLUSHER_ROLE)->apply($container)
Branch: 1 branch
BranchTrueFalseTotal
unless $container->meta->does_role($Bread::Board::LifeCycle::Session::WithParameters::FLUSHER_ROLE) 1 1 2
34 unless $container->meta->does_role($FLUSHER_ROLE);
35 }
36 2 };
37  
38 2 1;
39  
40 __END__
« Container/Role/WithSessions.pm ↑ Summary LifeCycle/Session.pm »