summaryrefslogtreecommitdiff
path: root/lib/MaildirIndexer/Parser.rakumod
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2020-01-25 15:35:02 +0000
committerdakkar <dakkar@thenautilus.net>2020-01-25 15:38:23 +0000
commit314ee051c170c33d2c912b6750f916b73f9cb507 (patch)
tree8b5ed72f69791d17d7d2f5e0ed83cb03f152f8b3 /lib/MaildirIndexer/Parser.rakumod
parentnicer scan-dir signature (diff)
downloadMaildirIndexer-314ee051c170c33d2c912b6750f916b73f9cb507.tar.gz
MaildirIndexer-314ee051c170c33d2c912b6750f916b73f9cb507.tar.bz2
MaildirIndexer-314ee051c170c33d2c912b6750f916b73f9cb507.zip
fewer temporary variables
we can `return` from an inner block, even when that block is executed somewhere else: `return` is lexical!
Diffstat (limited to 'lib/MaildirIndexer/Parser.rakumod')
-rw-r--r--lib/MaildirIndexer/Parser.rakumod35
1 files changed, 17 insertions, 18 deletions
diff --git a/lib/MaildirIndexer/Parser.rakumod b/lib/MaildirIndexer/Parser.rakumod
index 407078d..1762e58 100644
--- a/lib/MaildirIndexer/Parser.rakumod
+++ b/lib/MaildirIndexer/Parser.rakumod
@@ -61,34 +61,32 @@ my class Message-actions {
}
multi parse-email(IO::Path:D $p --> MaildirIndexer::Email) is export {
- my MaildirIndexer::Email $result;
- MaildirIndexer::LogTimelineSchema::Parse::Email::File.log: :file($p.path), -> {
+ MaildirIndexer::LogTimelineSchema::Parse::Email::File.log: :file($p.path), {
# as of 2019,11, `slurp` replaces all \r\n with \n ??
- $result = parse-email($p.slurp(:enc<utf8-c8>), path => $p);
+ return parse-email($p.slurp(:enc<utf8-c8>), path => $p);
}
- return $result;
}
multi parse-email(IO::Path:D $p, :$headers-only! --> MaildirIndexer::Email) is export {
- my MaildirIndexer::Email $result;
- MaildirIndexer::LogTimelineSchema::Parse::Email::File.log: :file($p.path), -> {
- my IO::Handle $h = $p.open(
+ # 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(
:enc<utf8-c8>,
:nl-in(@separators),
:!chomp,
);
- $result = parse-email(
+ return parse-email(
$h.lines()[0],
path => $p,
);
- $h.close();
}
- return $result;
}
multi parse-email(IO::Socket::Async:D $s --> MaildirIndexer::Email) is export {
- my MaildirIndexer::Email $result;
- MaildirIndexer::LogTimelineSchema::Parse::Email::Socket.log: -> {
+ MaildirIndexer::LogTimelineSchema::Parse::Email::Socket.log: {
+ my MaildirIndexer::Email $result;
my $string;
react {
whenever $s.Supply(:enc<utf8-c8>) {
@@ -99,17 +97,18 @@ multi parse-email(IO::Socket::Async:D $s --> MaildirIndexer::Email) is export {
$result = parse-email($string) and done;
}
}
+ return $result;
}
- return $result;
}
multi parse-email(Str:D $email-str, :$path = IO --> MaildirIndexer::Email) is export {
- my MaildirIndexer::Email $result;
- MaildirIndexer::LogTimelineSchema::Parse::Email::Str.log: -> {
- CATCH { warn $_; return Nil };
+ MaildirIndexer::LogTimelineSchema::Parse::Email::Str.log: {
+ CATCH { return .fail };
with Message.parse($email-str,:actions(Message-actions.new(:$path))) {
- $result = .made;
+ return .made;
+ }
+ else {
+ return Nil;
}
}
- return $result;
}