NAME
any::feature - Backwards-compatible handling of new syntactic features
VERSION
version 1.100840
SYNOPSIS
use any::feature 'say';
say 'Hello, world!';
DESCRIPTION
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
FUNCTIONS
dispatch
Takes as arguments a direction (activate
or deactivate
), a package name and a feature name. Activates or deactivates the given feature for the given package.
activate
Takes as arguments a package name and a feature name. Uses dispatch()
to activate the given feature in the given package.
deactivate
Takes as arguments a package name and a feature name. Uses dispatch()
to deactivate the given feature in the given package.
import
Takes the same arguments as Perl 5.10's use feature
pragma. Uses activate()
and deactivate()
to do its job.
unimport
Takes the same arguments as Perl 5.10's no feature
pragma. Uses activate()
and deactivate()
to do its job.
get_effective_version
Uses Perl::Version to get the version number of the current perl interpreter. This is used to decide the course of action.
get_effective_revision
Uses Perl::Version to get the revision number of the current perl interpreter. This is used to decide the course of action.
INSTALLATION
See perlmodinstall for information and options on installing Perl modules.
BUGS AND LIMITATIONS
No bugs have been reported.
Please report any bugs or feature requests through the web interface at http://rt.cpan.org/Public/Dist/Display.html?Name=any-feature.
AVAILABILITY
The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit http://www.perl.com/CPAN/ to find a CPAN site near you, or see http://search.cpan.org/dist/any-feature/.
The development version lives at http://github.com/hanekomu/any-feature/. Instead of sending patches, please fork this project using the standard git and github infrastructure.
AUTHOR
Marcel Gruenauer <marcel@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2009 by Marcel Gruenauer.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.