Skip to content

Instantly share code, notes, and snippets.

@schwern
Created September 23, 2011 23:05
Show Gist options
  • Save schwern/1238683 to your computer and use it in GitHub Desktop.
Save schwern/1238683 to your computer and use it in GitHub Desktop.
Demonstrate lexical pragma nature of bundles with Method::Signatures
# 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