Venus::Role::Subscribable
Subscribable Role
Subscribable Role for Perl 5
method: publish method: subscribe method: subscribers method: unsubscribe
package Example;
use Venus::Class;
with 'Venus::Role::Subscribable';
sub execute {
$_[0]->publish('on.execute');
}
package main;
my $example = Example->new;
# $example->subscribe('on.execute', sub{...});
# bless(..., 'Example')
# $example->publish('on.execute');
# bless(..., 'Example')
This package provides a mechanism for publishing and subscribing to events.
The publish method notifies all subscribers for a given event and returns the invocant.
publish(string $name, any @args) (object)
{ since => '1.75', }
=example-1 publish
# given: synopsis
package main;
$example = $example->publish;
# bless(..., 'Example')
The subscribe method registers a subscribers (i.e. callbacks) for a given event, and returns the invocant.
subscribe(string $name, coderef $code) (object)
{ since => '1.75', }
=example-1 subscribe
# given: synopsis
package main;
$example = $example->subscribe('on.execute', sub {$example->{emitted} = [@_]});
# bless(..., 'Example')
The subscribers method returns the number of subscribers (i.e. callbacks) for a given event.
subscribers(string $name) (number)
{ since => '1.75', }
=example-1 subscribers
# given: synopsis
package main;
$example = $example->subscribers;
# 0
The unsubscribe method deregisters all subscribers (i.e. callbacks) for a given event, or a specific callback if provided, and returns the invocant.
unsubscribe(string $name, coderef $code) (object)
{ since => '1.75', }
=example-1 unsubscribe
# given: synopsis
package main;
$example = $example->unsubscribe;
# bless(..., 'Example')
t/Venus.t: present: authors t/Venus.t: present: license
28 POD Errors
The following errors were encountered while parsing the POD:
- Around line 16:
Unknown directive: =name
- Around line 24:
Unknown directive: =tagline
- Around line 32:
Unknown directive: =abstract
- Around line 40:
Unknown directive: =includes
- Around line 51:
Unknown directive: =synopsis
- Around line 87:
Unknown directive: =description
- Around line 95:
Unknown directive: =method
- Around line 100:
Unknown directive: =signature
- Around line 104:
Unknown directive: =metadata
- Around line 141:
=cut found outside a pod block. Skipping to next block.
- Around line 164:
=cut found outside a pod block. Skipping to next block.
- Around line 187:
=cut found outside a pod block. Skipping to next block.
- Around line 198:
Unknown directive: =method
- Around line 203:
Unknown directive: =signature
- Around line 207:
Unknown directive: =metadata
- Around line 257:
=cut found outside a pod block. Skipping to next block.
- Around line 276:
Unknown directive: =method
- Around line 281:
Unknown directive: =signature
- Around line 285:
Unknown directive: =metadata
- Around line 321:
=cut found outside a pod block. Skipping to next block.
- Around line 347:
=cut found outside a pod block. Skipping to next block.
- Around line 357:
Unknown directive: =method
- Around line 362:
Unknown directive: =signature
- Around line 366:
Unknown directive: =metadata
- Around line 403:
=cut found outside a pod block. Skipping to next block.
- Around line 431:
=cut found outside a pod block. Skipping to next block.
- Around line 457:
=cut found outside a pod block. Skipping to next block.
- Around line 478:
Unknown directive: =partials