From: Michael Stapelberg Date: Mon, 22 Mar 2010 21:33:26 +0000 (+0100) Subject: Use $self->message in subscribe X-Git-Tag: AnyEvent-0.02~5 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=0271f14b08a43bb87250de66489d99497b6d86a6;p=i3%2Fi3 Use $self->message in subscribe --- diff --git a/lib/AnyEvent/I3.pm b/lib/AnyEvent/I3.pm index 282f24a5..310fa5ef 100644 --- a/lib/AnyEvent/I3.pm +++ b/lib/AnyEvent/I3.pm @@ -157,24 +157,25 @@ sub _handle_i3_message { Subscribes to the given event types. This function awaits a hashref with the key being the name of the event and the value being a callback. - $i3->subscribe({ + my %callbacks = ( workspace => sub { say "Workspaces changed" } - }); + ); + + if ($i3->subscribe(\%callbacks)->recv->{success}) + say "Successfully subscribed"; + } =cut sub subscribe { my ($self, $callbacks) = @_; - my $payload = encode_json [ keys %{$callbacks} ]; - my $len = length($payload); - my $message = $magic . pack("LL", $len, TYPE_SUBSCRIBE) . $payload; - $self->{ipchdl}->push_write($message); - # Register callbacks for each message type for my $key (keys %{$callbacks}) { my $type = $events{$key}; $self->{callbacks}->{$type} = $callbacks->{$key}; } + + $self->message(TYPE_SUBSCRIBE, [ keys %{$callbacks} ]) } =head2 $i3->message($type, $content)