ector on
the right. Our example is roughly equivalent to this closure:
{ $_.does(Str) and $_ ~~ /^[isnt|arent|amnot|aint]$/; }
except that a subtype knows when to call itself.
A subtype is not
um where { $^n % 2 == 0 }
my Str_not2b $hamlet;
$hamlet = 'isnt'; # Okay because 'isnt' ~~ /^[isnt|arent|amnot|aint]$/
$hamlet = 'amnt'; # Bzzzzzzzt! 'amnt' !~ /^[isnt|arent|amnot|a
Rules::Common :profanity;
multi sub mesg ($mesg of Str where /<profanity>/ is copy) {
$mesg ~~ s:g/<profanity>/[expletive deleted]/;
print $MESG_LOG: $mesg;
}
multi sub mesg ($mesg of
r
refered to by the 'C<_dash_profile>' element of %$meta is marked as 'in use'
then a warning is given (just once) and C<new> returns undef, so no sample is
taken.
If $allow_overlap is true, then ove
if @params[$i+1] ~~ m:perl5 {:$} {
@params[$i] ~~ s:perl5 {:$}{,};
}
}
}
my $param_list = @params.join(" ");
$param_list ~~ s:perl5 {,$}{}; # rem
"$statements\n" ~
" # TODO - _end_pad\n";
}
sub emit_Variable ( $s is copy ) {
$s ~~ s:perl5/^"(.*)"$/$0/;
$s
}
sub emit_Int ( $s ) { $s }
sub emit_Str ( $s ) { $s }
sub emit_Rat
f $default eq '';
# rewrite '$name,' to '$name = default,'
my ($name, $separator) = $param ~~ m:perl5 {(.*)(.)};
$default ~
$name ~
' = ' ~
$separator
}
# -- Main prog
for %attrs.keys.sort -> $key {
my $copy = lc $key;
$copy ~~ s:P5:g/_/-/;
my $value = ($escape) ?? simple_escape(%attrs{$key}) !! %att
scape (Str $string is copy) returns Str {
$string ~~ s:P5:g/&/&/;
$string ~~ s:P5:g/</</;
$string ~~ s:P5:g/>/>/;
$string ~~ s:P5:g/"/"/;
return $string;
}
1;
$got, Rule $expected, Str $desc?, :$todo, :$depends) returns Bool is export {
my $test := $got ~~ $expected;
Test::proclaim($test, $desc, $todo, $got, $expected, $depends);
}
## unlike
sub u
, Rule $expected, Str $desc?, :$todo, :$depends) returns Bool is export {
my $test := not($got ~~ $expected);
Test::proclaim($test, $desc, $todo, $got, $expected, $depends, :negate);
}
# eval
o, :$depends) returns Bool is export {
try { code() };
if ($!) {
&Test::ok.goto($! ~~ $match, $desc, :$todo, :$depends);
}
else {
Test::proclaim(undef, $desc, $todo, "N
$string;
$result ~~ s:Perl5:g/&\#(\d+);?/{chr($0)}/;
$result ~~ s:Perl5:g/(&\#[xX]([0-9a-fA-F]+);?)/{my $c = :16($1); $c < 256 ?? chr($c) !! $0}/;
$result ~~ s:Perl5:g/(&(\w+);?)/{%en
code\n "
# ) if $!;
#}
#%subst{$unsafe_chars}($string);
$result ~~ s:Perl5:g/([$unsafe_chars])/{
%char_to_entity.exists($0)
?? %char_to_e
}
else {
# Encode control chars, high bit chars and '<', '&', '>', '"'
$result ~~ s:perl5:g/([^\n\r\t !\#\$%\'-;=?-~])/{
%char_to_entity.exists($0)
?? %
bin/jerkme.rss HTTP/1.0\n",
"Host: www.phreeow.net\n"
);
$hdl.flush;
if ($hdl.slurp ~~ rx:perl5{<description>(.+)</description>\s*</item>}) {
say $0;
}
else {
say "*** O
sent over the wire, and analyzes the response. This line is worth
breaking down:
if ($hdl.slurp ~~ rx:perl5{<description>(.+)</description>\s*</item>}) { ... }
# Perl 5 equivalent
sub slurp {
l 5. The other difference
is that instead of using C<=~>, we now use C<~~> to match. The change
is not just one of spelling: C<~~> is the shiny new I<smart match>
operator, which has very well-defined
tem Matcher
subset Matcher of Item | Junction;
Used to supply a test to match against. Assume C<~~> will be used against it.
=item Ordering
subset KeyExtractor of Code where { .sig === :(Any -->
e where { .sig === :(Any, Any --> Int ) };
subset OrderingPair of Pair where { .left ~~ KeyExtractor && .right ~~ Comparator };
subset Ordering where Signature | KeyExtractor | Comparator | Orderin
f C<@array>, in order.
If C<@indextests> are provided, only elements whose indices match
C<$index ~~ any(@indextests)> are iterated.
What is returned at each element of the iteration varies with fun
elsif (($k.chars > 1) && (substr($k,-1,1) eq "x") # XXX - excess parens required
&& ($k ~~ %rx_helper_cache{'re_x'})) {
my $n = 0+ ~$0; # +$0 XXX
%mods.delete($k);
%mods{'
n;
}
elsif (($k.chars > 2) && (substr($k,-2,2) eq ("th"|"st"|"nd"|"rd"))
&& ($k ~~ %rx_helper_cache{'re_nth'})) {
my $n = 0+ ~$0; # +$0 XXX
%mods.delete($k);
%mods
g) {
my $s = ~$string;
my $offset = 0;
my @a;
while 1 {
my $m = $s ~~ $rx;
last if !$m;
push(@a,$m);
my $off = $m.to +1;
# $m.from += $o
ctly C<Play()> it.
The second (and third) form opens the
wave output device with the format given
(or if none given, defaults to 44.1kHz,
16 bits, stereo); to produce something
audible you can
$var (keys %{$to_instantiate||{}}){
my $class = $to_instantiate->{$var};
given(ref $class){
when('HASH'){
my ($package, $method) = %$class;
exit; # exit child
}
}
};
method _req_handler($req) {
my $res = eval {
given($req->uri){
when(m{^/(?:index(?:[.]html?)?)?$}){
return $self->_rende
to HTML
=head1 SYNOPSIS
use Text::GooglewikiFormat;
my $raw = '*bold* _italic_ ~~strike~~';
my $html = Text::GooglewikiFormat::format($raw);
# $html is qq~<p><strong>bold</st
_function_from_definition {
my ($package, $function, $fdef, $shift, $precondition) = @_;
given(ref $fdef){
when('ARRAY'){
my @fdef = @$fdef;
my $func;
= $plugin->upper_bound($port);
Returns the maximum value for the $port, or C<undef> if none is given (assume 1).
Also L</is_sample_rate|see is_sample_rate>.
=head2 is_sample_rate
my $max = $plug
ne = $fh.readline;
last unless $line.defined; # exit as soon as possible
if ($line ~~ rx:P5/^=pod/) {
$is_parsing = 1;
%events<start_document>();
}
efined($_line) &&
!($_line ~~ rx:P5/^$/) &&
$_line ~~ rx:P5/^\s(.*?)$/ ) {
while (defined($_line) &&
!($_line ~~ rx:P5/^$/) ) {
interpolate($_line, %events);
~~ m/^(\Q$const\E)(.*)/s;
# return unless @_[0] ~~ perl5:m:s:/^(\Q$const\E)(.*)/;
# return unless @_[0] ~~ /^ ( $const )(.*)/; # (putter on #perl6)
# return unless @_[0] ~~
"~~" . $::CLASS->name . "~~";
}
}
};
my $pp = $PrettyPrinter->new();
isa_ok($pp, 'PrettyPrinter');
is($pp->pretty(), '~~PrettyPrinter~~', '.
is(
$pp->pretty({ array => [ \1, \'two', $pp ] }),
'{ array => [ 1, two, ~~PrettyPrinter~~ ] }',
'... recursive multi-methods');
}
{
my $PrettyPrinter2 = class '
ty = ::multi_sub 'PrettyPrinter2::pretty' => ('PrettyPrinter2') => sub {
"~~" . $::CLASS->name . "~~";
};
$::CLASS->add_method('pretty' => ::make_method($pret
~~ m/^(\Q$const\E)(.*)/s;
# return unless @_[0] ~~ perl5:m:s:/^(\Q$const\E)(.*)/;
# return unless @_[0] ~~ /^ ( $const )(.*)/; # (putter on #perl6)
# return unless @_[0] ~~
est = =$hdl;
$request ~~ s:P5/\s+$//;
#diag $request;
if ($request ~~ rx:P5"^GET /stop-server/") {
last();
};
while (readline($hdl) ~~ rx:P5/\S/) { 1 };
$h
-)
# threads while running an external command)
for @urls -> $t_url {
my $url = $t_url;
$url ~~ s:perl5/%s/$base_url/;
my $inc = map {qq! "-I$_"!}, @*INC;
# Will block forever
# my $outpu
Perl 6: generalisierter Smart-Match-Operator
$s ~~ 1978;
$s ~~ "Hallo, Welt";
$s ~~ /regex/;
$s !~ funktion();
#=Alles zusammen: (änlich wie any)
$s ~~ (123, funktion, /regex/)
($a, $b, $c) !~ ($d, $