<commit_before>use v6;
use Test;
plan 15;

unless (try { EVAL("1", :lang<Perl5>) }) {
    skip-rest;
    exit;
}

{
    my $r = EVAL("0", :lang<Perl5>);
    is($r, 0, "number");
}

{
    my $r = EVAL("2", :lang<Perl5>);
    is($r, 2, "number");
}

{
    my $r = EVAL('"perl6 now"', :lang<Perl5>);
    is($r, 'perl6 now', "string");
}

my $p5_dumper = EVAL('sub {return(wantarray ? @_ : $_[0]); }', :lang<Perl5>);

my %h = ( a => 1 );

{
    my $test = '%h.kv received as hash';
    my ($k,$v) = $p5_dumper(%h.kv);
    is($k, 'a', $test~' (key)');
    is($v, '1', $test~' (value)');
}

{
    my $test = q{ (VAR %h)received as hashref };
    my %o := $p5_dumper($%h);
    is(%o<a>, 1, $test);
}

my @a = <b c d>;
{
    my $test = q{ (@a) received as array };
    my @o = $p5_dumper(@a);
    is(@o[0], "b", $test);
    is(@o[2], "d", $test);
}

{
    my $test = q{ (VAR @a) received as arrayref };
    my $o = $p5_dumper($@a);
    is($o[0], "b", $test);
    is($o[2], "d", $test);
}

my $s = 'str';

{
   my $test = q{ ($s) received as scalar };
   my $o = $p5_dumper($s);
   is($o, $s, $test);
}

{
   my $test = q{ (VAR $s) received as scalarref };
   my $o = $p5_dumper(VAR $s);
   is($$o, $s, $test);
}

{
    my $test = q{ (&p6func) Passing a Raku coderef to Perl };

    sub  plus_one (Int $int) { $int+1 }
    my $sub = EVAL('sub { my $p6_coderef = shift; $p6_coderef->(3) }', :lang<Perl5>);
    my $result = $sub(&plus_one);
    is($result,4,$test);
}

#?rakudo skip "would need v5"
{
    sub add_in_perl ($x, $y) {
        use v5;
        $x + $y;
    }

    eval-lives-ok("{use v5;}", "RT #77596 - use v5 in a block lives");

    is(add_in_perl(42, 42), 84, 'Defining subroutines with "use v5" blocks');
}

# vim: ft=perl6<commit_msg>Cannot change languages in *any* scope<commit_after>use v6;
use Test;
plan 15;

unless (try { EVAL("1", :lang<Perl5>) }) {
    skip-rest;
    exit;
}

{
    my $r = EVAL("0", :lang<Perl5>);
    is($r, 0, "number");
}

{
    my $r = EVAL("2", :lang<Perl5>);
    is($r, 2, "number");
}

{
    my $r = EVAL('"perl6 now"', :lang<Perl5>);
    is($r, 'perl6 now', "string");
}

my $p5_dumper = EVAL('sub {return(wantarray ? @_ : $_[0]); }', :lang<Perl5>);

my %h = ( a => 1 );

{
    my $test = '%h.kv received as hash';
    my ($k,$v) = $p5_dumper(%h.kv);
    is($k, 'a', $test~' (key)');
    is($v, '1', $test~' (value)');
}

{
    my $test = q{ (VAR %h)received as hashref };
    my %o := $p5_dumper($%h);
    is(%o<a>, 1, $test);
}

my @a = <b c d>;
{
    my $test = q{ (@a) received as array };
    my @o = $p5_dumper(@a);
    is(@o[0], "b", $test);
    is(@o[2], "d", $test);
}

{
    my $test = q{ (VAR @a) received as arrayref };
    my $o = $p5_dumper($@a);
    is($o[0], "b", $test);
    is($o[2], "d", $test);
}

my $s = 'str';

{
   my $test = q{ ($s) received as scalar };
   my $o = $p5_dumper($s);
   is($o, $s, $test);
}

{
   my $test = q{ (VAR $s) received as scalarref };
   my $o = $p5_dumper(VAR $s);
   is($$o, $s, $test);
}

{
    my $test = q{ (&p6func) Passing a Raku coderef to Perl };

    sub  plus_one (Int $int) { $int+1 }
    my $sub = EVAL('sub { my $p6_coderef = shift; $p6_coderef->(3) }', :lang<Perl5>);
    my $result = $sub(&plus_one);
    is($result,4,$test);
}

# https://github.com/Raku/old-issue-tracker/issues/2127
{
    dies-ok { q/sub a() { use v5; }/.EVAL }, 'cannot switch languages inside a sub';
    dies-ok { q/{ use v5; }/.EVAL }, 'or any scope for that matter';
}

# vim: ft=perl6
{'fraction_non_alphanumeric': 0.2510098095787651, 'fraction_numerical': 0.02827466820542412, 'mean_word_length': 2.784934497816594, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6061681', 'n_tokens_mistral': 1659, 'n_tokens_neox': 1608, 'n_words': 407}