[libnet-dbus-perl] 276/335: Make use of Net::DBus::Callback optional & deprecated
Intrigeri
intrigeri at moszumanska.debian.org
Sat Mar 21 01:08:09 UTC 2015
This is an automated email from the git hooks/post-receive script.
intrigeri pushed a commit to branch experimental
in repository libnet-dbus-perl.
commit 4f3925261da902b856084391f299c77f03b3ec8a
Author: Daniel P. Berrange <berrange at redhat.com>
Date: Mon May 4 18:41:22 2009 +0100
Make use of Net::DBus::Callback optional & deprecated
---
examples/example-client-async.pl | 3 +--
examples/example-signal-receiver.pl | 4 ++--
lib/Net/DBus/Callback.pm | 7 ++++--
lib/Net/DBus/Reactor.pm | 43 ++++++++++++++++++++++++++-----------
4 files changed, 38 insertions(+), 19 deletions(-)
diff --git a/examples/example-client-async.pl b/examples/example-client-async.pl
index cbca6e2..deba421 100644
--- a/examples/example-client-async.pl
+++ b/examples/example-client-async.pl
@@ -5,7 +5,6 @@ use strict;
use Net::DBus;
use Net::DBus::Reactor;
-use Net::DBus::Callback;
use Net::DBus::Annotation qw(:call);
my $bus = Net::DBus->session();
@@ -35,7 +34,7 @@ sub tick {
print "Adding timer\n";
-$r->add_timeout(500, Net::DBus::Callback->new(method => \&tick));
+$r->add_timeout(500, \&tick);
print "Entering main loop\n";
$r->run;
diff --git a/examples/example-signal-receiver.pl b/examples/example-signal-receiver.pl
index c00dadc..85b2bdc 100644
--- a/examples/example-signal-receiver.pl
+++ b/examples/example-signal-receiver.pl
@@ -27,11 +27,11 @@ $object->connect_to_signal("HelloSignal", \&hello_signal_handler);
my $reactor = Net::DBus::Reactor->main();
my $ticks = 0;
-$reactor->add_timeout(1000, Net::DBus::Callback->new(method => sub {
+$reactor->add_timeout(1000, sub {
$object->emitHelloSignal();
if ($ticks++ == 10) {
$reactor->shutdown();
}
-}));
+});
$reactor->run();
diff --git a/lib/Net/DBus/Callback.pm b/lib/Net/DBus/Callback.pm
index 40b8131..fc7d48f 100644
--- a/lib/Net/DBus/Callback.pm
+++ b/lib/Net/DBus/Callback.pm
@@ -47,7 +47,10 @@ Net::DBus::Callback - a callback for receiving reactor events
This module provides a simple container for storing details
about a callback to be invoked at a later date. It is used
when registering to receive events from the L<Net::DBus::Reactor>
-class
+class. NB use of this module in application code is no longer
+neccessary and it remains purely for backwards compatability.
+Instead you can simply pass a subroutine code reference in
+any place where a callback is desired.
=head1 METHODS
@@ -129,7 +132,7 @@ Daniel P. Berrange.
=head1 COPYRIGHT
-Copyright (C) 2004-2006 Daniel P. Berrange
+Copyright (C) 2004-2009 Daniel P. Berrange
=head1 SEE ALSO
diff --git a/lib/Net/DBus/Reactor.pm b/lib/Net/DBus/Reactor.pm
index 03d61b2..7a09c7f 100644
--- a/lib/Net/DBus/Reactor.pm
+++ b/lib/Net/DBus/Reactor.pm
@@ -1,6 +1,6 @@
# -*- perl -*-
#
-# Copyright (C) 2004-2006 Daniel P. Berrange
+# Copyright (C) 2004-2009 Daniel P. Berrange
#
# This program is free software; You can redistribute it and/or modify
# it under the same terms as Perl itself. Either:
@@ -37,13 +37,13 @@ Manage some file handlers
Net::DBus::Callback->new(method => sub {
my $fd = shift;
...read some data...
- }, args => [$fd]);
+ }, args => [$fd]));
$reactor->add_write($fd,
Net::DBus::Callback->new(method => sub {
my $fd = shift;
...write some data...
- }, args => [$fd]);
+ }, args => [$fd]));
Temporarily (dis|en)able a handle
@@ -484,11 +484,12 @@ sub _dispatch_hook {
=item $reactor->add_read($fd, $callback[, $status]);
Registers a file handle for monitoring of read
-events. The C<$callback> parameter specifies an
-instance of the C<Net::DBus::Callback> object to invoke
-each time an event occurs. The optional C<$status>
-parameter is a boolean value to specify whether the
-watch is initially enabled.
+events. The C<$callback> parameter specifies either
+a code reference to a subroutine, or an instance of
+the C<Net::DBus::Callback> object to invoke each time
+an event occurs. The optional C<$status> parameter is
+a boolean value to specify whether the watch is
+initially enabled.
=cut
@@ -500,7 +501,8 @@ sub add_read {
=item $reactor->add_write($fd, $callback[, $status]);
Registers a file handle for monitoring of write
-events. The C<$callback> parameter specifies an
+events. The C<$callback> parameter specifies either
+a code reference to a subroutine, or an
instance of the C<Net::DBus::Callback> object to invoke
each time an event occurs. The optional C<$status>
parameter is a boolean value to specify whether the
@@ -517,7 +519,8 @@ sub add_write {
=item $reactor->add_exception($fd, $callback[, $status]);
Registers a file handle for monitoring of exception
-events. The C<$callback> parameter specifies an
+events. The C<$callback> parameter specifies either
+a code reference to a subroutine, or an
instance of the C<Net::DBus::Callback> object to invoke
each time an event occurs. The optional C<$status>
parameter is a boolean value to specify whether the
@@ -534,7 +537,8 @@ sub add_exception {
=item my $id = $reactor->add_timeout($interval, $callback, $status);
Registers a new timeout to expire every C<$interval>
-milliseconds. The C<$callback> parameter specifies an
+milliseconds. The C<$callback> parameter specifies either
+a code reference to a subroutine, or an
instance of the C<Net::DBus::Callback> object to invoke
each time the timeout expires. The optional C<$status>
parameter is a boolean value to specify whether the
@@ -551,6 +555,10 @@ sub add_timeout {
my $enabled = shift;
$enabled = 1 unless defined $enabled;
+ if (ref($callback) eq "CODE") {
+ $callback = Net::DBus::Callback->new(method => $callback);
+ }
+
my $key;
for (my $i = 0 ; $i <= $#{$self->{timeouts}} && !(defined $key); $i++) {
$key = $i unless defined $self->{timeouts}->[$i];
@@ -610,7 +618,8 @@ sub toggle_timeout {
Registers a new hook to be fired on each iteration
of the event loop. The C<$callback> parameter
-specifies an instance of the C<Net::DBus::Callback>
+specifies either a code reference to a subroutine, or
+an instance of the C<Net::DBus::Callback>
class to invoke. The C<$status> parameter determines
whether the hook is initially enabled, or disabled.
The return parameter is a unique id which should
@@ -624,6 +633,10 @@ sub add_hook {
my $enabled = shift;
$enabled = 1 unless defined $enabled;
+ if (ref($callback) eq "CODE") {
+ $callback = Net::DBus::Callback->new(method => $callback);
+ }
+
my $key;
for (my $i = 0 ; $i <= $#{$self->{hooks}} && !(defined $key); $i++) {
$key = $i unless defined $self->{hooks}->[$i];
@@ -682,6 +695,10 @@ sub _add {
my $enabled = shift;
$enabled = 1 unless defined $enabled;
+ if (ref($callback) eq "CODE") {
+ $callback = Net::DBus::Callback->new(method => $callback);
+ }
+
$self->{fds}->{$type}->{$fd} = {
callback => $callback,
enabled => $enabled
@@ -777,6 +794,6 @@ Daniel Berrange E<lt>dan at berrange.comE<gt>
=head1 COPYRIGHT
-Copyright 2004 by Daniel Berrange
+Copyright 2004-2009 by Daniel Berrange
=cut
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libnet-dbus-perl.git
More information about the Pkg-perl-cvs-commits
mailing list