Bread-Board-LifeCycle-Session
view release on metacpan or search on metacpan
lib/Bread/Board/LifeCycle/Session.pm view on Meta::CPAN
package Bread::Board::LifeCycle::Session;
our $AUTHORITY = 'cpan:GSG';
# ABSTRACT: A short-lived singleton for Bread::Board
use version;
our $VERSION = 'v0.900.1'; # VERSION
use Moose::Role;
use Module::Runtime ();
use namespace::autoclean;
our $FLUSHER_ROLE = 'Bread::Board::Container::Role::WithSessions';
with 'Bread::Board::LifeCycle::Singleton';
### XXX: Lifecycle consumption happens after service construction,
### so we have pick a method that would get called after
### construction. The 'get' method is pretty hot, so this should
### be done as fast as possible.
before get => sub {
my $self = shift;
# Assume we've already done this if an instance exists
return if $self->has_instance;
Module::Runtime::require_module($FLUSHER_ROLE);
my @containers = ($self->get_root_container);
# Traverse the sub containers and apply the WithSessions role
while (my $container = shift @containers) {
push @containers, values %{$container->sub_containers};
Class::MOP::class_of($FLUSHER_ROLE)->apply($container)
unless $container->meta->does_role($FLUSHER_ROLE);
}
};
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Bread::Board::LifeCycle::Session - A short-lived singleton for Bread::Board
=head1 VERSION
version v0.900.1
=head1 SYNOPSIS
use Bread::Board;
my $c = container 'Reports' => as {
service generic_report => (
class => 'Report',
lifecycle => 'Session',
);
};
sub dispatch {
# ... dispatch code ...
my $services_flushed = $c->flush_session_instances;
( run in 1.522 second using v1.01-cache-2.11-cpan-39bf76dae61 )