The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Devel::PPPort - Perl/Pollution/Portability

SYNOPSIS

  Devel::PPPort::WriteFile();   # defaults to ./ppport.h
  Devel::PPPort::WriteFile('someheader.h');

  # Same as above but retrieve contents rather than write file
  my $contents = Devel::PPPort::GetFileContents();
  my $contents = Devel::PPPort::GetFileContents('someheader.h');

Start using Devel::PPPort for XS projects

  $ cpan Devel::PPPort
  $ perl -MDevel::PPPort -e'Devel::PPPort::WriteFile'
  $ perl ppport.h --compat-version=5.6.1 --patch=diff.patch *.xs
  $ patch -p0 < diff.patch
  $ echo ppport.h >>MANIFEST

DESCRIPTION

Perl's API has changed over time, gaining new features, new functions, increasing its flexibility, and reducing the impact on the C namespace environment (reduced pollution). The header file written by this module, typically ppport.h, attempts to bring some of the newer Perl API features to older versions of Perl, so that you can worry less about keeping track of old releases, but users can still reap the benefit.

Devel::PPPort contains two functions, WriteFile and GetFileContents. WriteFile's only purpose is to write the ppport.h C header file. This file contains a series of macros and, if explicitly requested, functions that allow XS modules to be built using older versions of Perl. Currently, Perl versions from __MIN_PERL__ to __MAX_PERL__ are supported.

GetFileContents can be used to retrieve the file contents rather than writing it out.

This module is used by h2xs to write the file ppport.h.

Why use ppport.h?

You should use ppport.h in modern code so that your code will work with the widest range of Perl interpreters possible, without significant additional work.

You should attempt to get older code to fully use ppport.h, because the reduced pollution of newer Perl versions is an important thing. It's so important that the old polluting ways of original Perl modules will not be supported very far into the future, and your module will almost certainly break! By adapting to it now, you'll gain compatibility and a sense of having done the electronic ecology some good.

How to use ppport.h

Don't direct the users of your module to download Devel::PPPort. They are most probably not XS writers. Also, don't make ppport.h optional. Rather, just take the most recent copy of ppport.h that you can find (e.g. by generating it with the latest Devel::PPPort release from CPAN), copy it into your project, adjust your project to use it, test it, and distribute the header along with your module.

It is important to use the most recent version of ppport.h. You do need to test before shipping a newer version than you already had. One possible failure is that someone had to convert a backported element from a macro into a function, and actual functions must be enabled with a NEED macro to minimize the possibility of namespace pollution. See HACKERS for details. The developers of Devel::PPPort want to hear if there are other problems that arise from using a later ppport.h. Use https://github.com/Dual-Life/Devel-PPPort/issues to report any.

Running ppport.h

But ppport.h is more than just a C header. It's also a Perl script that can check your source code. It will suggest hints and portability notes, and can even make suggestions on how to change your code. You can run it like any other Perl program:

    perl ppport.h [options] [files]

It also has embedded documentation, so you can use

    perldoc ppport.h

to find out more about how to use it.

FUNCTIONS

WriteFile

WriteFile takes one optional argument. When called with one argument, it expects to be passed a filename. When called with no arguments, it defaults to the filename ppport.h.

The function returns a true value if the file was written successfully. Otherwise it returns a false value.

GetFileContents

GetFileContents behaves like WriteFile above, but returns the contents of the would-be file rather than writing it out.

COMPATIBILITY

ppport.h supports Perl versions from __MIN_PERL__ to __MAX_PERL__ in threaded and non-threaded configurations.

Provided Perl compatibility API

The header file written by this module, typically ppport.h, provides access to the following elements of the Perl API that are not otherwise available in Perl releases older than when the elements were first introduced. (Note that many of these are not supported all the way back to __MIN_PERL__, but it may be that they are supported back as far as you need; see "Supported Perl API, sorted by version" for that information.)

    __PROVIDED_API__

Supported Perl API, sorted by version

The table in this section lists all the Perl API elements available, sorted by the version in which support starts. This includes all the elements that ppport.h helps out with, as well as those elements that it doesn't.

In some cases, it doesn't make practical sense for elements to be supported earlier than they already are. For example, UTF-8 functionality isn't provided prior to the release where it was first introduced.

But in other cases, it just is that no one has implemented support yet. Patches welcome! Some elements are ported backward for some releases, but not all the way to __MIN_PERL__.

If an element, call it ELEMENT, is not on this list, try using this command to find out why:

 perl ppport.h --api-info=ELEMENT

A few of the entries in the list below are marked as DEPRECATED. You should not use these for new code, and should be converting existing uses to use something better.

Some of the entries in the list are marked as "experimental". This means these should not generally be used. They may be removed or changed without notice. You can ask why they are experimental by sending email to mailto:perl5-porters@perl.org.

And some of the entries are marked as "undocumented". This means that they aren't necessarily considered stable, and could be changed or removed in some future release without warning. It is therefore a bad idea to use them without further checking. It could be that these are considered to be for perl core use only; or it could be, though, that Devel::PPPort doesn't know where to find their documentation, or that it's just an oversight that they haven't been documented. If you want to use one, and potentially have it backported, first send mail to mailto:perl5-porters@perl.org.

    __UNSUPPORTED_API__

BUGS

If you find any bugs, Devel::PPPort doesn't seem to build on your system, or any of its tests fail, please send a bug report to https://github.com/Dual-Life/Devel-PPPort/issues/new.

AUTHORS

  • Version 1.x of Devel::PPPort was written by Kenneth Albanowski.

  • Version 2.x was ported to the Perl core by Paul Marquess.

  • Version 3.x was ported back to CPAN by Marcus Holland-Moritz.

  • Versions >= 3.22 are maintained by perl5 porters

COPYRIGHT

Version 3.x, Copyright (C) 2004-2013, Marcus Holland-Moritz.

             Copyright (C) 2018-2020, The perl5 porters

Version 2.x, Copyright (C) 2001, Paul Marquess.

Version 1.x, Copyright (C) 1999, Kenneth Albanowski.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

See h2xs, ppport.h.