1 package Thrasher
::Backend
::Test
;
5 use base
'Thrasher::Backend';
6 use Thrasher
::Callbacks
qw(callbacks);
10 Thrasher::Backend::Test - a test backed
14 This module implements a test backend for Thrasher, suitable for
15 unit testing without reference to a real storage backend.
17 This module accepts a simple hashref mapping from JIDs to the
18 hashrefs returned by C<registered>, and stores them if you
19 register. Very simple.
25 my $self = $class->SUPER::new
();
27 my $args = shift || {};
29 my $registered = $args->{registered
} || {};
30 $self->{registered
} = $registered;
32 $self->{legacy_to_jid
} = {};
33 $self->{jid_to_legacy
} = {};
43 return $self->{registered
}->{$jid};
49 my $registration_info = shift;
51 $self->{registered
}->{$jid} = $registration_info;
58 delete $self->{registered
}->{$jid};
59 delete $self->{legacy_to_jid
}->{$jid};
60 delete $self->{jid_to_legacy
}->{$jid};
63 sub retrieve_legacy_name_to_jid
{
66 my $legacy_name = shift;
67 return $self->{legacy_to_jid
}->{$user_jid}->{$legacy_name};
70 sub jid_to_legacy_name
{
74 my $stored_name = $self->{jid_to_legacy
}->{$user_jid}->{$jid};
75 return $stored_name if defined($stored_name);
77 # Otherwise, our best guess is "chop off everything after @".
78 return $self->fake_up_a_legacy_name($user_jid, $jid);
81 sub jid_has_legacy_name
{
85 return $self->{jid_to_legacy
}->{$user_jid}->{$jid};
88 sub store_username_mapping
{
92 my $mapped_jid = shift;
94 $self->{jid_to_legacy
}->{$user_jid}->{$mapped_jid} = $legacy;
95 $self->{legacy_to_jid
}->{$user_jid}->{$legacy} = $mapped_jid;
100 my $user_jid = shift;
101 return $self->{legacy_to_jid
}->{$user_jid};
106 my $user_jid = shift;
107 my $legacy_username = shift;
108 $self->{avatars
}->{$user_jid}->{$legacy_username} = shift;
113 my $user_jid = shift;
114 my $legacy_username = shift;
115 return $self->{avatars
}->{$user_jid}->{$legacy_username};
120 my $user_jid = shift;
121 return $self->{avatars
}->{$user_jid};
126 my @jids = keys %{$self->{registered
}};
132 my $user_jid = shift;
133 return $self->{roster
}->{$user_jid} || {};
138 my $user_jid = shift;
139 my $new_roster = shift;
141 $self->{roster
}->{$user_jid} = $new_roster;
144 sub set_roster_user_state
{
146 my $user_jid = shift;
147 my $legacy_username = shift;
150 if ($state == $self->unsubscribed) {
151 delete $self->{roster
}->{$user_jid}->{$legacy_username};
153 $self->{roster
}->{$user_jid}->{$legacy_username} = $state;
159 my $user_jid = shift;
163 $self->{misc
}->{$user_jid}->{$key} = $value;
168 my $user_jid = shift;
171 return $self->{misc
}->{$user_jid}->{$key};
176 my $user_jid = shift;
178 return $self->{misc
}->{$user_jid};