From: Shawn M Moore Date: Sun, 28 Sep 2008 18:42:15 +0000 (+0000) Subject: Don't construct a Test::Builder at BEGIN time, only once throws_ok or lives_ok is... X-Git-Tag: 0.19~184 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=commitdiff_plain;h=fb0394a27249134114e98ed491f5306c15d049e0 Don't construct a Test::Builder at BEGIN time, only once throws_ok or lives_ok is called --- diff --git a/lib/Mouse/Util.pm b/lib/Mouse/Util.pm index d30abf3..ad10a59 100644 --- a/lib/Mouse/Util.pm +++ b/lib/Mouse/Util.pm @@ -123,7 +123,7 @@ BEGIN { # VVVVV CODE TAKEN FROM TEST::EXCEPTION VVVVV 'Test::Exception' => do { - my $Tester = Test::Builder->new; + my $Tester; my $is_exception = sub { my $exception = shift; @@ -154,6 +154,8 @@ BEGIN { unless defined $description; my $exception = $try_as_caller->($coderef); + $Tester ||= Test::Builder->new; + my $regex = $Tester->maybe_regex( $expecting ); my $ok = $regex ? ( $exception =~ m/$regex/ ) @@ -171,6 +173,9 @@ BEGIN { 'lives_ok' => sub (&;$) { my ( $coderef, $description ) = @_; my $exception = $try_as_caller->( $coderef ); + + $Tester ||= Test::Builder->new; + my $ok = $Tester->ok( ! $is_exception->( $exception ), $description ); $Tester->diag( $exception_as_string->( "died:", $exception ) ) unless $ok; $@ = $exception;