| 1 | package Mojo::Events; | ||
| 2 | 2 | ▶ | use Mojo::Base -base; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | |||
| 4 | 2 | ▶ | use Mojo::Events::Dispatcher; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 2 | ▶ | use Mojo::Events::Listeners; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 2 | ▶ | use Mojo::Server; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 2 | our $VERSION = '0.0.2'; | |
| 10 | |||
| 11 | 0 | ▶ | has app => sub { Mojo::Server->new->build_app('Mojo::HelloWorld') }, weak => 1; |
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||
| 12 | 0 | ▶ | has namespaces => sub { [] }; |
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||
| 13 | |||
| 14 | 0 | ▶ | has dispatcher => sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 15 | 0 | my $self = shift; | |
| 16 | |||
| 17 | 0 | return Mojo::Events::Dispatcher->new(app => $self->app, namespaces => $self->namespaces); | |
| 18 | 2 | }; | |
| 19 | |||
| 20 | 2 | 1; | |
| 21 | |||
| 22 | =encoding utf8 | ||
| 23 | |||
| 24 | =head1 NAME | ||
| 25 | |||
| 26 | Mojo::Events - Dispatch and handle sync/async events in Mojolicious | ||
| 27 | |||
| 28 | =head1 SYNOPSIS | ||
| 29 | |||
| 30 | use Mojo::Events; | ||
| 31 | |||
| 32 | my $events = Mojo::Events->new(app => $app, namespaces => ['Listeners::Namespace']); | ||
| 33 | |||
| 34 | $events->dispatcher->dispatch(say => 'Hello!'); | ||
| 35 | |||
| 36 | =head1 DESCRIPTION | ||
| 37 | |||
| 38 | L<Mojo::Events> is a very basic implementation for events/listeners | ||
| 39 | |||
| 40 | =head1 ATTRIBUTES | ||
| 41 | |||
| 42 | L<Mojo::Events> inherits all attributes from L<Mojo::Base>. | ||
| 43 | |||
| 44 | =head1 METHODS | ||
| 45 | |||
| 46 | L<Mojo::Events> inherits all methods from L<Mojo::Base> and implements | ||
| 47 | the following new ones. | ||
| 48 | |||
| 49 | =head2 new | ||
| 50 | |||
| 51 | my $events = Mojo::Events->new(app => $app, namespaces => ['Listeners::Namespace']); | ||
| 52 | |||
| 53 | Events manipulator object. | ||
| 54 | |||
| 55 | =head2 dispatcher | ||
| 56 | |||
| 57 | my $dispatcher = $events->dispatcher; | ||
| 58 | |||
| 59 | # dispatch an event | ||
| 60 | $dispatcher->dispatch(event_name => (<event args>)); | ||
| 61 | |||
| 62 | # register a new listener | ||
| 63 | $dispatcher->register(My::Custom::Listener->new(app => $mojolicious)); | ||
| 64 | |||
| 65 | Events dispatcher. | ||
| 66 | |||
| 67 | =head1 SEE ALSO | ||
| 68 | |||
| 69 | L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>. | ||
| 70 | |||
| 71 | =cut | ||