Skip to content

Instantly share code, notes, and snippets.

/test.pl Secret

Created December 28, 2012 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/46da99bcb774f2eb98fa to your computer and use it in GitHub Desktop.
Save anonymous/46da99bcb774f2eb98fa to your computer and use it in GitHub Desktop.
use v6;
module MyApp {
class Foo {
has $.name;
has $.things = [];
method add_thing (Foo $thing) {
$.things.push($thing);
}
}
our $dyn;
sub foo (Foo $thing, Callable $body) is export {
if $dyn {
$dyn.add_thing($thing);
}
temp $dyn = $thing;
$body.();
return $thing;
}
}
import MyApp;
my $foo = foo MyApp::Foo.new(name => 'a'), {
foo MyApp::Foo.new(name => 'b'), sub {
};
foo MyApp::Foo.new(name => 'c'), {
foo MyApp::Foo.new(name => 'd'), sub {
};
};
};
say $foo.perl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment