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
conversation
$conn->on(conversation => sub { my ($conn, $conversation) = @_; });
Emitted when a new $conversation is created.
me
$conn->on(me => sub { my ($conn, $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
$conn->on(message => sub { my ($conn, $conn, $msg) = @_; });
$conn->on(message => sub { my ($conn, $conversation, $msg) = @_; });
Emitted when a connection or conversation receives a new message. $msg
will contain:
{
from => $str,
message => $str,
type => {action|error|notice|privmsg},
}
state
$conn->on(state => sub { my ($conn, $state, $reason) = @_; });
Emitted when the connection state change.
conversation
$conn->on(conversation => sub { my ($conn, $conversation, $info) = @_; });
Emitted when the conversation 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 = $conn->id;
$str = $class->id(\%attr);
Returns a unique identifier for a connection.
info
$hash_ref = $conn->info;
Holds misc information about the connection.
messages
$obj = $conn->messages;
Holds a Convos::Core::Conversation object with the conversation to the server.
on_connect_commands
$array_ref = $conn->on_connect_commands;
$conn = $conn->on_connect_commands([...]);
Holds a list of commands to execute when first connected.
name
$str = $conn->name;
Holds the name of the connection.
profile
$profile = $conn->profile;
$conn = $conn->profile(Convos::Core::ConnectionProfile->new);
Holds a Convos::Core::ConnectionProfile object from "connection_settings" in Convos::Core.
reconnect_delay
$num = $conn->reconnect_delay;
$conn = $conn->reconnect_delay(4);
When the next automatic reconnect should happen after a failed "connect_p".
url
$url = $conn->url;
Holds a Mojo::URL object which describes where to connect to. This attribute is read-only.
user
$user = $conn->user;
Holds a Convos::Core::User object that owns this connection.
wanted_state
$conn = $conn->wanted_state("disconnected");
$str = $conn->wanted_state;
Used to change the state that the user want the connection to be in. Note that it is also required to call "connect_p" and "disconnect" to actually change the state.
METHODS
Convos::Core::Connection inherits all methods from Mojo::Base and implements the following new ones.
connect_p
$p = $conn->connect_p;
Used to connect to "url". Meant to be overloaded in a subclass.
conversation
$conversation = $conn->conversation(\%attrs);
Returns a new Convos::Core::Conversation object or updates an existing object.
conversations
$objs = $conn->conversations;
Returns an array-ref of of Convos::Core::Conversation objects.
disconnect_p
$p = $conn->disconnect_p;
Used to disconnect from server. Meant to be overloaded in a subclass.
get_conversation
$conversation = $conn->get_conversation($id);
$conversation = $conn->get_conversation(\%attrs);
Returns a Convos::Core::Conversation object or undef.
new
$conn = Convos::Core::Connection->new(\%attrs);
Creates a new connection object.
nick
$str = $connection->nick;
Returns the current nick.
reconnect_p
$p = $connection->reconnect_p;
Same as calling "disconnect_p" and then "connect_p".
save_p
$p = $conn->save_p->then(sub { my $conn = shift });
Will save "ATTRIBUTES" to persistent storage. See "save_object" in Convos::Core::Backend for details.
send_p
$p = $conn->send_p($target => $message);
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
$conn = $conn->state($state, $message);
$state = $conn->state;
Holds the state of this object. $state
can be "disconnecting", "disconnected", "connecting" or "connected".
uri
$path = $conn->uri;
Holds a Mojo::Path object, with the URI to where this object should be stored.