1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
NAME
Perl::MinimumVersion - Find a minimum required version of perl for Perl
code
SYNOPSIS
# Create the version checking object
$object = Perl::MinimumVersion->new( $filename );
$object = Perl::MinimumVersion->new( \$source );
$object = Perl::MinimumVersion->new( $ppi_document );
# Find the minimum version
$version = $object->minimum_version;
DESCRIPTION
"Perl::MinimumVersion" takes Perl source code and calculates the minimum
version of perl required to be able to run it. Because it is based on
PPI, it can do this without having to actually load the code.
Currently it tests both the syntax of your code, and the use of explicit
version dependencies such as "require 5.008".
Future plans are to also add support for tracing module dependencies.
Using "Perl::MinimumVersion" is dead simple, the synopsis pretty much
covers it.
The distribution comes with a script called perlver, which is the
easiest way to run "Perl::MinimumVersion" on your code:
% perlver lib/Foo/Bar.pm
See the documentation for perlver for more details.
METHODS
new
# Create the version checking object
$object = Perl::MinimumVersion->new( $filename );
$object = Perl::MinimumVersion->new( \$source );
$object = Perl::MinimumVersion->new( $ppi_document );
The "new" constructor creates a new version checking object for a
PPI::Document. You can also provide the document to be read as a file
name, or as a "SCALAR" reference containing the code.
Returns a new "Perl::MinimumVersion" object, or "undef" on error.
Document
The "Document" accessor can be used to get the PPI::Document object back
out of the version checker.
minimum_version
The "minimum_version" method is the primary method for finding the
minimum perl version required based on "all" factors in the document.
At the present time, this is just syntax and explicit version checks, as
Perl::Depends is not yet completed.
Returns a version object, or "undef" on error.
minimum_explicit_version
The "minimum_explicit_version" method checks through Perl code for the
use of explicit version dependencies such as.
use 5.006;
require 5.005_03;
Although there is almost always only one of these in a file, if more
than one are found, the highest version dependency will be returned.
Returns a version object, false if no dependencies could be found, or
"undef" on error.
minimum_syntax_version $limit
The "minimum_syntax_version" method will explicitly test only the
Document's syntax to determine it's minimum version, to the extent that
this is possible.
It takes an optional parameter of a version object defining the lowest
known current value. For example, if it is already known that it must be
5.006 or higher, then you can provide a param of qv(5.006) and the
method will not run any of the tests below this version. This should
provide dramatic speed improvements for large and/or complex documents.
The limitations of parsing Perl mean that this method may provide
artificially low results, but should not artificially high results.
For example, if "minimum_syntax_version" returned 5.006, you can be
confident it will not run on anything lower, although there is a chance
that during actual execution it may use some untestable feature that
creates a dependency on a higher version.
Returns a version object, false if no dependencies could be found, or
"undef" on error.
minimum_external_version
WARNING: This method has not been implemented. Any attempted use will
throw an exception
The "minimum_external_version" examines code for dependencies on other
external files, and recursively traverses the dependency tree applying
the same tests to those files as it does to the original.
Returns a "version" object, false if no dependencies could be found, or
"undef" on error.
version_markers
This method returns a list of pairs in the form:
($version, \@markers)
Each pair represents all the markers that could be found indicating that
the version was the minimum needed version. @markers is an array of
strings. Currently, these strings are not as clear as they might be, but
this may be changed in the future. In other words: don't rely on them as
specific identifiers.
BUGS
Perl::MinimumVersion does a reasonable job of catching the best-known
explicit version dependencies.
However it is exceedingly easy to add a new syntax check, so if you find
something this is missing, copy and paste one of the existing 5 line
checking functions, modify it to find what you want, and report it to
rt.cpan.org, along with the version needed.
I don't even need an entire diff... just the function and version.
TO DO
Write lots more version checkers
- Perl 5.10 operators and language structures
- Three-argument open
Write the explicit version checker
Write the recursive module descend stuff
_while_readdir for postfix while without brackets
Check for more 5.12 features (currently only detecting "package NAME
VERSION;", "...", and "use feature ':5.12'")
SUPPORT
All bugs should be filed via the CPAN bug tracker at
<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Perl-MinimumVersion>
For other issues, or commercial enhancement or support, contact the
author.
AUTHORS
Adam Kennedy <adamk@cpan.org>
SEE ALSO
perlver - the command-line script for running "Perl::MinimumVersion" on
your code.
Perl::MinimumVersion::Fast - another module which does the same thing.
It's a lot faster, but only supports Perl 5.8.1+.
<http://ali.as/>, PPI, version
REPOSITORY
<https://github.com/neilbowers/Perl-MinimumVersion>
COPYRIGHT
Copyright 2005 - 2014 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included
with this module.
|