1package DJabberd::PresenceChecker; 2# abstract base class 3use strict; 4use warnings; 5use base 'DJabberd::Plugin'; 6 7sub new { 8 my ($class) = @_; 9 return bless {}, $class; 10} 11 12sub vhost { $_[0]->{vhost} } 13 14sub register { 15 my ($self, $vhost) = @_; 16 17 $self->{vhost} = $vhost; 18 Scalar::Util::weaken($self->{vhost}); 19 20 # this is an odd hook, in that it wants to be called a lot, but the 21 # normal hook chain system doesn't support that, so instead 22 # this provides a cleaner interface for subclasses, which just call 23 # 'add' and 'done', and this takes care of the ugliness of calling 24 # the $add_cb callback. 25 $vhost->register_hook("PresenceCheck", sub { 26 my (undef, $cb, $jid, $add_cb) = @_; 27 # cb can 'decline' only 28 29 my $cb2 = DJabberd::Callback->new({ 30 done => sub { $cb->decline }, 31 decline => sub { $cb->decline }, 32 declined => sub { $cb->decline }, 33 }); 34 35 $self->check_presence($cb2, $jid, $add_cb); 36 37 }); 38} 39 40# override this. 41sub check_presence { 42 my ($self, $cb, $jid, $add_cb) = @_; 43 # cb can only '->done/decline' 44 $cb->done; 45} 46 471; 48