summaryrefslogtreecommitdiffstats
path: root/lib/Bread/Board.pm
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-12-28 14:59:34 -0600
committerJesse Luehrs <doy@tozt.net>2012-12-28 14:59:34 -0600
commit54cb9b50f55b77758a8bf0666acd962e4d56c544 (patch)
tree9b0a8fbc50366bac0a1fa10db1de29571224a0e3 /lib/Bread/Board.pm
parentaa83df0cf585876df5901d15ae959fe319ee2dfe (diff)
downloadp6-bread-board-54cb9b50f55b77758a8bf0666acd962e4d56c544.tar.gz
p6-bread-board-54cb9b50f55b77758a8bf0666acd962e4d56c544.zip
implement set_root_container and friends
Diffstat (limited to 'lib/Bread/Board.pm')
-rw-r--r--lib/Bread/Board.pm27
1 files changed, 22 insertions, 5 deletions
diff --git a/lib/Bread/Board.pm b/lib/Bread/Board.pm
index 39b5a4b..eecec5c 100644
--- a/lib/Bread/Board.pm
+++ b/lib/Bread/Board.pm
@@ -360,19 +360,36 @@ role Singleton does Lifecycle is export {
}
our $CC;
+our $in_container = False;
+
+our sub set_root_container (Container $c) {
+ die "Can't set the root container when we're already in a container"
+ if $in_container;
+ $CC = $c;
+}
proto container is export {*}
-multi container (Container $c, Callable $body) {
+multi container (Container $c, Callable $body = sub {}) {
$CC.add_sub_container($c)
if $CC;
- temp $CC = $c;
- $body.();
+ # PERL6: temp doesn't work properly in multisubs
+ #temp $CC = $c;
+ #temp $in_container = True;
+ #$body.();
+ my $old_CC = $CC;
+ my $old_in_container = $in_container;
+ $CC = $c;
+ $in_container = True;
+ {
+ LEAVE { $CC = $old_CC; $in_container = $old_in_container };
+ $body.();
+ }
$c;
}
-multi container (Str $name, Callable $body) {
+multi container (Str $name, Callable $body = sub {}) {
container(Container.new(name => $name), $body);
}
-multi container (Callable $body) {
+multi container (Callable $body = sub {}) {
container(Container.new, $body);
}