-
-
Save anonymous/46da99bcb774f2eb98fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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