Initial Commit

This commit is contained in:
Riley Schneider
2025-12-03 16:38:10 +01:00
parent c5e26bf594
commit b732d8d4b5
17680 changed files with 5977495 additions and 2 deletions

View File

@@ -0,0 +1,271 @@
package ExtUtils::MakeMaker::CPANfile;
use strict;
use warnings;
use ExtUtils::MakeMaker ();
use File::Spec::Functions qw/catfile rel2abs/;
use Module::CPANfile;
use version;
our $VERSION = "0.09";
sub import {
my $class = shift;
my $orig = \&ExtUtils::MakeMaker::WriteMakefile;
my $writer = sub {
my %params = @_;
# Do nothing if not called from Makefile.PL
my ($caller, $file, $line) = caller;
(my $root = rel2abs($file)) =~ s/Makefile\.PL$//i or return;
if (my $file = eval { Module::CPANfile->load(catfile($root, "cpanfile")) }) {
my $prereqs = $file->prereqs;
# Runtime requires => PREREQ_PM
_merge(
\%params,
_get($prereqs, 'runtime', 'requires'),
'PREREQ_PM',
);
# Build requires => BUILD_REQUIRES / PREREQ_PM
_merge(
\%params,
_get($prereqs, 'build', 'requires'),
_eumm('6.56') ? 'BUILD_REQUIRES' : 'PREREQ_PM',
);
# Test requires => TEST_REQUIRES / BUILD_REQUIRES / PREREQ_PM
_merge(
\%params,
_get($prereqs, 'test', 'requires'),
_eumm('6.63_03') ? 'TEST_REQUIRES' :
_eumm('6.56') ? 'BUILD_REQUIRES' : 'PREREQ_PM',
);
# Configure requires => CONFIGURE_REQUIRES / ignored
_merge(
\%params,
_get($prereqs, 'configure', 'requires'),
_eumm('6.52') ? 'CONFIGURE_REQUIRES' : undef,
);
# Add myself to configure requires (if possible)
_merge(
\%params,
{'ExtUtils::MakeMaker::CPANfile' => $VERSION},
_eumm('6.52') ? 'CONFIGURE_REQUIRES' : undef,
);
# Set dynamic_config to 0 if not set explicitly
if (!exists $params{META_ADD}{dynamic_config} &&
!exists $params{META_MERGE}{dynamic_config}) {
$params{META_MERGE}{dynamic_config} = 0;
}
# recommends, suggests, conflicts
my $requires_2_0;
for my $type (qw/recommends suggests conflicts/) {
for my $phase (qw/configure build test runtime develop/) {
my %tmp = %{$params{META_MERGE}{prereqs}{$phase} || {}};
_merge(
\%tmp,
_get($prereqs, $phase, $type),
$type,
);
if ($tmp{$type}) {
$params{META_MERGE}{prereqs}{$phase} = \%tmp;
$requires_2_0 = 1;
}
}
}
if ($requires_2_0) { # for better recommends support
# stash prereqs, which is already converted
my $tmp_prereqs = delete $params{META_MERGE}{prereqs};
require CPAN::Meta::Converter;
for my $key (qw/META_ADD META_MERGE/) {
next unless %{$params{$key} || {}};
my $converter = CPAN::Meta::Converter->new($params{$key}, default_version => 1.4);
$params{$key} = $converter->upgrade_fragment;
}
if ($params{META_MERGE}{prereqs}) {
require CPAN::Meta::Requirements;
for my $phase (keys %{$tmp_prereqs || {}}) {
for my $rel (keys %{$tmp_prereqs->{$phase} || {}}) {
my $req1 = CPAN::Meta::Requirements->from_string_hash($tmp_prereqs->{$phase}{$rel});
my $req2 = CPAN::Meta::Requirements->from_string_hash($params{META_MERGE}{prereqs}{$phase}{$rel});
$req1->add_requirements($req2);
$params{META_MERGE}{prereqs}{$phase} = $req1->as_string_hash;
}
}
} else {
$params{META_MERGE}{prereqs} = $tmp_prereqs;
}
}
# XXX: better to use also META_MERGE when applicable?
# As a small bonus, remove params that the installed version
# of EUMM doesn't know, so that we can always write them
# in Makefile.PL without caring about EUMM version.
# (EUMM warns if it finds unknown parameters.)
# As EUMM 6.17 is our prereq, we can safely ignore the keys
# defined before 6.17.
{
last if _eumm('6.66_03');
if (my $r = delete $params{TEST_REQUIRES}) {
_merge(\%params, $r, 'BUILD_REQUIRES');
}
last if _eumm('6.56');
if (my $r = delete $params{BUILD_REQUIRES}) {
_merge(\%params, $r, 'PREREQ_PM');
}
last if _eumm('6.52');
delete $params{CONFIGURE_REQUIRES};
last if _eumm('6.47_01');
delete $params{MIN_PERL_VERSION};
last if _eumm('6.45_01');
delete $params{META_ADD};
delete $params{META_MERGE};
last if _eumm('6.30_01');
delete $params{LICENSE};
}
} else {
print "cpanfile is not available: $@\n";
exit 0; # N/A
}
$orig->(%params);
};
{
no warnings 'redefine';
*main::WriteMakefile =
*ExtUtils::MakeMaker::WriteMakefile = $writer;
}
}
sub _eumm {
my $version = shift;
eval { ExtUtils::MakeMaker->VERSION($version) } ? 1 : 0;
}
sub _get {
my $prereqs = shift;
eval { $prereqs->requirements_for(@_)->as_string_hash };
}
sub _merge {
my ($params, $requires, $key) = @_;
return unless $key;
for (keys %{$requires || {}}) {
my $version = _normalize_version($requires->{$_});
next unless defined $version;
if (not exists $params->{$key}{$_}) {
$params->{$key}{$_} = $version;
} else {
my $prev = $params->{$key}{$_};
if (version->parse($prev) < version->parse($version)) {
$params->{$key}{$_} = $version;
}
}
}
}
sub _normalize_version {
my $version = shift;
# shortcuts
return unless defined $version;
return $version unless $version =~ /\s/;
# TODO: better range handling
$version =~ s/(?:>=|==)\s*//;
$version =~ s/,.+$//;
return $version unless $version =~ /\s/;
return;
}
1;
__END__
=encoding utf-8
=head1 NAME
ExtUtils::MakeMaker::CPANfile - cpanfile support for EUMM
=head1 SYNOPSIS
# Makefile.PL
use ExtUtils::MakeMaker::CPANfile;
WriteMakefile(
NAME => 'Foo::Bar',
AUTHOR => 'A.U.Thor <author@cpan.org>',
);
# cpanfile
requires 'ExtUtils::MakeMaker' => '6.17';
on test => sub {
requires 'Test::More' => '0.88';
};
=head1 DESCRIPTION
ExtUtils::MakeMaker::CPANfile loads C<cpanfile> in your distribution
and modifies parameters for C<WriteMakefile> in your Makefile.PL.
Just use it instead of L<ExtUtils::MakeMaker> (which should be
loaded internally), and prepare C<cpanfile>.
As of version 0.03, ExtUtils::MakeMaker::CPANfile also removes
WriteMakefile parameters that the installed version of
ExtUtils::MakeMaker doesn't know, to avoid warnings.
=head1 LIMITATION
=head2 complex version ranges
As of this writing, complex version ranges are simply ignored.
=head2 dynamic config
Strictly speaking, C<cpanfile> is a Perl script, and may have some
conditions in it. That said, you don't need to run Makefile.PL
to determine prerequisites in most cases. Hence, as of 0.06,
ExtUtils::MakeMaker::CPANfile sets C<dynamic_config> to false
by default. If you do need a CPAN installer to run Makefile.PL
to customize prerequisites dynamically, set C<dynamic_config>
to true explicitly (via META_ADD/META_MERGE).
=head1 FOR MODULE AUTHORS
Though the minimum version requirement of ExtUtils::MakeMaker is
arbitrary set to 6.17 (the one bundled in Perl 5.8.1), you need
at least EUMM 6.52 (with CONFIGURE_REQUIRES support) when you
release a distribution.
=head1 LICENSE
Copyright (C) Kenichi Ishigaki.
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=head1 AUTHOR
Kenichi Ishigaki E<lt>ishigaki@cpan.orgE<gt>
=cut

View File

@@ -0,0 +1,41 @@
package ExtUtils::MakeMaker::Config;
use strict;
use warnings;
our $VERSION = '7.58';
$VERSION =~ tr/_//d;
use Config ();
# Give us an overridable config.
our %Config = %Config::Config;
sub import {
my $caller = caller;
no strict 'refs'; ## no critic
*{$caller.'::Config'} = \%Config;
}
1;
=head1 NAME
ExtUtils::MakeMaker::Config - Wrapper around Config.pm
=head1 SYNOPSIS
use ExtUtils::MakeMaker::Config;
print $Config{installbin}; # or whatever
=head1 DESCRIPTION
B<FOR INTERNAL USE ONLY>
A very thin wrapper around Config.pm so MakeMaker is easier to test.
=cut

View File

@@ -0,0 +1,668 @@
package ExtUtils::MakeMaker::FAQ;
our $VERSION = '7.58';
$VERSION =~ tr/_//d;
1;
__END__
=head1 NAME
ExtUtils::MakeMaker::FAQ - Frequently Asked Questions About MakeMaker
=head1 DESCRIPTION
FAQs, tricks and tips for L<ExtUtils::MakeMaker>.
=head2 Module Installation
=over 4
=item How do I install a module into my home directory?
If you're not the Perl administrator you probably don't have
permission to install a module to its default location. Ways of handling
this with a B<lot> less manual effort on your part are L<perlbrew>
and L<local::lib>.
Otherwise, you can install it for your own use into your home directory
like so:
# Non-unix folks, replace ~ with /path/to/your/home/dir
perl Makefile.PL INSTALL_BASE=~
This will put modules into F<~/lib/perl5>, man pages into F<~/man> and
programs into F<~/bin>.
To ensure your Perl programs can see these newly installed modules,
set your C<PERL5LIB> environment variable to F<~/lib/perl5> or tell
each of your programs to look in that directory with the following:
use lib "$ENV{HOME}/lib/perl5";
or if $ENV{HOME} isn't set and you don't want to set it for some
reason, do it the long way.
use lib "/path/to/your/home/dir/lib/perl5";
=item How do I get MakeMaker and Module::Build to install to the same place?
Module::Build, as of 0.28, supports two ways to install to the same
location as MakeMaker.
We highly recommend the install_base method, its the simplest and most
closely approximates the expected behavior of an installation prefix.
1) Use INSTALL_BASE / C<--install_base>
MakeMaker (as of 6.31) and Module::Build (as of 0.28) both can install
to the same locations using the "install_base" concept. See
L<ExtUtils::MakeMaker/INSTALL_BASE> for details. To get MM and MB to
install to the same location simply set INSTALL_BASE in MM and
C<--install_base> in MB to the same location.
perl Makefile.PL INSTALL_BASE=/whatever
perl Build.PL --install_base /whatever
This works most like other language's behavior when you specify a
prefix. We recommend this method.
2) Use PREFIX / C<--prefix>
Module::Build 0.28 added support for C<--prefix> which works like
MakeMaker's PREFIX.
perl Makefile.PL PREFIX=/whatever
perl Build.PL --prefix /whatever
We highly discourage this method. It should only be used if you know
what you're doing and specifically need the PREFIX behavior. The
PREFIX algorithm is complicated and focused on matching the system
installation.
=item How do I keep from installing man pages?
Recent versions of MakeMaker will only install man pages on Unix-like
operating systems by default. To generate manpages on non-Unix operating
systems, make the "manifypods" target.
For an individual module:
perl Makefile.PL INSTALLMAN1DIR=none INSTALLMAN3DIR=none
If you want to suppress man page installation for all modules you have
to reconfigure Perl and tell it 'none' when it asks where to install
man pages.
=item How do I use a module without installing it?
Two ways. One is to build the module normally...
perl Makefile.PL
make
make test
...and then use L<blib> to point Perl at the built but uninstalled module:
perl -Mblib script.pl
perl -Mblib -e '...'
The other is to install the module in a temporary location.
perl Makefile.PL INSTALL_BASE=~/tmp
make
make test
make install
And then set PERL5LIB to F<~/tmp/lib/perl5>. This works well when you
have multiple modules to work with. It also ensures that the module
goes through its full installation process which may modify it.
Again, L<local::lib> may assist you here.
=item How can I organize tests into subdirectories and have them run?
Let's take the following test directory structure:
t/foo/sometest.t
t/bar/othertest.t
t/bar/baz/anothertest.t
Now, inside of the C<WriteMakeFile()> function in your F<Makefile.PL>, specify
where your tests are located with the C<test> directive:
test => {TESTS => 't/*.t t/*/*.t t/*/*/*.t'}
The first entry in the string will run all tests in the top-level F<t/>
directory. The second will run all test files located in any subdirectory under
F<t/>. The third, runs all test files within any subdirectory within any other
subdirectory located under F<t/>.
Note that you do not have to use wildcards. You can specify explicitly which
subdirectories to run tests in:
test => {TESTS => 't/*.t t/foo/*.t t/bar/baz/*.t'}
=item PREFIX vs INSTALL_BASE from Module::Build::Cookbook
The behavior of PREFIX is complicated and depends closely on how your
Perl is configured. The resulting installation locations will vary
from machine to machine and even different installations of Perl on the
same machine. Because of this, its difficult to document where prefix
will place your modules.
In contrast, INSTALL_BASE has predictable, easy to explain installation
locations. Now that Module::Build and MakeMaker both have INSTALL_BASE
there is little reason to use PREFIX other than to preserve your existing
installation locations. If you are starting a fresh Perl installation we
encourage you to use INSTALL_BASE. If you have an existing installation
installed via PREFIX, consider moving it to an installation structure
matching INSTALL_BASE and using that instead.
=item Generating *.pm files with substitutions eg of $VERSION
If you want to configure your module files for local conditions, or to
automatically insert a version number, you can use EUMM's C<PL_FILES>
capability, where it will automatically run each F<*.PL> it finds to
generate its basename. For instance:
# Makefile.PL:
require 'common.pl';
my $version = get_version();
my @pms = qw(Foo.pm);
WriteMakefile(
NAME => 'Foo',
VERSION => $version,
PM => { map { ($_ => "\$(INST_LIB)/$_") } @pms },
clean => { FILES => join ' ', @pms },
);
# common.pl:
sub get_version { '0.04' }
sub process { my $v = get_version(); s/__VERSION__/$v/g; }
1;
# Foo.pm.PL:
require 'common.pl';
$_ = join '', <DATA>;
process();
my $file = shift;
open my $fh, '>', $file or die "$file: $!";
print $fh $_;
__DATA__
package Foo;
our $VERSION = '__VERSION__';
1;
You may notice that C<PL_FILES> is not specified above, since the default
of mapping each .PL file to its basename works well.
If the generated module were architecture-specific, you could replace
C<$(INST_LIB)> above with C<$(INST_ARCHLIB)>, although if you locate
modules under F<lib>, that would involve ensuring any C<lib/> in front
of the module location were removed.
=back
=head2 Common errors and problems
=over 4
=item "No rule to make target `/usr/lib/perl5/CORE/config.h', needed by `Makefile'"
Just what it says, you're missing that file. MakeMaker uses it to
determine if perl has been rebuilt since the Makefile was made. It's
a bit of a bug that it halts installation.
Some operating systems don't ship the CORE directory with their base
perl install. To solve the problem, you likely need to install a perl
development package such as perl-devel (CentOS, Fedora and other
Redhat systems) or perl (Ubuntu and other Debian systems).
=back
=head2 Philosophy and History
=over 4
=item Why not just use <insert other build config tool here>?
Why did MakeMaker reinvent the build configuration wheel? Why not
just use autoconf or automake or ppm or Ant or ...
There are many reasons, but the major one is cross-platform
compatibility.
Perl is one of the most ported pieces of software ever. It works on
operating systems I've never even heard of (see perlport for details).
It needs a build tool that can work on all those platforms and with
any wacky C compilers and linkers they might have.
No such build tool exists. Even make itself has wildly different
dialects. So we have to build our own.
=item What is Module::Build and how does it relate to MakeMaker?
Module::Build is a project by Ken Williams to supplant MakeMaker.
Its primary advantages are:
=over 8
=item * pure perl. no make, no shell commands
=item * easier to customize
=item * cleaner internals
=item * less cruft
=back
Module::Build was long the official heir apparent to MakeMaker. The
rate of both its development and adoption has slowed in recent years,
though, and it is unclear what the future holds for it. That said,
Module::Build set the stage for I<something> to become the heir to
MakeMaker. MakeMaker's maintainers have long said that it is a dead
end and should be kept functioning, while being cautious about extending
with new features.
=back
=head2 Module Writing
=over 4
=item How do I keep my $VERSION up to date without resetting it manually?
Often you want to manually set the $VERSION in the main module
distribution because this is the version that everybody sees on CPAN
and maybe you want to customize it a bit. But for all the other
modules in your dist, $VERSION is really just bookkeeping and all that's
important is it goes up every time the module is changed. Doing this
by hand is a pain and you often forget.
Probably the easiest way to do this is using F<perl-reversion> in
L<Perl::Version>:
perl-reversion -bump
If your version control system supports revision numbers (git doesn't
easily), the simplest way to do it automatically is to use its revision
number (you are using version control, right?).
In CVS, RCS and SVN you use $Revision$ (see the documentation of your
version control system for details). Every time the file is checked
in the $Revision$ will be updated, updating your $VERSION.
SVN uses a simple integer for $Revision$ so you can adapt it for your
$VERSION like so:
($VERSION) = q$Revision$ =~ /(\d+)/;
In CVS and RCS version 1.9 is followed by 1.10. Since CPAN compares
version numbers numerically we use a sprintf() to convert 1.9 to 1.009
and 1.10 to 1.010 which compare properly.
$VERSION = sprintf "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/g;
If branches are involved (ie. $Revision: 1.5.3.4$) it's a little more
complicated.
# must be all on one line or MakeMaker will get confused.
$VERSION = do { my @r = (q$Revision$ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r };
In SVN, $Revision$ should be the same for every file in the project so
they would all have the same $VERSION. CVS and RCS have a different
$Revision$ per file so each file will have a different $VERSION.
Distributed version control systems, such as SVK, may have a different
$Revision$ based on who checks out the file, leading to a different $VERSION
on each machine! Finally, some distributed version control systems, such
as darcs, have no concept of revision number at all.
=item What's this F<META.yml> thing and how did it get in my F<MANIFEST>?!
F<META.yml> is a module meta-data file pioneered by Module::Build and
automatically generated as part of the 'distdir' target (and thus
'dist'). See L<ExtUtils::MakeMaker/"Module Meta-Data">.
To shut off its generation, pass the C<NO_META> flag to C<WriteMakefile()>.
=item How do I delete everything not in my F<MANIFEST>?
Some folks are surprised that C<make distclean> does not delete
everything not listed in their MANIFEST (thus making a clean
distribution) but only tells them what they need to delete. This is
done because it is considered too dangerous. While developing your
module you might write a new file, not add it to the MANIFEST, then
run a C<distclean> and be sad because your new work was deleted.
If you really want to do this, you can use
C<ExtUtils::Manifest::manifind()> to read the MANIFEST and File::Find
to delete the files. But you have to be careful. Here's a script to
do that. Use at your own risk. Have fun blowing holes in your foot.
#!/usr/bin/perl -w
use strict;
use File::Spec;
use File::Find;
use ExtUtils::Manifest qw(maniread);
my %manifest = map {( $_ => 1 )}
grep { File::Spec->canonpath($_) }
keys %{ maniread() };
if( !keys %manifest ) {
print "No files found in MANIFEST. Stopping.\n";
exit;
}
find({
wanted => sub {
my $path = File::Spec->canonpath($_);
return unless -f $path;
return if exists $manifest{ $path };
print "unlink $path\n";
unlink $path;
},
no_chdir => 1
},
"."
);
=item Which tar should I use on Windows?
We recommend ptar from Archive::Tar not older than 1.66 with '-C' option.
=item Which zip should I use on Windows for '[ndg]make zipdist'?
We recommend InfoZIP: L<http://www.info-zip.org/Zip.html>
=back
=head2 XS
=over 4
=item How do I prevent "object version X.XX does not match bootstrap parameter Y.YY" errors?
XS code is very sensitive to the module version number and will
complain if the version number in your Perl module doesn't match. If
you change your module's version # without rerunning Makefile.PL the old
version number will remain in the Makefile, causing the XS code to be built
with the wrong number.
To avoid this, you can force the Makefile to be rebuilt whenever you
change the module containing the version number by adding this to your
WriteMakefile() arguments.
depend => { '$(FIRST_MAKEFILE)' => '$(VERSION_FROM)' }
=item How do I make two or more XS files coexist in the same directory?
Sometimes you need to have two and more XS files in the same package.
There are three ways: C<XSMULTI>, separate directories, and bootstrapping
one XS from another.
=over 8
=item XSMULTI
Structure your modules so they are all located under F<lib>, such that
C<Foo::Bar> is in F<lib/Foo/Bar.pm> and F<lib/Foo/Bar.xs>, etc. Have your
top-level C<WriteMakefile> set the variable C<XSMULTI> to a true value.
Er, that's it.
=item Separate directories
Put each XS files into separate directories, each with their own
F<Makefile.PL>. Make sure each of those F<Makefile.PL>s has the correct
C<CFLAGS>, C<INC>, C<LIBS> etc. You will need to make sure the top-level
F<Makefile.PL> refers to each of these using C<DIR>.
=item Bootstrapping
Let's assume that we have a package C<Cool::Foo>, which includes
C<Cool::Foo> and C<Cool::Bar> modules each having a separate XS
file. First we use the following I<Makefile.PL>:
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'Cool::Foo',
VERSION_FROM => 'Foo.pm',
OBJECT => q/$(O_FILES)/,
# ... other attrs ...
);
Notice the C<OBJECT> attribute. MakeMaker generates the following
variables in I<Makefile>:
# Handy lists of source code files:
XS_FILES= Bar.xs \
Foo.xs
C_FILES = Bar.c \
Foo.c
O_FILES = Bar.o \
Foo.o
Therefore we can use the C<O_FILES> variable to tell MakeMaker to use
these objects into the shared library.
That's pretty much it. Now write I<Foo.pm> and I<Foo.xs>, I<Bar.pm>
and I<Bar.xs>, where I<Foo.pm> bootstraps the shared library and
I<Bar.pm> simply loading I<Foo.pm>.
The only issue left is to how to bootstrap I<Bar.xs>. This is done
from I<Foo.xs>:
MODULE = Cool::Foo PACKAGE = Cool::Foo
BOOT:
# boot the second XS file
boot_Cool__Bar(aTHX_ cv);
If you have more than two files, this is the place where you should
boot extra XS files from.
The following four files sum up all the details discussed so far.
Foo.pm:
-------
package Cool::Foo;
require DynaLoader;
our @ISA = qw(DynaLoader);
our $VERSION = '0.01';
bootstrap Cool::Foo $VERSION;
1;
Bar.pm:
-------
package Cool::Bar;
use Cool::Foo; # bootstraps Bar.xs
1;
Foo.xs:
-------
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
MODULE = Cool::Foo PACKAGE = Cool::Foo
BOOT:
# boot the second XS file
boot_Cool__Bar(aTHX_ cv);
MODULE = Cool::Foo PACKAGE = Cool::Foo PREFIX = cool_foo_
void
cool_foo_perl_rules()
CODE:
fprintf(stderr, "Cool::Foo says: Perl Rules\n");
Bar.xs:
-------
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
MODULE = Cool::Bar PACKAGE = Cool::Bar PREFIX = cool_bar_
void
cool_bar_perl_rules()
CODE:
fprintf(stderr, "Cool::Bar says: Perl Rules\n");
And of course a very basic test:
t/cool.t:
--------
use Test;
BEGIN { plan tests => 1 };
use Cool::Foo;
use Cool::Bar;
Cool::Foo::perl_rules();
Cool::Bar::perl_rules();
ok 1;
This tip has been brought to you by Nick Ing-Simmons and Stas Bekman.
An alternative way to achieve this can be seen in L<Gtk2::CodeGen>
and L<Glib::CodeGen>.
=back
=back
=head1 DESIGN
=head2 MakeMaker object hierarchy (simplified)
What most people need to know (superclasses on top.)
ExtUtils::MM_Any
|
ExtUtils::MM_Unix
|
ExtUtils::MM_{Current OS}
|
ExtUtils::MakeMaker
|
MY
The object actually used is of the class L<MY|ExtUtils::MY> which allows you to
override bits of MakeMaker inside your Makefile.PL by declaring
MY::foo() methods.
=head2 MakeMaker object hierarchy (real)
Here's how it really works:
ExtUtils::MM_Any
|
ExtUtils::MM_Unix
|
ExtUtils::Liblist::Kid ExtUtils::MM_{Current OS} (if necessary)
| |
ExtUtils::Liblist ExtUtils::MakeMaker |
| | |
| | |-----------------------
ExtUtils::MM
| |
ExtUtils::MY MM (created by ExtUtils::MM)
| |
MY (created by ExtUtils::MY) |
. |
(mixin) |
. |
PACK### (created each call to ExtUtils::MakeMaker->new)
NOTE: Yes, this is a mess. See
L<http://archive.develooper.com/makemaker@perl.org/msg00134.html>
for some history.
NOTE: When L<ExtUtils::MM> is loaded it chooses a superclass for MM from
amongst the ExtUtils::MM_* modules based on the current operating
system.
NOTE: ExtUtils::MM_{Current OS} represents one of the ExtUtils::MM_*
modules except L<ExtUtils::MM_Any> chosen based on your operating system.
NOTE: The main object used by MakeMaker is a PACK### object, *not*
L<ExtUtils::MakeMaker>. It is, effectively, a subclass of L<MY|ExtUtils::MY>,
L<ExtUtils::MakeMaker>, L<ExtUtils::Liblist> and ExtUtils::MM_{Current OS}
NOTE: The methods in L<MY|ExtUtils::MY> are simply copied into PACK### rather
than MY being a superclass of PACK###. I don't remember the rationale.
NOTE: L<ExtUtils::Liblist> should be removed from the inheritance hiearchy
and simply be called as functions.
NOTE: Modules like L<File::Spec> and L<Exporter> have been omitted for clarity.
=head2 The MM_* hierarchy
MM_Win95 MM_NW5
\ /
MM_BeOS MM_Cygwin MM_OS2 MM_VMS MM_Win32 MM_DOS MM_UWIN
\ | | | / / /
------------------------------------------------
| |
MM_Unix |
| |
MM_Any
NOTE: Each direct L<MM_Unix|ExtUtils::MM_Unix> subclass is also an
L<MM_Any|ExtUtils::MM_Any> subclass. This
is a temporary hack because MM_Unix overrides some MM_Any methods with
Unix specific code. It allows the non-Unix modules to see the
original MM_Any implementations.
NOTE: Modules like L<File::Spec> and L<Exporter> have been omitted for clarity.
=head1 PATCHING
If you have a question you'd like to see added to the FAQ (whether or
not you have the answer) please either:
=over 2
=item * make a pull request on the MakeMaker github repository
=item * raise a issue on the MakeMaker github repository
=item * file an RT ticket
=item * email makemaker@perl.org
=back
=head1 AUTHOR
The denizens of makemaker@perl.org.
=head1 SEE ALSO
L<ExtUtils::MakeMaker>
=cut

View File

@@ -0,0 +1,384 @@
package ExtUtils::MakeMaker::Locale;
use strict;
use warnings;
our $VERSION = "7.58";
$VERSION =~ tr/_//d;
use base 'Exporter';
our @EXPORT_OK = qw(
decode_argv env
$ENCODING_LOCALE $ENCODING_LOCALE_FS
$ENCODING_CONSOLE_IN $ENCODING_CONSOLE_OUT
);
use Encode ();
use Encode::Alias ();
our $ENCODING_LOCALE;
our $ENCODING_LOCALE_FS;
our $ENCODING_CONSOLE_IN;
our $ENCODING_CONSOLE_OUT;
sub DEBUG () { 0 }
sub _init {
if ($^O eq "MSWin32") {
unless ($ENCODING_LOCALE) {
# Try to obtain what the Windows ANSI code page is
eval {
unless (defined &GetConsoleCP) {
require Win32;
# manually "import" it since Win32->import refuses
*GetConsoleCP = sub { &Win32::GetConsoleCP } if defined &Win32::GetConsoleCP;
}
unless (defined &GetConsoleCP) {
require Win32::API;
Win32::API->Import('kernel32', 'int GetConsoleCP()');
}
if (defined &GetConsoleCP) {
my $cp = GetConsoleCP();
$ENCODING_LOCALE = "cp$cp" if $cp;
}
};
}
unless ($ENCODING_CONSOLE_IN) {
# only test one since set together
unless (defined &GetInputCP) {
eval {
require Win32;
eval {
local $SIG{__WARN__} = sub {} if ( "$]" < 5.014 ); # suppress deprecation warning for inherited AUTOLOAD of Win32::GetConsoleCP()
Win32::GetConsoleCP();
};
# manually "import" it since Win32->import refuses
*GetInputCP = sub { &Win32::GetConsoleCP } if defined &Win32::GetConsoleCP;
*GetOutputCP = sub { &Win32::GetConsoleOutputCP } if defined &Win32::GetConsoleOutputCP;
};
unless (defined &GetInputCP) {
eval {
# try Win32::Console module for codepage to use
require Win32::Console;
*GetInputCP = sub { &Win32::Console::InputCP }
if defined &Win32::Console::InputCP;
*GetOutputCP = sub { &Win32::Console::OutputCP }
if defined &Win32::Console::OutputCP;
};
}
unless (defined &GetInputCP) {
# final fallback
*GetInputCP = *GetOutputCP = sub {
# another fallback that could work is:
# reg query HKLM\System\CurrentControlSet\Control\Nls\CodePage /v ACP
((qx(chcp) || '') =~ /^Active code page: (\d+)/)
? $1 : ();
};
}
}
my $cp = GetInputCP();
$ENCODING_CONSOLE_IN = "cp$cp" if $cp;
$cp = GetOutputCP();
$ENCODING_CONSOLE_OUT = "cp$cp" if $cp;
}
}
unless ($ENCODING_LOCALE) {
eval {
require I18N::Langinfo;
$ENCODING_LOCALE = I18N::Langinfo::langinfo(I18N::Langinfo::CODESET());
# Workaround of Encode < v2.25. The "646" encoding alias was
# introduced in Encode-2.25, but we don't want to require that version
# quite yet. Should avoid the CPAN testers failure reported from
# openbsd-4.7/perl-5.10.0 combo.
$ENCODING_LOCALE = "ascii" if $ENCODING_LOCALE eq "646";
# https://rt.cpan.org/Ticket/Display.html?id=66373
$ENCODING_LOCALE = "hp-roman8" if $^O eq "hpux" && $ENCODING_LOCALE eq "roman8";
};
$ENCODING_LOCALE ||= $ENCODING_CONSOLE_IN;
}
# Workaround of Encode < v2.71 for "cp65000" and "cp65001"
# The "cp65000" and "cp65001" aliases were added in [Encode v2.71](https://github.com/dankogai/p5-encode/commit/7874bd95aa10967a3b5dbae333d16bcd703ac6c6)
# via commit <https://github.com/dankogai/p5-encode/commit/84b9c1101d5251d37e226f80d1c6781718779047>.
# This will avoid test failures for Win32 machines using the UTF-7 or UTF-8 code pages.
$ENCODING_LOCALE = 'UTF-7' if $ENCODING_LOCALE && lc($ENCODING_LOCALE) eq "cp65000";
$ENCODING_LOCALE = 'utf-8-strict' if $ENCODING_LOCALE && lc($ENCODING_LOCALE) eq "cp65001";
if ($^O eq "darwin") {
$ENCODING_LOCALE_FS ||= "UTF-8";
}
# final fallback
$ENCODING_LOCALE ||= $^O eq "MSWin32" ? "cp1252" : "UTF-8";
$ENCODING_LOCALE_FS ||= $ENCODING_LOCALE;
$ENCODING_CONSOLE_IN ||= $ENCODING_LOCALE;
$ENCODING_CONSOLE_OUT ||= $ENCODING_CONSOLE_IN;
unless (Encode::find_encoding($ENCODING_LOCALE)) {
my $foundit;
if (lc($ENCODING_LOCALE) eq "gb18030") {
eval {
require Encode::HanExtra;
};
if ($@) {
die "Need Encode::HanExtra to be installed to support locale codeset ($ENCODING_LOCALE), stopped";
}
$foundit++ if Encode::find_encoding($ENCODING_LOCALE);
}
die "The locale codeset ($ENCODING_LOCALE) isn't one that perl can decode, stopped"
unless $foundit;
}
# use Data::Dump; ddx $ENCODING_LOCALE, $ENCODING_LOCALE_FS, $ENCODING_CONSOLE_IN, $ENCODING_CONSOLE_OUT;
}
_init();
Encode::Alias::define_alias(sub {
no strict 'refs';
no warnings 'once';
return ${"ENCODING_" . uc(shift)};
}, "locale");
sub _flush_aliases {
no strict 'refs';
for my $a (sort keys %Encode::Alias::Alias) {
if (defined ${"ENCODING_" . uc($a)}) {
delete $Encode::Alias::Alias{$a};
warn "Flushed alias cache for $a" if DEBUG;
}
}
}
sub reinit {
$ENCODING_LOCALE = shift;
$ENCODING_LOCALE_FS = shift;
$ENCODING_CONSOLE_IN = $ENCODING_LOCALE;
$ENCODING_CONSOLE_OUT = $ENCODING_LOCALE;
_init();
_flush_aliases();
}
sub decode_argv {
die if defined wantarray;
for (@ARGV) {
$_ = Encode::decode(locale => $_, @_);
}
}
sub env {
my $k = Encode::encode(locale => shift);
my $old = $ENV{$k};
if (@_) {
my $v = shift;
if (defined $v) {
$ENV{$k} = Encode::encode(locale => $v);
}
else {
delete $ENV{$k};
}
}
return Encode::decode(locale => $old) if defined wantarray;
}
1;
__END__
=head1 NAME
ExtUtils::MakeMaker::Locale - bundled Encode::Locale
=head1 SYNOPSIS
use Encode::Locale;
use Encode;
$string = decode(locale => $bytes);
$bytes = encode(locale => $string);
if (-t) {
binmode(STDIN, ":encoding(console_in)");
binmode(STDOUT, ":encoding(console_out)");
binmode(STDERR, ":encoding(console_out)");
}
# Processing file names passed in as arguments
my $uni_filename = decode(locale => $ARGV[0]);
open(my $fh, "<", encode(locale_fs => $uni_filename))
|| die "Can't open '$uni_filename': $!";
binmode($fh, ":encoding(locale)");
...
=head1 DESCRIPTION
In many applications it's wise to let Perl use Unicode for the strings it
processes. Most of the interfaces Perl has to the outside world are still byte
based. Programs therefore need to decode byte strings that enter the program
from the outside and encode them again on the way out.
The POSIX locale system is used to specify both the language conventions
requested by the user and the preferred character set to consume and
output. The C<Encode::Locale> module looks up the charset and encoding (called
a CODESET in the locale jargon) and arranges for the L<Encode> module to know
this encoding under the name "locale". It means bytes obtained from the
environment can be converted to Unicode strings by calling C<<
Encode::encode(locale => $bytes) >> and converted back again with C<<
Encode::decode(locale => $string) >>.
Where file systems interfaces pass file names in and out of the program we also
need care. The trend is for operating systems to use a fixed file encoding
that don't actually depend on the locale; and this module determines the most
appropriate encoding for file names. The L<Encode> module will know this
encoding under the name "locale_fs". For traditional Unix systems this will
be an alias to the same encoding as "locale".
For programs running in a terminal window (called a "Console" on some systems)
the "locale" encoding is usually a good choice for what to expect as input and
output. Some systems allows us to query the encoding set for the terminal and
C<Encode::Locale> will do that if available and make these encodings known
under the C<Encode> aliases "console_in" and "console_out". For systems where
we can't determine the terminal encoding these will be aliased as the same
encoding as "locale". The advice is to use "console_in" for input known to
come from the terminal and "console_out" for output to the terminal.
In addition to arranging for various Encode aliases the following functions and
variables are provided:
=over
=item decode_argv( )
=item decode_argv( Encode::FB_CROAK )
This will decode the command line arguments to perl (the C<@ARGV> array) in-place.
The function will by default replace characters that can't be decoded by
"\x{FFFD}", the Unicode replacement character.
Any argument provided is passed as CHECK to underlying Encode::decode() call.
Pass the value C<Encode::FB_CROAK> to have the decoding croak if not all the
command line arguments can be decoded. See L<Encode/"Handling Malformed Data">
for details on other options for CHECK.
=item env( $uni_key )
=item env( $uni_key => $uni_value )
Interface to get/set environment variables. Returns the current value as a
Unicode string. The $uni_key and $uni_value arguments are expected to be
Unicode strings as well. Passing C<undef> as $uni_value deletes the
environment variable named $uni_key.
The returned value will have the characters that can't be decoded replaced by
"\x{FFFD}", the Unicode replacement character.
There is no interface to request alternative CHECK behavior as for
decode_argv(). If you need that you need to call encode/decode yourself.
For example:
my $key = Encode::encode(locale => $uni_key, Encode::FB_CROAK);
my $uni_value = Encode::decode(locale => $ENV{$key}, Encode::FB_CROAK);
=item reinit( )
=item reinit( $encoding )
Reinitialize the encodings from the locale. You want to call this function if
you changed anything in the environment that might influence the locale.
This function will croak if the determined encoding isn't recognized by
the Encode module.
With argument force $ENCODING_... variables to set to the given value.
=item $ENCODING_LOCALE
The encoding name determined to be suitable for the current locale.
L<Encode> know this encoding as "locale".
=item $ENCODING_LOCALE_FS
The encoding name determined to be suitable for file system interfaces
involving file names.
L<Encode> know this encoding as "locale_fs".
=item $ENCODING_CONSOLE_IN
=item $ENCODING_CONSOLE_OUT
The encodings to be used for reading and writing output to the a console.
L<Encode> know these encodings as "console_in" and "console_out".
=back
=head1 NOTES
This table summarizes the mapping of the encodings set up
by the C<Encode::Locale> module:
Encode | | |
Alias | Windows | Mac OS X | POSIX
------------+---------+--------------+------------
locale | ANSI | nl_langinfo | nl_langinfo
locale_fs | ANSI | UTF-8 | nl_langinfo
console_in | OEM | nl_langinfo | nl_langinfo
console_out | OEM | nl_langinfo | nl_langinfo
=head2 Windows
Windows has basically 2 sets of APIs. A wide API (based on passing UTF-16
strings) and a byte based API based a character set called ANSI. The
regular Perl interfaces to the OS currently only uses the ANSI APIs.
Unfortunately ANSI is not a single character set.
The encoding that corresponds to ANSI varies between different editions of
Windows. For many western editions of Windows ANSI corresponds to CP-1252
which is a character set similar to ISO-8859-1. Conceptually the ANSI
character set is a similar concept to the POSIX locale CODESET so this module
figures out what the ANSI code page is and make this available as
$ENCODING_LOCALE and the "locale" Encoding alias.
Windows systems also operate with another byte based character set.
It's called the OEM code page. This is the encoding that the Console
takes as input and output. It's common for the OEM code page to
differ from the ANSI code page.
=head2 Mac OS X
On Mac OS X the file system encoding is always UTF-8 while the locale
can otherwise be set up as normal for POSIX systems.
File names on Mac OS X will at the OS-level be converted to
NFD-form. A file created by passing a NFC-filename will come
in NFD-form from readdir(). See L<Unicode::Normalize> for details
of NFD/NFC.
Actually, Apple does not follow the Unicode NFD standard since not all
character ranges are decomposed. The claim is that this avoids problems with
round trip conversions from old Mac text encodings. See L<Encode::UTF8Mac> for
details.
=head2 POSIX (Linux and other Unixes)
File systems might vary in what encoding is to be used for
filenames. Since this module has no way to actually figure out
what the is correct it goes with the best guess which is to
assume filenames are encoding according to the current locale.
Users are advised to always specify UTF-8 as the locale charset.
=head1 SEE ALSO
L<I18N::Langinfo>, L<Encode>, L<Term::Encoding>
=head1 AUTHOR
Copyright 2010 Gisle Aas <gisle@aas.no>.
This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=cut

View File

@@ -0,0 +1,213 @@
package ExtUtils::MakeMaker::Tutorial;
our $VERSION = '7.58';
$VERSION =~ tr/_//d;
=head1 NAME
ExtUtils::MakeMaker::Tutorial - Writing a module with MakeMaker
=head1 SYNOPSIS
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'Your::Module',
VERSION_FROM => 'lib/Your/Module.pm'
);
=head1 DESCRIPTION
This is a short tutorial on writing a simple module with MakeMaker.
It's really not that hard.
=head2 The Mantra
MakeMaker modules are installed using this simple mantra
perl Makefile.PL
make
make test
make install
There are lots more commands and options, but the above will do it.
=head2 The Layout
The basic files in a module look something like this.
Makefile.PL
MANIFEST
lib/Your/Module.pm
That's all that's strictly necessary. There's additional files you might
want:
lib/Your/Other/Module.pm
t/some_test.t
t/some_other_test.t
Changes
README
INSTALL
MANIFEST.SKIP
bin/some_program
=over 4
=item Makefile.PL
When you run Makefile.PL, it makes a Makefile. That's the whole point of
MakeMaker. The Makefile.PL is a simple program which loads
ExtUtils::MakeMaker and runs the WriteMakefile() function to generate a
Makefile.
Here's an example of what you need for a simple module:
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'Your::Module',
VERSION_FROM => 'lib/Your/Module.pm'
);
NAME is the top-level namespace of your module. VERSION_FROM is the file
which contains the $VERSION variable for the entire distribution. Typically
this is the same as your top-level module.
=item MANIFEST
A simple listing of all the files in your distribution.
Makefile.PL
MANIFEST
lib/Your/Module.pm
File paths in a MANIFEST always use Unix conventions (ie. /) even if you're
not on Unix.
You can write this by hand or generate it with 'make manifest'.
See L<ExtUtils::Manifest> for more details.
=item lib/
This is the directory where the .pm and .pod files you wish to have
installed go. They are laid out according to namespace. So Foo::Bar
is F<lib/Foo/Bar.pm>.
=item t/
Tests for your modules go here. Each test filename ends with a .t.
So F<t/foo.t> 'make test' will run these tests.
Typically, the F<t/> test directory is flat, with all test files located
directly within it. However, you can nest tests within subdirectories, for
example:
t/foo/subdir_test.t
To do this, you need to inform C<WriteMakeFile()> in your I<Makefile.PL> file
in the following fashion:
test => {TESTS => 't/*.t t/*/*.t'}
That will run all tests in F<t/>, as well as all tests in all subdirectories
that reside under F<t/>. You can nest as deeply as makes sense for your project.
Simply add another entry in the test location string. For example, to test:
t/foo/bar/subdir_test.t
You would use the following C<test> directive:
test => {TESTS => 't/*.t t/*/*/*.t'}
Note that in the above example, tests in the first subdirectory will not be
run. To run all tests in the intermediary subdirectory preceding the one
the test files are in, you need to explicitly note it:
test => {TESTS => 't/*.t t/*/*.t t/*/*/*.t'}
You don't need to specify wildcards if you only want to test within specific
subdirectories. The following example will only run tests in F<t/foo>:
test => {TESTS => 't/foo/*.t'}
Tests are run from the top level of your distribution. So inside a test
you would refer to ./lib to enter the lib directory, for example.
=item Changes
A log of changes you've made to this module. The layout is free-form.
Here's an example:
1.01 Fri Apr 11 00:21:25 PDT 2003
- thing() does some stuff now
- fixed the wiggy bug in withit()
1.00 Mon Apr 7 00:57:15 PDT 2003
- "Rain of Frogs" now supported
=item README
A short description of your module, what it does, why someone would use it
and its limitations. CPAN automatically pulls your README file out of
the archive and makes it available to CPAN users, it is the first thing
they will read to decide if your module is right for them.
=item INSTALL
Instructions on how to install your module along with any dependencies.
Suggested information to include here:
any extra modules required for use
the minimum version of Perl required
if only works on certain operating systems
=item MANIFEST.SKIP
A file full of regular expressions to exclude when using 'make
manifest' to generate the MANIFEST. These regular expressions
are checked against each file path found in the distribution (so
you're matching against "t/foo.t" not "foo.t").
Here's a sample:
~$ # ignore emacs and vim backup files
.bak$ # ignore manual backups
\# # ignore CVS old revision files and emacs temp files
Since # can be used for comments, # must be escaped.
MakeMaker comes with a default MANIFEST.SKIP to avoid things like
version control directories and backup files. Specifying your own
will override this default.
=item bin/
=back
=head1 SEE ALSO
L<perlmodstyle> gives stylistic help writing a module.
L<perlnewmod> gives more information about how to write a module.
There are modules to help you through the process of writing a module:
L<ExtUtils::ModuleMaker>, L<Module::Starter>, L<Minilla::Tutorial>,
L<Dist::Milla::Tutorial>, L<Dist::Zilla::Starter>
=cut
1;

View File

@@ -0,0 +1,57 @@
#--------------------------------------------------------------------------#
# This is a modified copy of version.pm 0.9909, bundled exclusively for
# use by ExtUtils::Makemaker and its dependencies to bootstrap when
# version.pm is not available. It should not be used by ordinary modules.
#
# When loaded, it will try to load version.pm. If that fails, it will load
# ExtUtils::MakeMaker::version::vpp and alias various *version functions
# to functions in that module. It will also override UNIVERSAL::VERSION.
#--------------------------------------------------------------------------#
package ExtUtils::MakeMaker::version;
use 5.006001;
use strict;
use warnings;
use vars qw(@ISA $VERSION $CLASS $STRICT $LAX *declare *qv);
$VERSION = '7.58';
$VERSION =~ tr/_//d;
$CLASS = 'version';
{
local $SIG{'__DIE__'};
eval "use version";
if ( $@ ) { # don't have any version.pm installed
eval "use ExtUtils::MakeMaker::version::vpp";
die "$@" if ( $@ );
no warnings;
delete $INC{'version.pm'};
$INC{'version.pm'} = $INC{'ExtUtils/MakeMaker/version.pm'};
push @version::ISA, "ExtUtils::MakeMaker::version::vpp";
$version::VERSION = $VERSION;
*version::qv = \&ExtUtils::MakeMaker::version::vpp::qv;
*version::declare = \&ExtUtils::MakeMaker::version::vpp::declare;
*version::_VERSION = \&ExtUtils::MakeMaker::version::vpp::_VERSION;
*version::vcmp = \&ExtUtils::MakeMaker::version::vpp::vcmp;
*version::new = \&ExtUtils::MakeMaker::version::vpp::new;
if ("$]" >= 5.009000) {
no strict 'refs';
*version::stringify = \&ExtUtils::MakeMaker::version::vpp::stringify;
*{'version::(""'} = \&ExtUtils::MakeMaker::version::vpp::stringify;
*{'version::(<=>'} = \&ExtUtils::MakeMaker::version::vpp::vcmp;
*version::parse = \&ExtUtils::MakeMaker::version::vpp::parse;
}
require ExtUtils::MakeMaker::version::regex;
*version::is_lax = \&ExtUtils::MakeMaker::version::regex::is_lax;
*version::is_strict = \&ExtUtils::MakeMaker::version::regex::is_strict;
*LAX = \$ExtUtils::MakeMaker::version::regex::LAX;
*STRICT = \$ExtUtils::MakeMaker::version::regex::STRICT;
}
elsif ( ! version->can('is_qv') ) {
*version::is_qv = sub { exists $_[0]->{qv} };
}
}
1;

View File

@@ -0,0 +1,125 @@
#--------------------------------------------------------------------------#
# This is a modified copy of version.pm 0.9909, bundled exclusively for
# use by ExtUtils::Makemaker and its dependencies to bootstrap when
# version.pm is not available. It should not be used by ordinary modules.
#--------------------------------------------------------------------------#
package ExtUtils::MakeMaker::version::regex;
use strict;
use warnings;
use vars qw($VERSION $CLASS $STRICT $LAX);
$VERSION = '7.58';
$VERSION =~ tr/_//d;
#--------------------------------------------------------------------------#
# Version regexp components
#--------------------------------------------------------------------------#
# Fraction part of a decimal version number. This is a common part of
# both strict and lax decimal versions
my $FRACTION_PART = qr/\.[0-9]+/;
# First part of either decimal or dotted-decimal strict version number.
# Unsigned integer with no leading zeroes (except for zero itself) to
# avoid confusion with octal.
my $STRICT_INTEGER_PART = qr/0|[1-9][0-9]*/;
# First part of either decimal or dotted-decimal lax version number.
# Unsigned integer, but allowing leading zeros. Always interpreted
# as decimal. However, some forms of the resulting syntax give odd
# results if used as ordinary Perl expressions, due to how perl treats
# octals. E.g.
# version->new("010" ) == 10
# version->new( 010 ) == 8
# version->new( 010.2) == 82 # "8" . "2"
my $LAX_INTEGER_PART = qr/[0-9]+/;
# Second and subsequent part of a strict dotted-decimal version number.
# Leading zeroes are permitted, and the number is always decimal.
# Limited to three digits to avoid overflow when converting to decimal
# form and also avoid problematic style with excessive leading zeroes.
my $STRICT_DOTTED_DECIMAL_PART = qr/\.[0-9]{1,3}/;
# Second and subsequent part of a lax dotted-decimal version number.
# Leading zeroes are permitted, and the number is always decimal. No
# limit on the numerical value or number of digits, so there is the
# possibility of overflow when converting to decimal form.
my $LAX_DOTTED_DECIMAL_PART = qr/\.[0-9]+/;
# Alpha suffix part of lax version number syntax. Acts like a
# dotted-decimal part.
my $LAX_ALPHA_PART = qr/_[0-9]+/;
#--------------------------------------------------------------------------#
# Strict version regexp definitions
#--------------------------------------------------------------------------#
# Strict decimal version number.
my $STRICT_DECIMAL_VERSION =
qr/ $STRICT_INTEGER_PART $FRACTION_PART? /x;
# Strict dotted-decimal version number. Must have both leading "v" and
# at least three parts, to avoid confusion with decimal syntax.
my $STRICT_DOTTED_DECIMAL_VERSION =
qr/ v $STRICT_INTEGER_PART $STRICT_DOTTED_DECIMAL_PART{2,} /x;
# Complete strict version number syntax -- should generally be used
# anchored: qr/ \A $STRICT \z /x
$STRICT =
qr/ $STRICT_DECIMAL_VERSION | $STRICT_DOTTED_DECIMAL_VERSION /x;
#--------------------------------------------------------------------------#
# Lax version regexp definitions
#--------------------------------------------------------------------------#
# Lax decimal version number. Just like the strict one except for
# allowing an alpha suffix or allowing a leading or trailing
# decimal-point
my $LAX_DECIMAL_VERSION =
qr/ $LAX_INTEGER_PART (?: \. | $FRACTION_PART $LAX_ALPHA_PART? )?
|
$FRACTION_PART $LAX_ALPHA_PART?
/x;
# Lax dotted-decimal version number. Distinguished by having either
# leading "v" or at least three non-alpha parts. Alpha part is only
# permitted if there are at least two non-alpha parts. Strangely
# enough, without the leading "v", Perl takes .1.2 to mean v0.1.2,
# so when there is no "v", the leading part is optional
my $LAX_DOTTED_DECIMAL_VERSION =
qr/
v $LAX_INTEGER_PART (?: $LAX_DOTTED_DECIMAL_PART+ $LAX_ALPHA_PART? )?
|
$LAX_INTEGER_PART? $LAX_DOTTED_DECIMAL_PART{2,} $LAX_ALPHA_PART?
/x;
# Complete lax version number syntax -- should generally be used
# anchored: qr/ \A $LAX \z /x
#
# The string 'undef' is a special case to make for easier handling
# of return values from ExtUtils::MM->parse_version
$LAX =
qr/ undef | $LAX_DECIMAL_VERSION | $LAX_DOTTED_DECIMAL_VERSION /x;
#--------------------------------------------------------------------------#
# Preloaded methods go here.
sub is_strict { defined $_[0] && $_[0] =~ qr/ \A $STRICT \z /x }
sub is_lax { defined $_[0] && $_[0] =~ qr/ \A $LAX \z /x }
1;

File diff suppressed because it is too large Load Diff