Perl6-Pugs

 view release on metacpan or  search on metacpan

misc/pX/Common/lrep-compiler/Runtime/RuleCompiler.pm  view on Meta::CPAN

use strict;
our @EXPORT_OK = qw(rule);

sub compiled {
    my $class = shift;
    my $code = shift;
    my ($grammar) = caller;
    bless { code => $code, grammar => $grammar }, $class;
}

sub rule(&) {
    my $rule = shift;
    return Runtime::RuleCompiler->compiled(sub {
       	my $grammar = shift;
	my $tree;
	print Dumper($rule->($grammar)->( $_[0], undef, $tree, $tree )) if $ENV{DEBUG_lrep};
	Pugs::Runtime::Rule::rule_wrapper($_[0],$rule->($grammar)->( $_[0], undef, $tree, $tree )); 
    })->code();
}
sub perl5 {
    my $self = shift;

t/blocks/lexical_subs.t  view on Meta::CPAN

plan 6;

sub f() { 
    my sub g(){"g"}; my sub h(){g()}; h();
};
is(f(),'g');


sub foo($x) { $x + 1 }

sub callit(&foo) {
    foo(1);
}

is(foo(1), 2);
is(callit({ $^x + 2 }), 3, "lexical subs get precedence over package subs");

sub infix:<@@> ($x, $y) { $x + $y }

sub foo2(&infix:<@@>) {
    2 @@ 3;
}

is(2 @@ 3, 5);
is(foo2({ $^a * $^b }), 6);

{
    my sub test_this {
        ok 1, "Could call ok from within a lexical sub";
        return 1;



( run in 0.828 second using v1.01-cache-2.11-cpan-49f99fa48dc )