| 1 | package DJabberd::RosterStorage; | ||
| 2 | # abstract base class | ||
| 3 | 20 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 20 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 20 | ▶ | use base 'DJabberd::Plugin'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 20 | ▶ | use DJabberd::Roster; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 20 | ▶ | use DJabberd::RosterItem; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | ### store the object in a closure, so we can retrieve it later | ||
| 10 | ### this allows us to manipulate the roster storage from other | ||
| 11 | ### places, to for example pre-link users. | ||
| 12 | 20 | { my $singleton; | |
| 13 | 0 | ▶ | sub singleton { $singleton }; |
|
Subroutine
singleton: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 14 | |||
| 15 | 42 | ▶ | sub new { |
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 16 | 42 | my $self = shift; | |
| 17 | 42 | $singleton = $self->SUPER::new( @_ ); | |
| 18 | } | ||
| 19 | } | ||
| 20 | |||
| 21 | # don't override, or at least call SUPER to this if you do. | ||
| 22 | 20 | ▶ | sub register { |
|
Subroutine
register: called CC=1 SCAR=2.0
Pod
undocumented
| |||
| 23 | 42 | my ($self, $vhost) = @_; | |
| 24 | 0 | ▶ | $vhost->register_hook("RosterGet", sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 25 | 0 | my ($vh, $cb, $jid) = @_; | |
| 26 | # cb can '->set_roster(Roster)' or decline | ||
| 27 | 0 | $self->get_roster($cb, $jid); | |
| 28 | 42 | }); | |
| 29 | 0 | ▶ | $vhost->register_hook("RosterAddUpdateItem", sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 30 | 0 | my ($vh, $cb, $jid, $ritem) = @_; | |
| 31 | # $cb takes ->done($ritem_final) or error | ||
| 32 | 0 | $self->addupdate_roster_item($cb, $jid, $ritem); | |
| 33 | 42 | }); | |
| 34 | 0 | ▶ | $vhost->register_hook("RosterRemoveItem", sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 35 | 0 | my ($vh, $cb, $jid, $ritem) = @_; | |
| 36 | # $cb can ->done | ||
| 37 | 0 | $self->delete_roster_item($cb, $jid, $ritem); | |
| 38 | 42 | }); | |
| 39 | 0 | ▶ | $vhost->register_hook("RosterLoadItem", sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 40 | 0 | my ($vh, $cb, $user_jid, $contact_jid) = @_; | |
| 41 | # cb can 'set($data|undef)' and 'error($reason)' | ||
| 42 | 0 | $self->load_roster_item($user_jid, $contact_jid, $cb); | |
| 43 | 42 | }); | |
| 44 | |||
| 45 | 0 | ▶ | $vhost->register_hook("RosterSetItem", sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 46 | 0 | my ($vh, $cb, $user_jid, $ritem) = @_; | |
| 47 | # cb can ->error($reason) and ->done() | ||
| 48 | 0 | $self->set_roster_item($cb, $user_jid, $ritem); | |
| 49 | 42 | }); | |
| 50 | 0 | ▶ | $vhost->register_hook("RosterWipe", sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 51 | 0 | my ($vh, $cb, $user_jid) = @_; | |
| 52 | # cb can ->error($reason) and ->done() | ||
| 53 | 0 | $self->wipe_roster($cb, $user_jid); | |
| 54 | 42 | }); | |
| 55 | |||
| 56 | } | ||
| 57 | |||
| 58 | # override this. | ||
| 59 | 0 | ▶ | sub get_roster { |
|
Subroutine
get_roster: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 60 | 0 | my ($self, $cb, $jid) = @_; | |
| 61 | 0 | $cb->declined; | |
| 62 | } | ||
| 63 | |||
| 64 | # override this. | ||
| 65 | 0 | ▶ | sub addupdate_roster_item { |
|
Subroutine
addupdate_roster_item: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 66 | 0 | my ($self, $cb, $jid, $ritem) = @_; | |
| 67 | 0 | $cb->declined; | |
| 68 | } | ||
| 69 | |||
| 70 | # override this. unlike addupdate, you should respect the subscription level | ||
| 71 | 0 | ▶ | sub set_roster_item { |
|
Subroutine
set_roster_item: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 72 | 0 | my ($self, $cb, $jid, $ritem) = @_; | |
| 73 | 0 | warn "SET ROSTER ITEM FAILED\n"; | |
| 74 | 0 | $cb->error; | |
| 75 | } | ||
| 76 | |||
| 77 | # override this. | ||
| 78 | 0 | ▶ | sub delete_roster_item { |
|
Subroutine
delete_roster_item: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 79 | 0 | my ($self, $cb, $jid, $ritem) = @_; | |
| 80 | 0 | $cb->declined; | |
| 81 | } | ||
| 82 | |||
| 83 | # override this. | ||
| 84 | 0 | ▶ | sub load_roster_item { |
|
Subroutine
load_roster_item: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 85 | 0 | my ($self, $jid, $target_jid, $cb) = @_; | |
| 86 | 0 | $cb->error("load_roster_item not implemented"); | |
| 87 | } | ||
| 88 | |||
| 89 | # override this. | ||
| 90 | 0 | ▶ | sub wipe_roster { |
|
Subroutine
wipe_roster: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 91 | 0 | my ($self, $cb, $jid) = @_; | |
| 92 | 0 | $cb->error("wipe_roster not implemented"); | |
| 93 | } | ||
| 94 | |||
| 95 | 20 | 1; | |