aboutsummaryrefslogtreecommitdiff
path: root/lib/Sietima/MailStore/FS.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Sietima/MailStore/FS.pm')
-rw-r--r--lib/Sietima/MailStore/FS.pm56
1 files changed, 37 insertions, 19 deletions
diff --git a/lib/Sietima/MailStore/FS.pm b/lib/Sietima/MailStore/FS.pm
index c429dfd..9a77c3c 100644
--- a/lib/Sietima/MailStore/FS.pm
+++ b/lib/Sietima/MailStore/FS.pm
@@ -2,8 +2,8 @@ package Sietima::MailStore::FS;
use Moo;
use Sietima::Policy;
use Types::Path::Tiny qw(Dir);
-use Types::Standard qw(Object ArrayRef Str slurpy);
-use Type::Params qw(compile);
+use Types::Standard qw(Object ArrayRef Str Slurpy);
+use Type::Params -sigs;
use Sietima::Types qw(EmailMIME TagName);
use Digest::SHA qw(sha1_hex);
use namespace::clean;
@@ -72,15 +72,21 @@ get the same identifier.
=cut
-sub store($self,$mail,@tags) {
- state $check = compile(Object,EmailMIME,slurpy ArrayRef[TagName]);$check->(@_);
+signature_for store => (
+ method => Object,
+ positional => [
+ EmailMIME,
+ Slurpy[ArrayRef[TagName]],
+ ],
+);
+sub store($self,$mail,$tags) {
my $str = $mail->as_string;
my $id = sha1_hex($str);
$self->_msgdir->child($id)->spew_raw($str);
- $self->_tagdir->child($_)->append("$id\n") for @tags;
+ $self->_tagdir->child($_)->append("$id\n") for $tags->@*;
return $id;
}
@@ -98,9 +104,11 @@ list context.
=cut
+signature_for retrieve_by_id => (
+ method => Object,
+ positional => [ Str ],
+);
sub retrieve_by_id($self,$id) {
- state $check = compile(Object,Str);$check->(@_);
-
my $msg_path = $self->_msgdir->child($id);
return unless -e $msg_path;
return Email::MIME->new($msg_path->slurp_raw);
@@ -126,13 +134,17 @@ sub _tagged_by($self,$tag) {
return $tag_file->lines({chomp=>1});
}
-sub retrieve_ids_by_tags($self,@tags) {
- state $check = compile(Object,slurpy ArrayRef[TagName]);$check->(@_);
-
+signature_for retrieve_ids_by_tags => (
+ method => Object,
+ positional => [
+ Slurpy[ArrayRef[TagName]],
+ ],
+);
+sub retrieve_ids_by_tags($self,$tags) {
# this maps: id -> how many of the given @tags it has
my %msgs;
- if (@tags) {
- for my $tag (@tags) {
+ if ($tags->@*) {
+ for my $tag ($tags->@*) {
$_++ for @msgs{$self->_tagged_by($tag)};
}
}
@@ -144,7 +156,7 @@ sub retrieve_ids_by_tags($self,@tags) {
for my $id (keys %msgs) {
# if this message id does not have all the required tags, we
# won't return it
- next unless $msgs{$id} == @tags;
+ next unless $msgs{$id} == $tags->@*;
push @ret, $id;
}
return \@ret;
@@ -164,11 +176,15 @@ returns an arrayref of hashrefs like:
=cut
-sub retrieve_by_tags($self,@tags) {
- state $check = compile(Object,slurpy ArrayRef[TagName]);$check->(@_);
-
+signature_for retrieve_by_tags => (
+ method => Object,
+ positional => [
+ Slurpy[ArrayRef[TagName]],
+ ],
+);
+sub retrieve_by_tags($self,$tags) {
my @ret;
- for my $id ($self->retrieve_ids_by_tags(@tags)->@*) {
+ for my $id ($self->retrieve_ids_by_tags($tags->@*)->@*) {
push @ret, {
id => $id,
mail => $self->retrieve_by_id($id),
@@ -187,9 +203,11 @@ from disk. Removing a non-existent message does nothing.
=cut
+signature_for remove => (
+ method => Object,
+ positional => [ Str ],
+);
sub remove($self,$id) {
- state $check = compile(Object,Str);$check->(@_);
-
for my $tag_file ($self->_tagdir->children) {
$tag_file->edit_lines( sub { $_='' if /\A\Q$id\E\n?\z/ } );
}