The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Convos::Core::Connection - A Convos connection base class

DESCRIPTION

Convos::Core::Connection is a base class for Convos connections.

See also Convos::Core::Connection::Irc.

EVENTS

dialog

  $self->on(dialog => sub { my ($self, $dialog) = @_; });

Emitted when a new $dialog is created.

me

  $self->on(me => sub { my ($self, $me) = @_; });

Emitted when information about the representation of "user" changes. $me contains:

  {
    nick                     => $str,
    real_host                => $str,
    version                  => $str,
    available_user_modes     => $str,
    available_channel_modes  => $str,
  }

Note that this hash is Convos::Core::Connection::Irc specific.

message

  $self->on(message => sub { my ($self, $self, $msg) = @_; });
  $self->on(message => sub { my ($self, $dialog, $msg) = @_; });

Emitted when a connection or dialog receives a new message. $msg will contain:

  {
    from    => $str,
    message => $str,
    type    => {action|notice|privmsg},
  }

state

  $self->on(state => sub { my ($self, $state, $reason) = @_; });

Emitted when the connection state change.

dialog

  $self->on(dialog => sub { my ($self, $dialog, $info) = @_; });

Emitted when the dialog change state. $info will contain information about the change:

  {join => $nick}
  {nick => $new_new, renamed_from => $old_nick_lc}
  {part => $nick, message => $reason, kicker => $kicker}
  {part => $nick, message => $reason}
  {updated => true}

ATTRIBUTES

Convos::Core::Connection inherits all attributes from Mojo::Base and implements the following new ones.

id

  $str = $self->id;
  $str = $class->id(\%attr);

Returns a unique identifier for a connection.

messages

  $obj = $self->messages;

Holds a Convos::Core::Dialog object with the conversation to the server.

name

  $str = $self->name;

Holds the name of the connection.

protocol

  $str = $self->protocol;

Holds the protocol name.

url

  $url = $self->url;

Holds a Mojo::URL object which describes where to connect to. This attribute is read-only.

user

  $user = $self->user;

Holds a Convos::Core::User object that owns this connection.

METHODS

Convos::Core::Connection inherits all methods from Mojo::Base and implements the following new ones.

connect

  $self = $self->connect(sub { my ($self, $err) = @_ });

Used to connect to "url". Meant to be overloaded in a subclass.

dialog

  $dialog = $self->dialog(\%attrs);

Returns a new Convos::Core::Dialog object or updates an existing object.

dialogs

  $objs = $self->dialogs;

Returns an array-ref of of Convos::Core::Dialog objects.

disconnect

  $self = $self->disconnect(sub { my ($self, $err) = @_ });

Used to disconnect from server. Meant to be overloaded in a subclass.

get_dialog

  $dialog = $self->get_dialog($id);
  $dialog = $self->get_dialog(\%attrs);

Returns a Convos::Core::Dialog object or undef.

new

  $self = Convos::Core::Connection->new(\%attrs);

Creates a new connection object.

participants

  $self = $self->participants("#target" => sub { my ($self, $err, $participants) = @_; });

Retrieves a list of participants in a room.

rooms

  $self = $self->rooms({match => "name"}, sub { my ($self, $err, $list) = @_; });

Used to retrieve a list of Convos::Core::Dialog objects for the given connection.

save

  $self = $self->save(sub { my ($self, $err) = @_; });

Will save "ATTRIBUTES" to persistent storage. See "save_object" in Convos::Core::Backend for details.

send

  $self = $self->send($target => $message, sub { my ($self, $err, $any) = @_; });

Used to send a $message to $target. $message is a plain string and $target can be a user or room/channel name.

Meant to be overloaded in a subclass.

state

  $self = $self->state($state, $message);
  $state = $self->state;

Holds the state of this object. $state can be "disconnected", "connected" or "queued" (default). "queued" means that the object is in the process of connecting or that it want to connect.

uri

  $path = $self->uri;

Holds a Mojo::Path object, with the URI to where this object should be stored.

wanted_state

  $str = $self->wanted_state;
  $self = $self->wanted_state("connected"); # or "disconnected"

The state that this connection should be in. "state" on the other hand reflects which state the connection is actually in.

AUTHOR

Jan Henning Thorsen - jhthorsen@cpan.org