Written by
Anonymous Coward(0)
on
2009-5-2 (土) at 8:41 pm
This is dazzling, but what's an inlineable function and how do I get one? I can avoid the 'No such class' error by declaring a package, but not by declaring a sub.
perl -le 'my foo $bax = q{bax}; print $bax;'
No such class foo at -e line 1, near "my foo"
Execution of -e aborted due to compilation errors.
perl -le 'package foo; package main; my foo $bax = q{bax}; print $bax;'
bax
perl -le 'sub foo { q{bob} }; my foo $bax = q{bax}; print $bax;'
No such class foo at -e line 1, near "; my foo"
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;'
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
Comments on Implementing Typed Lexical Variables | 3 comments | Post a comment
Re: Implementing Typed Lexical Variables
Written by Anonymous Coward (0) on 2009-5-2 (土) at 8:41 pm
This is dazzling, but what's an inlineable function and how do I get one? I can avoid the 'No such class' error by declaring a package, but not by declaring a sub.
perl -le 'my foo $bax = q{bax}; print $bax;' No such class foo at -e line 1, near "my foo" Execution of -e aborted due to compilation errors. perl -le 'package foo; package main; my foo $bax = q{bax}; print $bax;' bax perl -le 'sub foo { q{bob} }; my foo $bax = q{bax}; print $bax;' No such class foo at -e line 1, near "; my foo"[ Link | XML | YAML | Reply... ]
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.[ Parent | Link | XML | YAML | Reply... ]
Re: Re: Re: Implementing Typed Lexical Variables
Written by Anonymous Coward (0) on 2009-5-4 (月) at 1:11 am
Thanks, Florian. - Dotan
[ Parent | Link | XML | YAML | Reply... ]