Created
July 29, 2020 17:56
-
-
Save gfldex/1193b1eaf86f6be0903f92541a0adad3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
class Shell::Piping::Exitcode { | |
has $.exitint; | |
has $.command; | |
has @.STDERR; | |
multi method ACCEPTS(::?CLASS:D: Numeric $rhs) { | |
$!exitint ~~ $rhs | |
} | |
multi method ACCEPTS(::?CLASS:D: Str $rhs) { | |
$!command ~~ $rhs | |
} | |
multi method ACCEPTS(::?CLASS:D: Regex $rhs) { | |
@!STDERR.join(„\n“) ~~ $rhs | |
} | |
} | |
use MONKEY-TYPING; | |
augment class Regex { | |
multi method ACCEPTS(Regex:D: Shell::Piping::Exitcode:D $ex) { | |
use nqp; | |
$/ := nqp::getlexcaller('$/'); | |
# $/ := CALLER::<$/>; | |
my $m = $ex.STDERR.join(„\n“).match(self); | |
?$m | |
} | |
} | |
augment class Int { | |
multi method ACCEPTS(Int:D: Shell::Piping::Exitcode:D $ex) { | |
self.ACCEPTS($ex.exitint) | |
} | |
} | |
augment class Str { | |
multi method ACCEPTS(Str:D: Shell::Piping::Exitcode:D $ex) { | |
self.ACCEPTS($ex.command) | |
} | |
} | |
constant Exitcode = Shell::Piping::Exitcode; | |
my $ex = Exitcode.new: :STDERR(<abc def ghi>), :exitint(42), :command<find>; | |
say $ex ~~ 42 & ‚find‘ & /def/; | |
say $ex ~~ /def/; | |
given $ex { | |
when 42 & ‚find‘ & /def\s(\S+)/ { | |
say $/; | |
note „find terminated with 42 and $0“; | |
} | |
} | |
LEAVE slurp($*PROGRAM).say; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment