| 1 | package Bread::Board::LifeCycle::Session; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | our $AUTHORITY = 'cpan:GSG'; | |||||||||
| 4 | # ABSTRACT: A short-lived singleton for Bread::Board | ||||||||||
| 5 | 2 | ▶ | use version; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | our $VERSION = 'v0.900.1'; # VERSION | |||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use Module::Runtime (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 2 | our $FLUSHER_ROLE = 'Bread::Board::Container::Role::WithSessions'; | |||||||||
| 13 | |||||||||||
| 14 | 2 | with 'Bread::Board::LifeCycle::Singleton'; | |||||||||
| 15 | |||||||||||
| 16 | ### XXX: Lifecycle consumption happens after service construction, | ||||||||||
| 17 | ### so we have pick a method that would get called after | ||||||||||
| 18 | ### construction. The 'get' method is pretty hot, so this should | ||||||||||
| 19 | ### be done as fast as possible. | ||||||||||
| 20 | |||||||||||
| 21 | 6 | ▶ | before get => sub { | ||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||
| 22 | 6 | my $self = shift; | |||||||||
| 23 | |||||||||||
| 24 | # Assume we've already done this if an instance exists | ||||||||||
| 25 | 6 | ▶ | return if $self->has_instance; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | |||||||||||
| 27 | 6 | Module::Runtime::require_module($FLUSHER_ROLE); | |||||||||
| 28 | |||||||||||
| 29 | 6 | my @containers = ($self->get_root_container); | |||||||||
| 30 | |||||||||||
| 31 | # Traverse the sub containers and apply the WithSessions role | ||||||||||
| 32 | 6 | ▶ | while (my $container = shift @containers) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 6 | push @containers, values %{$container->sub_containers}; | |||||||||
| 34 | |||||||||||
| 35 | 6 | ▶ | Class::MOP::class_of($FLUSHER_ROLE)->apply($container) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | unless $container->meta->does_role($FLUSHER_ROLE); | ||||||||||
| 37 | } | ||||||||||
| 38 | 2 | }; | |||||||||
| 39 | |||||||||||
| 40 | 2 | 1; | |||||||||
| 41 | |||||||||||
| 42 | __END__ | ||||||||||