[libbread-board-perl] 11/66: allow setting the root container multiple times

Jonas Smedegaard js at alioth.debian.org
Sun Sep 29 21:23:32 UTC 2013


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository libbread-board-perl.

commit b19834db2fd903ac3dc13ca63d4cef324a3abcad
Author: Jesse Luehrs <doy at tozt.net>
Date:   Fri Jul 20 23:08:36 2012 -0500

    allow setting the root container multiple times
    
    i'm pretty sure what we actually wanted here was to not allow setting it
    from within a container, not to disallow setting it multiple times
    entirely - that condition makes this function pretty useless (because it
    can only be used once globally across the entire program).
---
 lib/Bread/Board.pm |    5 ++++-
 t/022_sugar.t      |   15 +++++++++++++--
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/lib/Bread/Board.pm b/lib/Bread/Board.pm
index 4ccc4e6..9a95e6f 100644
--- a/lib/Bread/Board.pm
+++ b/lib/Bread/Board.pm
@@ -35,9 +35,11 @@ Moose::Exporter->setup_import_methods(
 sub as (&) { $_[0] }
 
 our $CC;
+our $in_container;
 
 sub set_root_container {
-    (defined $CC && confess "Cannot set the root container, CC is already defined $CC");
+    confess "Can't set the root container when we're already in a container"
+        if $in_container;
     $CC = shift;
 }
 
@@ -112,6 +114,7 @@ sub container ($;$$) {
     if (defined $body) {
         local $_  = $c;
         local $CC = $c;
+        local $in_container = 1;
         $body->($c);
     }
 
diff --git a/t/022_sugar.t b/t/022_sugar.t
index 66dbac2..0dbf579 100644
--- a/t/022_sugar.t
+++ b/t/022_sugar.t
@@ -35,8 +35,19 @@ my $c = container 'MyApp';
 
 Bread::Board::set_root_container($c);
 
-my $exception = exception{ Bread::Board::set_root_container($c) };
-like $exception, qr/^Cannot set the root container/, 'cannot set root container twice';
+is exception { Bread::Board::set_root_container($c) }, undef,
+   "setting the root container multiple times works";
+
+is exception { Bread::Board::set_root_container(undef) }, undef,
+   "setting the root container to undef works";
+
+container $c => as {
+    like exception { Bread::Board::set_root_container(undef) },
+         qr/Can't set the root container when we're already in a container/,
+         "can't set the root container from inside a container";
+};
+
+Bread::Board::set_root_container($c);
 
 loggers(); # reuse baby !!!
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libbread-board-perl.git



More information about the Pkg-perl-cvs-commits mailing list