Respond to Implementing Typed Lexical Variables
Caveat poster: if you decide to digitally sign your post, add something to it mentioning that it is attached to this article. Otherwise, someone could just paste it into another discussion, out of context, and the signature would still validate.
Re: Re: Implementing Typed Lexical Variables
Written by Florian Ragwitz (742f2a428e635a5e)
on
2009-5-3 (日) at 1:44 am
That's what the empty prototype in the anonymous sub that get's installed in the blog posts as well as MooseX::Lexical::Types on CPAN is for:
$meta->add_package_symbol('&'.$type_name => sub () { $decorator });It allows you to tell perl that your function doesn't take any arguments and is constant. With that, it can be inlined, which means it will be called during compile time and the result will be put in the place where the function call was:
$ perl -le'{ package bob; } sub foo () { q{bob} }; my foo $bax = q{bax}; print $bax;' baxNote that the package, which name is returned by
foo, still needs to exist.