Re: Re: Implementing Typed Lexical Variables

Written by Florian Ragwitz (742f2a428e635a5e) [SIGNED] 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;'
bax

Note that the package, which name is returned by foo, still needs to exist.

  • Re: Re: Re: Implementing Typed Lexical Variables

    Written by Anonymous Coward (0) on 2009-5-4 (月) at 1:11 am

    Thanks, Florian. - Dotan


Navigation

Categories

Tags

Login