Created
September 23, 2011 23:05
-
-
Save schwern/1238683 to your computer and use it in GitHub Desktop.
Demonstrate lexical pragma nature of bundles with Method::Signatures
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
# Simulate a bundle module | |
BEGIN { | |
package Bundle; | |
use parent qw(Method::Signatures); | |
} | |
# Simulate a user of that bundle | |
package Bar; | |
{ | |
use Test::More; | |
# use Bundle; | |
BEGIN { | |
Bundle->import; | |
} | |
ok defined &compiletime, "compile_at_BEGIN on"; | |
func compiletime($msg) { return 42 } | |
# Different scope, turn off compile_at_BEGIN | |
{ | |
# use Bundle { compile_at_BEGIN => 0 }; | |
BEGIN { | |
Bundle->import({ compile_at_BEGIN => 0 }); | |
} | |
ok !defined &runtime, "compile_at_BEGIN off in inner scope"; | |
func runtime($msg) { return 23 } | |
ok defined &runtime; | |
} | |
ok defined &compiletime, "compile_at_BEGIN still on in outer scope"; | |
is compiletime("compiletime works"), 42; | |
is runtime("runtime works"), 23; | |
done_testing; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment