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 15:

Unknown directive: =name

Around line 23:

Unknown directive: =tagline

Around line 31:

Unknown directive: =abstract

Around line 39:

Unknown directive: =includes

Around line 50:

Unknown directive: =synopsis

Around line 86:

Unknown directive: =description

Around line 94:

Unknown directive: =method

Around line 99:

Unknown directive: =signature

Around line 103:

Unknown directive: =metadata

Around line 140:

=cut found outside a pod block. Skipping to next block.

Around line 163:

=cut found outside a pod block. Skipping to next block.

Around line 186:

=cut found outside a pod block. Skipping to next block.

Around line 197:

Unknown directive: =method

Around line 202:

Unknown directive: =signature

Around line 206:

Unknown directive: =metadata

Around line 256:

=cut found outside a pod block. Skipping to next block.

Around line 275:

Unknown directive: =method

Around line 280:

Unknown directive: =signature

Around line 284:

Unknown directive: =metadata

Around line 320:

=cut found outside a pod block. Skipping to next block.

Around line 346:

=cut found outside a pod block. Skipping to next block.

Around line 356:

Unknown directive: =method

Around line 361:

Unknown directive: =signature

Around line 365:

Unknown directive: =metadata

Around line 410:

=cut found outside a pod block. Skipping to next block.

Around line 438:

=cut found outside a pod block. Skipping to next block.

Around line 464:

=cut found outside a pod block. Skipping to next block.

Around line 485:

Unknown directive: =partials