Skip to content

Instantly share code, notes, and snippets.

View tmp.raku
use v6.d;
multi sub trait_mod:<is>(Exception:U $ex, :$refineable) {
$ex.HOW.add_attribute($ex, Attribute.new(:name<@refinements>, :type(Array), :package($ex)));
$ex.HOW.add_method($ex, ‚refine‘, my method (&cond, &message) {
$ex.WHO::<@refinements>.append: &cond, &message;
state $wrapped;
$ex.HOW.find_method($ex, ‚message‘).wrap(my method {
my @refinements := self.WHO::<@refinements>;
for @refinements -> &cond, &message {
View tmp.raku
use v6.d;
class C {
has $.foo;
has $.bar;
method m {
my %h = foo => 1, bar => 2;
for self.^attributes {
.set_value(self, %h{.name.subst(/^'$!'/, '')})
}
View tmp.raku
use v6;
class Shell::Piping::Exitcode {
has $.exitint;
has $.command;
has @.STDERR;
multi method ACCEPTS(::?CLASS:D: Numeric $rhs) {
$!exitint ~~ $rhs
}
View tmp.raku
use v6;
class Shell::Piping::Exitcode {
has $.exitint;
has $.command;
has @.STDERR;
multi method ACCEPTS(::?CLASS:D: Numeric $rhs) {
$!exitint ~~ $rhs
}
View tmp.raku
use v6;
class Exitcode does Positional {
has @.captured handles <elems AT-POS EXISTS-POS iterator>;
}
my $ex = Exitcode.new: :captured(<abc def ghi>);
say $ex[1];
say $ex ~~ /a/;
View failspec.txt
############ RUN 1
Test Summary Report
-------------------
t/spec/S16-filehandles/filetest.rakudo.moar (Wstat: 12800
Tests: 128 Failed: 50)
Failed tests: 57-64, 69-72, 77-80, 83-84, 87-88, 91-92
95-96, 101-112, 115-128
Non-zero exit status: 50
t/spec/S32-io/chdir.t (Wstat: 9472
View errorer
#! /usr/bin/env raku
# $*ERR.say: "<ERROR MESSAGE>";
for lines() -> $l {
if 10.rand < 2 {
$*ERR.say: $l;
} else {
$*OUT.say: $l;
}
View shell-pipe-class.raku
use v6;
## agregation of STDERR
## filtering of STDERR for colour coding and ENV vars
## exception handling with STDERR stashing
## https://colabti.org/irclogger/irclogger_log/raku?date=2020-07-04#l268
subset Arrayish of Any where { .^can(‚push‘) && .^can(‚list‘) }
class Shell::Pipe {
View threaded-proc-async.raku
use v6;
my @list = 1..10;
my @results;
loop {
@results = @list[^24].hyper(:degree(2), :batch(1)).map({ my $type = run('/bin/ls', :out).out.slurp.chars; $_ but role Mime { has $.mime = $type } });
dd @results[0].mime;
last if now > 5 + BEGIN now;
}
View exceptional-run.raku
use v6;
BEGIN {
class X::Shell::CommandNotFound is Exception {
has $.cmd;
method message { 'The shell command ⟨' ~ $.cmd ~ '⟩ was not found.' }
}
class X::Shell::NoAccess is Exception {
has $.cmd;
You can’t perform that action at this time.