NAME
App::Environ - Simple environment to build applications using service locator pattern
SYNOPSIS
use App::Environ;
# Register handlers in your class
App::Environ->register( __PACKAGE__,
initialize => sub {
my $cb = pop if ref( $_[-1] ) eq 'CODE';
my @args = @_;
# handling...
},
reload => sub { ... },
'finalize:r' => sub { ... },
);
# Send events from your application
# Synchronous interface
App::Environ->send_event( 'initialize', qw( foo bar ) );
App::Environ->send_event('reload');
App::Environ->send_event('finalize:r');
# Asynchronous interface
App::Environ->send_event( 'initialize', qw( foo bar ), sub { ... } );
App::Environ->send_event( 'reload', sub { ... } );
App::Environ->send_event( 'finalize:r', sub { ... } );
DESCRIPTION
App::Environ is the simple environment to build applications using service locator pattern. Allows register different application components that provide common resources.
METHODS
register( $class, \%handlers )
Registers handlers for specified events. When an event have been sent, event handlers will be processed in order in which they was registered. If you want that event handlers have been processed in reverse order, add postfix :r
to event name.
send_event( $event [, @args ] [, $cb->() ] )
Sends specified event. All handlers registered for this event will be processed.
SEE ALSO
Also see examples from the package to better understand the concept.
AUTHOR
Eugene Ponizovsky, <ponizovsky@gmail.com>
COPYRIGHT AND LICENSE
Copyright (c) 2016, Eugene Ponizovsky, <ponizovsky@gmail.com>. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.