Skip to content

Commit

Permalink
Fix %*BOT-ENV situation
Browse files Browse the repository at this point in the history
By using PROCESS variables instead. Dynamic variables shouldn't
be used in code where start blocks are common. See
rakudo/rakudo#3770.

There's probably a better way to achieve this, but for now
this will do.
  • Loading branch information
AlexDaniel committed Jun 25, 2020
1 parent 78011e8 commit 152bd39
Show file tree
Hide file tree
Showing 21 changed files with 9 additions and 35 deletions.
1 change: 0 additions & 1 deletion lib/Whateverable.pm6
Expand Up @@ -43,7 +43,6 @@ also does Whateverable::Configurable;
also does Whateverable::Discordable;

method TWEAK {
%*BOT-ENV<timeout> //= 10;
# wrap around everything to catch exceptions
once { # per class
self.^lookup(irc-to-me).wrap: sub ($self, $msg) {
Expand Down
7 changes: 6 additions & 1 deletion lib/Whateverable/Configurable.pm6
Expand Up @@ -22,7 +22,12 @@ unit role Whateverable::Configurable;
# Keep in mind that the variables are not saved anywhere and will
# be reset on bot restart.

# This role expects the class to have %.variables attribute.
# Create a global %PROCESS::BOT-ENV variable that is
# accessible as %*BOT-ENV.
INIT { # XXX Total hack, but is there a better way?
my %PROCESS::BOT-ENV := %*BOT-ENV // %();
%*BOT-ENV<timeout> = 10; # most bots expect this
}

has %!default-values; #← autopopulated based on the first encountered value

Expand Down
2 changes: 0 additions & 2 deletions xbin/Benchable.p6
Expand Up @@ -189,8 +189,6 @@ Z: loop (my $x = 0; $x < @commits - 1; $x++) {
}


my %*BOT-ENV;

Benchable.new.selfrun: benchable6, [ / bench6? <before ‘:’> /,
fuzzy-nick(benchable6, 2) ];

Expand Down
2 changes: 0 additions & 2 deletions xbin/Bisectable.p6
Expand Up @@ -273,8 +273,6 @@ sub process($msg, $code, $old, $new, @sha-gatherer?) {
}


my %*BOT-ENV;

Bisectable.new.selfrun: bisectable6, [ / [ b[isect]?6? | ‘what’ ] <before ‘:’> /,
fuzzy-nick(bisectable6, 2) ]

Expand Down
2 changes: 0 additions & 2 deletions xbin/Bloatable.p6
Expand Up @@ -123,8 +123,6 @@ method process($msg, $config, $sources is copy) {
}


my %*BOT-ENV;

Bloatable.new.selfrun: bloatable6, [ / bloat[y]?6? <before ‘:’> /,
fuzzy-nick(bloatable6, 2) ]

Expand Down
2 changes: 0 additions & 2 deletions xbin/Committable.p6
Expand Up @@ -91,8 +91,6 @@ sub process($msg, $config is copy, $code is copy, :%ENV) {
}


my %*BOT-ENV;

Committable.new.selfrun: committable6, [ / [ | c <!before [「:\」|「:/」]> [ommit]?6?
| @(shortcuts.keys) ] <before ‘:’> /,
fuzzy-nick(committable6, 3) ]
Expand Down
2 changes: 0 additions & 2 deletions xbin/Coverable.p6
Expand Up @@ -141,8 +141,6 @@ method process($msg, $config is copy, $grep, $code is copy) {
}


my %*BOT-ENV;

Coverable.new.selfrun: coverable6, [ / cover6? <before ‘:’> /,
fuzzy-nick(coverable6, 3) ];

Expand Down
2 changes: 1 addition & 1 deletion xbin/Evalable.p6
Expand Up @@ -111,7 +111,7 @@ method process($msg, $code, :$good-only?) {
}


my %*BOT-ENV = commit => HEAD;
%*BOT-ENV<commit> = HEAD;

Evalable.new.selfrun: evalable6, [/ [ | \s*[master|rakudo|‘r-m’|m|p6|perl6|raku]
| e[val]?6? | what ] <before ‘:’> /,
Expand Down
3 changes: 0 additions & 3 deletions xbin/Greppable.p6
Expand Up @@ -120,9 +120,6 @@ if $ECO-PATH.IO !~~ :d {
run <git clone>, $ECO-ORIGIN, $ECO-PATH
}


my %*BOT-ENV;

Greppable.new.selfrun: greppable6, [ / [file|tree]? grep6? <before ‘:’> /,
fuzzy-nick(greppable6, 2) ]

Expand Down
1 change: 0 additions & 1 deletion xbin/Linkable.p6
Expand Up @@ -186,7 +186,6 @@ sub fetch($prefix, $id) {
)
}

my %*BOT-ENV;

Linkable.new.selfrun: linkable6, [ fuzzy-nick(linkable6, 2) ]

Expand Down
2 changes: 0 additions & 2 deletions xbin/Nativecallable.p6
Expand Up @@ -38,7 +38,5 @@ multi method irc-to-me($msg where /^ \s* $<code>=.+ /) {
}


my %*BOT-ENV;

Nativecallable.new.selfrun: nativecallable6, [ / nativecall6? <before ‘:’> /,
fuzzy-nick(nativecallable6, 2) ];
2 changes: 0 additions & 2 deletions xbin/Notable.p6
Expand Up @@ -118,8 +118,6 @@ multi method irc-to-me($msg where
}


my %*BOT-ENV;

Notable.new.selfrun: notable6, [ / [@shortcuts]6? <before ‘:’> /,
fuzzy-nick(notable6, 1) ]

Expand Down
2 changes: 0 additions & 2 deletions xbin/Quotable.p6
Expand Up @@ -73,8 +73,6 @@ sub process-channel($file, $channel, $regex-str) {
}


my %*BOT-ENV;

Quotable.new.selfrun: quotable6, [ / quote6? <before ‘:’> /,
fuzzy-nick(quotable6, 1) ]

Expand Down
2 changes: 1 addition & 1 deletion xbin/Releasable.p6
Expand Up @@ -265,7 +265,7 @@ multi method irc-connected($msg) {
}


my %*BOT-ENV = branch => master;
%*BOT-ENV<branch> = master;

Releasable.new.selfrun: releasable6, [ / release6? <before ‘:’> /,
fuzzy-nick(releasable6, 2) ]
Expand Down
2 changes: 0 additions & 2 deletions xbin/Reportable.p6
Expand Up @@ -275,8 +275,6 @@ sub analyze(IO() $before-dir where .d, IO() $after-dir where .d) {
}


my %*BOT-ENV;

Reportable.new.selfrun: reportable6, [ / report6? <before ‘:’> /,
fuzzy-nick(reportable6, 2) ]

Expand Down
2 changes: 0 additions & 2 deletions xbin/Shareable.p6
Expand Up @@ -100,8 +100,6 @@ multi method irc-to-me($msg where /^ $<build>=[\S+] $/) {
}


my %*BOT-ENV;

Shareable.new.selfrun: shareable6, [ fuzzy-nick(shareable6, 2) ]

# vim: expandtab shiftwidth=4 ft=perl6
1 change: 0 additions & 1 deletion xbin/Sourceable.p6
Expand Up @@ -94,7 +94,6 @@ multi method irc-to-me($msg where { m:r/^ [$<maybe-rev>=\S+ \s+]? $<maybe-code>=
return $cry
}

my %*BOT-ENV;

Sourceable.new.selfrun: 'sourceable6', [ / s <before ':'> /,
fuzzy-nick('sourceable6', 2) ];
2 changes: 0 additions & 2 deletions xbin/Squashable.p6
Expand Up @@ -315,8 +315,6 @@ my $react = start react {
}


my %*BOT-ENV;

$squashable.selfrun: squashable6, [ / squash6? <before ‘:’> /,
fuzzy-nick(squashable6, 3) ]

Expand Down
1 change: 0 additions & 1 deletion xbin/Tellable.p6
Expand Up @@ -175,7 +175,6 @@ multi method irc-to-me($msg where { m:r/^ \s* [[to|tell|ask] \s+]? $<text>=[
I'll pass your message to {%seen{$normalized}<nick>}
}

my %*BOT-ENV = %();

{
# Renormalize on startup in case the rules were updated
Expand Down
2 changes: 0 additions & 2 deletions xbin/Undersightable.p6
Expand Up @@ -291,8 +291,6 @@ multi method irc-to-me($msg where /check|status|info|test|log/) {
}


my %*BOT-ENV;

Undersightable.new.selfrun: undersightable6, [ fuzzy-nick(undersightable6, 3) ]

# vim: expandtab shiftwidth=4 ft=perl6
2 changes: 1 addition & 1 deletion xbin/Unicodable.p6
Expand Up @@ -214,7 +214,7 @@ method propdump($msg, $query) {
}


my %*BOT-ENV = :30timeout;
%*BOT-ENV<timeout> = 30;

Unicodable.new.selfrun: unicodable6, [/ u[ni]?6? <before ‘:’> /, propdump, unidump,
fuzzy-nick(unicodable6, 3)];
Expand Down

0 comments on commit 152bd39

Please sign in to comment.