From: Lukas Mai Date: Sun, 15 Sep 2013 23:08:22 +0000 (+0200) Subject: add begin.t from Method::Signatures X-Git-Tag: v1.0301~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5424bb4a885554829b311cceb8a44822d7bab1c0;p=p5sagit%2FFunction-Parameters.git add begin.t from Method::Signatures --- diff --git a/MANIFEST b/MANIFEST index cdc0304..ae34204 100644 --- a/MANIFEST +++ b/MANIFEST @@ -43,6 +43,7 @@ t/foreign/Method-Signatures/anon.t t/foreign/Method-Signatures/array_param.t t/foreign/Method-Signatures/at_underscore.t t/foreign/Method-Signatures/attributes.t +t/foreign/Method-Signatures/begin.t t/foreign/Method-Signatures/caller.t t/foreign/Method-Signatures/comments.t t/foreign/Method-Signatures/debugger.t diff --git a/t/foreign/Method-Signatures/begin.t b/t/foreign/Method-Signatures/begin.t new file mode 100644 index 0000000..019edf7 --- /dev/null +++ b/t/foreign/Method-Signatures/begin.t @@ -0,0 +1,74 @@ +#!perl + +package Foo; + +use strict; +use warnings FATAL => 'all'; + +use Test::More; +use Test::Fatal; + +use Function::Parameters { method => { defaults => 'method', runtime => 0 } }; + + +our $phase; +BEGIN { $phase = 'compile-time' } +INIT { $phase = 'run-time' } + + +sub method_defined +{ + my ($method) = @_; + + local $Test::Builder::Level = $Test::Builder::Level + 1; + is exception { Foo->$method }, undef, "method $method is defined at $phase"; +} + +sub method_undefined +{ + my ($method) = @_; + + local $Test::Builder::Level = $Test::Builder::Level + 1; + like exception { Foo->$method }, qr/Can't locate object method/, "method $method is undefined at $phase"; +} + + +# The default configuration with compile at BEGIN on. +method top_level_default() {} + +# Turn it off. +use Function::Parameters { method => { defaults => 'method', runtime => 1 } }; +method top_level_off() {} + +# And on again. +use Function::Parameters { method => { defaults => 'method', runtime => 0 } }; +method top_level_on() {} + +# Now turn it off inside a lexical scope +{ + use Function::Parameters { method => { defaults => 'method', runtime => 1 } }; + method inner_scope_off() {} +} + +# And it's restored. +method outer_scope_on() {} + + +# at compile-time, some should be defined and others shouldn't be +BEGIN { + method_defined('top_level_default'); + method_undefined('top_level_off'); + method_defined('top_level_on'); + method_undefined('inner_scope_off'); + method_defined('outer_scope_on'); +} + +# by run-time, they should _all_ be defined +method_defined('top_level_default'); +method_defined('top_level_off'); +method_defined('top_level_on'); +method_defined('inner_scope_off'); +method_defined('outer_scope_on'); + + +done_testing;