summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2020-01-25 16:25:20 +0000
committerdakkar <dakkar@thenautilus.net>2020-01-25 16:25:20 +0000
commite55f4624cf43a7da5e67706d2759a38298b327e7 (patch)
tree22cca5121fe86413984d71339a5db70142ea8cd6
parentsay where things went wrong (diff)
downloadMaildirIndexer-e55f4624cf43a7da5e67706d2759a38298b327e7.tar.gz
MaildirIndexer-e55f4624cf43a7da5e67706d2759a38298b327e7.tar.bz2
MaildirIndexer-e55f4624cf43a7da5e67706d2759a38298b327e7.zip
Revert "fewer temporary variables"
This reverts commit 314ee051c170c33d2c912b6750f916b73f9cb507. I think that the bug with LEAVE messes up return values inside Log::Timeline as well
-rw-r--r--lib/MaildirIndexer/Email.rakumod8
-rw-r--r--lib/MaildirIndexer/Index/ByAddresses.rakumod11
-rw-r--r--lib/MaildirIndexer/Index/ByRef.rakumod11
-rw-r--r--lib/MaildirIndexer/Parser.rakumod35
-rw-r--r--lib/MaildirIndexer/ScanDir.rakumod2
-rw-r--r--lib/MaildirIndexer/Store.rakumod9
-rw-r--r--t/store.t2
7 files changed, 43 insertions, 35 deletions
diff --git a/lib/MaildirIndexer/Email.rakumod b/lib/MaildirIndexer/Email.rakumod
index aabf185..4f92106 100644
--- a/lib/MaildirIndexer/Email.rakumod
+++ b/lib/MaildirIndexer/Email.rakumod
@@ -18,9 +18,11 @@ method refs(--> Iterable) {
multi split-refs(Any --> Iterable) { return () }
multi split-refs(Str:D $str --> Iterable) {
+ my @result;
MaildirIndexer::LogTimelineSchema::Parse::Header.log: {
- return $/<refs>».Str if $str ~~ m{'<' $<refs> = (<-[<>]>+)+ % [ '>' .*? '<' ] '>' };
+ @result = $/<refs>».Str if $str ~~ m{'<' $<refs> = (<-[<>]>+)+ % [ '>' .*? '<' ] '>' };
}
+ return @result;
}
method addresses (--> Iterable) {
@@ -57,9 +59,11 @@ my grammar Address {
multi sub extract-addresses(Any --> Iterable) { return () }
multi sub extract-addresses(Str:D $str --> Iterable) {
+ my @result;
MaildirIndexer::LogTimelineSchema::Parse::Header.log: {
with Address.parse($str) {
- return $_<addr>».Str;
+ @result = $_<addr>».Str;
}
}
+ return @result;
}
diff --git a/lib/MaildirIndexer/Index/ByAddresses.rakumod b/lib/MaildirIndexer/Index/ByAddresses.rakumod
index 678254e..d420c3e 100644
--- a/lib/MaildirIndexer/Index/ByAddresses.rakumod
+++ b/lib/MaildirIndexer/Index/ByAddresses.rakumod
@@ -61,7 +61,7 @@ submethod account-for(Str @addresses,Str $mailbox,Int $step) {
}
method add-mail(MaildirIndexer::Email:D $email, Str:D $mailbox --> Nil) {
- MaildirIndexer::LogTimelineSchema::Index::Add.log: :class('ByAddresses'),:$mailbox, {
+ MaildirIndexer::LogTimelineSchema::Index::Add.log: :class('ByAddresses'),:$mailbox, -> {
# ignore adding the same file twice, files in maildirs are
# immutable
return if %!addresses-for-file{ $email.path }:exists;
@@ -76,7 +76,7 @@ method add-mail(MaildirIndexer::Email:D $email, Str:D $mailbox --> Nil) {
}
method del-path(IO:D $file, Str:D $mailbox --> Nil) {
- MaildirIndexer::LogTimelineSchema::Index::Rm.log: :class('ByAddresses'),:$mailbox, {
+ MaildirIndexer::LogTimelineSchema::Index::Rm.log: :class('ByAddresses'),:$mailbox, -> {
# using assignment would fail when the path isn't present in
# the hash, because it tries to assign the (undefined)
# Array[Str] as a single element, instead of splatting it;
@@ -107,12 +107,13 @@ submethod predict-mailbox-given-addresses(@addresses) {
}
method mailbox-for-email(MaildirIndexer::Email:D $email --> Str) {
- MaildirIndexer::LogTimelineSchema::Index::Find.log: :class('ByAddresses'), {
+ my Str $result;
+ MaildirIndexer::LogTimelineSchema::Index::Find.log: :class('ByAddresses'), -> {
my %prediction = self.predict-mailbox-given-addresses($email.addresses);
my @most-probable-mailboxes = %prediction.pairs.sort(*.value);
- if @most-probable-mailboxes -> $_ { return .[*-1].key }
- else { return Nil }
+ if @most-probable-mailboxes -> $_ { $result = .[*-1].key }
}
+ return $result;
}
diff --git a/lib/MaildirIndexer/Index/ByRef.rakumod b/lib/MaildirIndexer/Index/ByRef.rakumod
index 3a5ebdb..6e5b7f5 100644
--- a/lib/MaildirIndexer/Index/ByRef.rakumod
+++ b/lib/MaildirIndexer/Index/ByRef.rakumod
@@ -13,7 +13,7 @@ method dump() {
}
method add-mail(MaildirIndexer::Email:D $email, Str:D $mailbox --> Nil) {
- MaildirIndexer::LogTimelineSchema::Index::Add.log: :class('ByRef'),:$mailbox, {
+ MaildirIndexer::LogTimelineSchema::Index::Add.log: :class('ByRef'),:$mailbox, -> {
# ignore adding the same file twice, files in maildirs are
# immutable
return if %!id-for-file{ $email.path }:exists;
@@ -26,7 +26,7 @@ method add-mail(MaildirIndexer::Email:D $email, Str:D $mailbox --> Nil) {
}
method del-path(IO:D $file, Str:D $mailbox --> Nil) {
- MaildirIndexer::LogTimelineSchema::Index::Rm.log: :class('ByRef'),:$mailbox, {
+ MaildirIndexer::LogTimelineSchema::Index::Rm.log: :class('ByRef'),:$mailbox, -> {
my $id = %!id-for-file{ $file.path }:delete or return;
with %!mailboxes-for-id{ $id } -> $boxes {
$boxes{$mailbox}:delete;
@@ -36,10 +36,11 @@ method del-path(IO:D $file, Str:D $mailbox --> Nil) {
}
method mailbox-for-email(MaildirIndexer::Email:D $email --> Str) {
- MaildirIndexer::LogTimelineSchema::Index::Find.log: :class('ByRef'), {
+ my Str $result;
+ MaildirIndexer::LogTimelineSchema::Index::Find.log: :class('ByRef'), -> {
for |$email.refs() -> $ref {
- with %!mailboxes-for-id{$ref} { return .keys.sort.[0] }
+ with %!mailboxes-for-id{$ref} { $result = .keys.sort.[0] }
}
- return Nil;
}
+ return $result;
}
diff --git a/lib/MaildirIndexer/Parser.rakumod b/lib/MaildirIndexer/Parser.rakumod
index 7623d17..d30ca86 100644
--- a/lib/MaildirIndexer/Parser.rakumod
+++ b/lib/MaildirIndexer/Parser.rakumod
@@ -61,32 +61,34 @@ my class Message-actions {
}
multi parse-email(IO::Path:D $p --> MaildirIndexer::Email) is export {
- MaildirIndexer::LogTimelineSchema::Parse::Email::File.log: :file($p.path), {
+ my MaildirIndexer::Email $result;
+ MaildirIndexer::LogTimelineSchema::Parse::Email::File.log: :file($p.path), -> {
# as of 2019,11, `slurp` replaces all \r\n with \n ??
- return parse-email($p.slurp(:enc<utf8-c8>), path => $p);
+ $result = parse-email($p.slurp(:enc<utf8-c8>), path => $p);
}
+ return $result;
}
multi parse-email(IO::Path:D $p, :$headers-only! --> MaildirIndexer::Email) is export {
- # due to a bug, we can't put that LEAVE inside the inner block;
- # see https://github.com/rakudo/rakudo/issues/2380
- my IO::Handle $h; LEAVE { .close with $h };
- MaildirIndexer::LogTimelineSchema::Parse::Email::File.log: :file($p.path), {
- $h = $p.open(
+ my MaildirIndexer::Email $result;
+ MaildirIndexer::LogTimelineSchema::Parse::Email::File.log: :file($p.path), -> {
+ my IO::Handle $h = $p.open(
:enc<utf8-c8>,
:nl-in(@separators),
:!chomp,
);
- return parse-email(
+ $result = parse-email(
$h.lines()[0],
path => $p,
);
+ $h.close();
}
+ return $result;
}
multi parse-email(IO::Socket::Async:D $s --> MaildirIndexer::Email) is export {
- MaildirIndexer::LogTimelineSchema::Parse::Email::Socket.log: {
- my MaildirIndexer::Email $result;
+ my MaildirIndexer::Email $result;
+ MaildirIndexer::LogTimelineSchema::Parse::Email::Socket.log: -> {
my $string;
react {
whenever $s.Supply(:enc<utf8-c8>) {
@@ -98,18 +100,17 @@ multi parse-email(IO::Socket::Async:D $s --> MaildirIndexer::Email) is export {
QUIT { done };
}
}
- return $result;
}
+ return $result;
}
multi parse-email(Str:D $email-str, :$path = IO --> MaildirIndexer::Email) is export {
- MaildirIndexer::LogTimelineSchema::Parse::Email::Str.log: {
- CATCH { return .fail };
+ my MaildirIndexer::Email $result;
+ MaildirIndexer::LogTimelineSchema::Parse::Email::Str.log: -> {
+ CATCH { warn $_; return Nil };
with Message.parse($email-str,:actions(Message-actions.new(:$path))) {
- return .made;
- }
- else {
- return Nil;
+ $result = .made;
}
}
+ return $result;
}
diff --git a/lib/MaildirIndexer/ScanDir.rakumod b/lib/MaildirIndexer/ScanDir.rakumod
index 4d6230d..f0ea0b7 100644
--- a/lib/MaildirIndexer/ScanDir.rakumod
+++ b/lib/MaildirIndexer/ScanDir.rakumod
@@ -7,7 +7,7 @@ sub scan-dir(*@paths --> Supply) is export {
supply {
my %watched-dirs;
- CATCH { when X::IO { }; default { warn .gist; done } }
+ CATCH { when X::IO { }; default { warn $_; done } }
sub start-watching(IO::Path $dir) {
%watched-dirs{$dir.Str} = True;
diff --git a/lib/MaildirIndexer/Store.rakumod b/lib/MaildirIndexer/Store.rakumod
index 02ffa1d..791f9a4 100644
--- a/lib/MaildirIndexer/Store.rakumod
+++ b/lib/MaildirIndexer/Store.rakumod
@@ -25,12 +25,12 @@ method start(--> Nil) {
MaildirIndexer::LogTimelineSchema::Scan::End.log();
}
when $file ~~ :e & :f {
- MaildirIndexer::LogTimelineSchema::Store::Add.log: :file($file.path), {
+ MaildirIndexer::LogTimelineSchema::Store::Add.log: :file($file.path), -> {
self.add-file($file);
}
}
when $file ~~ :!e {
- MaildirIndexer::LogTimelineSchema::Store::Rm.log: :file($file.path), {
+ MaildirIndexer::LogTimelineSchema::Store::Rm.log: :file($file.path), -> {
self.del-file($file);
}
}
@@ -57,14 +57,15 @@ method del-file(IO:D $file --> Nil) {
}
method mailbox-for-email(MaildirIndexer::Email:D $email --> Str) {
+ my Str $result;
MaildirIndexer::LogTimelineSchema::Store::Find.log: {
$!lock.protect: {
for @!indices -> $index {
- with $index.mailbox-for-email($email) { return $_ };
+ with $index.mailbox-for-email($email) { $result = $_; last };
}
}
- return Nil;
}
+ return $result;
}
sub mailbox-from-path(Str() $path --> Str) {
diff --git a/t/store.t b/t/store.t
index 8544442..d5b2502 100644
--- a/t/store.t
+++ b/t/store.t
@@ -42,7 +42,7 @@ subtest 'finding' => {
is-deeply(
@responses,
- $['1','2','1',Nil],
+ $['1','2','1',Str],
'indexes are consulted until a defined value',
);
}