AnyEvent-Sway
view release on metacpan or search on metacpan
lib/AnyEvent/Sway.pm view on Meta::CPAN
my $type = $events{$key};
$self->{callbacks}->{$type} = $callbacks->{$key};
}
$self->message(TYPE_SUBSCRIBE, [ keys %{$callbacks} ])
}
=head2 $sway->message($type, $content)
Sends a message of the specified C<type> to Sway, possibly containing the data
structure C<content> (or C<content>, encoded as utf8, if C<content> is a
scalar), if specified.
my $reply = $sway->message(TYPE_RUN_COMMAND, "reload")->recv;
if ($reply->{success}) {
say "Configuration successfully reloaded";
}
=cut
sub message
{
my ($self, $type, $content) = @_;
confess "No message type specified" unless defined($type);
confess "No connection to Sway" unless defined($self->{ipchdl});
my $payload = "";
if ($content) {
if (not ref($content)) {
# Convert from Perlâs internal encoding to UTF8 octets
$payload = encode_utf8($content);
} else {
$payload = encode_json $content;
}
}
my $message = $magic . pack("LL", length($payload), $type) . $payload;
$self->{ipchdl}->push_write($message);
my $cv = AnyEvent->condvar;
# We donât preserve the old callback as it makes no sense to
( run in 0.625 second using v1.01-cache-2.11-cpan-49f99fa48dc )