pl2pm
Convert Perl library (.pl) files to modules (.pm)
SYNOPSIS
pl2pm oldlib.pl
DESCRIPTION
pl2pm is a Perl utility script designed to automate the conversion of legacy Perl library files (typically ending in .pl) into modern Perl module files (ending in .pm). It was created to facilitate the transition from Perl's pre-module era, where libraries were simple scripts without proper package structures, to the standardized module system using Exporter.
The script processes a single input file, typically located in a lib/ directory hierarchy (e.g., lib/Net/FTP.pl). It infers the package name from the relative path (e.g., Net::FTP) and wraps the original code with essential boilerplate:
- package Net::FTP;
- use strict;
- use Exporter; and @ISA = qw(Exporter);
- Auto-generates @EXPORT by scanning for subroutine definitions like sub ftp_get{...}
This tool is particularly useful for Perl core modules and CPAN libraries during early modernization efforts. However, the generated code often requires manual review and refinement for complex libraries, as it makes assumptions about exports and lacks support for advanced features like OO inheritance or custom export tags.
CAVEATS
No command-line options; assumes simple library format with subroutines to export. May overwrite existing .pm files; always review generated code. Does not handle files outside lib/ hierarchy well or modern syntax like signatures.
EXAMPLE
pl2pm lib/Net/FTP.pl
Generates lib/Net/FTP.pm with package Net::FTP and exports detected subs.
SOURCE LOCATION
Perl core: $PERL_LIB/pod/pl2pm (symlink to utils/pl2pm)
HISTORY
Introduced in Perl 5.0 (1994) as part of pod utilities to migrate pre-5.001 libraries to the new module system. Maintained in Perl core (pod/pl2pm) with minor tweaks for compatibility; largely obsolete today but useful for legacy code.


