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