AnyEvent-Mattermost
view release on metacpan or search on metacpan
lib/AnyEvent/Mattermost.pm view on Meta::CPAN
=head1 METHODS
=cut
=head2 new
$mconn = AnyEvent::Mattermost->new( $host, $team, $email, $password );
Creates a new AnyEvent::Mattermost object. No connections are opened and no
callbacks are registered yet.
The C<$host> parameter must be the HTTP/HTTPS URL of your Mattermost server. If
you omit the scheme and provide only a hostname, HTTPS will be assumed. Note
that Mattermost servers configured over HTTP will also use unencrypted C<ws://>
for the persistent WebSockets connection for receiving incoming messages. You
should use HTTPS unless there is no other choice.
C<$team> must be the Mattermost team's short name (the version which appears in
the URLs when connected through the web client).
lib/AnyEvent/Mattermost.pm view on Meta::CPAN
}
=head2 stop
$mconn->stop();
Closes connection with Mattermost server and ceases processing messages.
Callbacks which have been registered are left in place in case you wish to
start() the connection again.
If you wish to remove callbacks, without disposing of the AnyEvent::Mattermost
object itself, you will need to call on() and pass C<undef> for each events'
callback value (rather than the anonymous subroutines you had provided when
registering them).
=cut
sub stop {
my ($self) = @_;
$self->{'conn'}->close;
}
=head2 on
$mconn->on( $event1 => sub {}, [ $event2 => sub {}, ... ] );
Registers a callback for the named event type. Multiple events may be registered
in a single call to on(), but only one callback may exist for any given event
type. Any subsequent callbacks registered to an existing event handler will
overwrite the previous callback.
Every callback will receive two arguments: the AnyEvent::Mattermost object and
the raw message data received over the Mattermost WebSockets connection. This
message payload will take different forms depending on the type of event which
occurred, but the top-level data structure is always a hash reference with at
least the key C<event> (with a value matching that which you used to register
the callback). Most event types include a C<data> key, whose value is a hash
reference containing the payload of the event. For channel messages this will
include things like the sender's name, the channel name and type, and of course
the message itself.
For more explanation of event types, hope that the Mattermost project documents
them at some point. For now, L<Data::Dumper> based callbacks are your best bet.
=cut
sub on {
my ($self, %registrations) = @_;
foreach my $type (keys %registrations) {
my $cb = $registrations{$type};
$self->{'registry'}{$type} = $cb;
}
( run in 0.353 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )