Hi! Please consider following me on twitter: @hanekomu.
2009年02月18日
any::feature - Backwards-compatible handling of new syntactic features
I've released any::feature. The development repo is on github.
The problem
Perl 5.10 introduces new syntactic features which you can activate and
deactivate with the feature module. You want to use the
say feature in a program that's supposed to run under both Perl
5.8 and 5.10. So your program looks like this:
use feature 'say'; say 'Hello, world!';
But this only works in Perl 5.10, because there is no feature
module in Perl 5.8. So you write
use Perl6::Say; say 'Hello, world!';
This works, but it's strange to force Perl 5.10 users to install
Perl6::Say when the say feature is included in Perl
5.10.
The solution
Use any::feature!
WARNING: This is just a proof-of-concept.
any::feature can be used like Perl 5.10's feature
and will try to "do the right thing", regardless of whether you use Perl 5.8 or
Perl 5.10.
At the moment, this is just a proof-of-concept and only handles the
say feature. If things work out, I plan to extend it with other
Perl 5.10 features.
The following programs should work and exhibit the same behaviour both in Perl 5.8 and Perl 5.10.
This program will work:
use any::feature 'say'; say 'Hello, world!';
This program will fail at compile-time:
use any::feature 'say'; say 'Hello, world!'; no any::feature 'say'; say 'Oops';
The features are lexically scoped, which is how they work in Perl 5.10:
{ use any::feature 'say'; say 'foo'; } say 'bar'; # dies at compile-time
posted at: 14:04 | path: /dev | permalink | 0 comments | 0 trackbacks
Comments are closed for this story.
Trackbacks are closed for this story.