diff options
author | Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> | 2016-10-28 17:56:32 +0100 |
---|---|---|
committer | Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> | 2016-10-28 17:57:48 +0100 |
commit | 9c5768dfbaef3f2b5a5167a32c71d7259321e239 (patch) | |
tree | cbff1c2ecdf2096ede4823903f9f281ad3edb6c1 /t/lib | |
parent | use more signatures (diff) | |
download | Sietima-9c5768dfbaef3f2b5a5167a32c71d7259321e239.tar.gz Sietima-9c5768dfbaef3f2b5a5167a32c71d7259321e239.tar.bz2 Sietima-9c5768dfbaef3f2b5a5167a32c71d7259321e239.zip |
Use a hash for the test mailstore
Most of the operations are by ID, only retrieve_by_tags has to iterate
over the messages.
Diffstat (limited to 't/lib')
-rw-r--r-- | t/lib/Test/Sietima/MailStore.pm | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/t/lib/Test/Sietima/MailStore.pm b/t/lib/Test/Sietima/MailStore.pm index 2925fd3..030e5fc 100644 --- a/t/lib/Test/Sietima/MailStore.pm +++ b/t/lib/Test/Sietima/MailStore.pm @@ -9,15 +9,15 @@ with 'Sietima::MailStore'; has _mails => ( is => 'rw', - default => sub { +[] }, + default => sub { +{} }, ); -sub clear { shift->_mails([]) } +sub clear { shift->_mails({}) } sub store ($self,$mail,@tags) { my $str = $mail->as_string; my $id = sha1_hex($str); - push $self->_mails->@*, { + $self->_mails->{$id} = { id => $id, mail => $str, tags => { map {$_ => 1;} @tags, }, @@ -27,7 +27,7 @@ sub store ($self,$mail,@tags) { sub retrieve_by_tags ($self,@tags){ my @ret; - for my $m ($self->_mails->@*) { + for my $m (values $self->_mails->%*) { next unless all { $m->{tags}{$_} } @tags; push @ret, { $m->%{id}, @@ -39,8 +39,7 @@ sub retrieve_by_tags ($self,@tags){ } sub retrieve_by_id ($self,$id) { - for my $m ($self->_mails->@*) { - next unless $m->{id} eq $id; + if (my $m = $self->_mails->{$id}) { return Email::MIME->new($m->{mail}); } @@ -48,9 +47,7 @@ sub retrieve_by_id ($self,$id) { } sub remove($self,$id) { - my $idx = first_index { $_->{id} eq $id } $self->_mails->@*; - return unless defined $idx; - splice $self->_mails->@*,$idx,1; + delete $self->_mails->{$id}; return; } |