Что такое формат файла PM?
A .pm file is a Perl module - a plain-text source file that packages reusable Perl code into a named namespace. The module system was introduced with Perl 5 in 1994 and remains the foundation of the CPAN ecosystem, which hosts hundreds of thousands of .pm modules.
Every .pm file declares its namespace near the top with a package statement (e.g., package HTTP::Tiny;) and conventionally ends with a bare 1; so that use or require can verify a successful load. There is no binary magic number; the file is identified by its .pm extension and the presence of a package declaration.
Module name and file path are directly linked: Foo::Bar maps to Foo/Bar.pm somewhere on Perl's @INC search path. A module is loaded by a .pl script or another module with use Module::Name; or require "Module/Name.pm".
Typical contents include:
- Exported subroutines and variables (usually managed with
Exporter) - Object-oriented class definitions
- Embedded
.poddocumentation blocks - A version declaration via
our $VERSION = '1.00';
Modules are interpreted at run time; .pmc files are an optional byte-code cache. The MIME type is text/x-perl and the encoding is usually UTF-8 or ASCII, declared with use utf8; when needed.
Безопасность и защита
РИСК: MEDIUMA .pm file is plain text and safe to read or open in an editor - it cannot act by itself. The risk is in RUNNING it: Perl modules are executable code that can read/write files, run shell commands and make network calls, and code can even run at load time (BEGIN blocks, import logic) the moment a script does 'use Module;'. So treat an untrusted .pm like any program: read it before you load it, and don't run Perl code from sources you don't trust. The file sitting on disk is harmless.
Детали формата
в двух словах- Adobe PageMaker publication (.pm) - Older Aldus/Adobe PageMaker desktop-publishing documents used the .pm extension (later .pm5/.pm6/.p65/.pmd); open/convert in Adobe InDesign.
Программы, открывающие файлы PM
Технические подробности
глубокая спецификация| MIME type | text/x-perl (also accepted: application/x-perl, text/plain) |
| Encoding | UTF-8 or ASCII; non-ASCII source requires an explicit `use utf8;` declaration |
| File structure | `package` declaration → imports (`use`/`require`) → subroutines and variables → optional `Exporter` setup → embedded POD docs → trailing true value (`1;`) |
| Magic bytes / signature | None; no binary signature. Identified by the `.pm` extension and a `package` statement near the top. An optional UTF-8 BOM (EF BB BF) may precede the first line. |
| Namespace-to-path mapping | Module name maps directly to its file path: `Foo::Bar` resolves to `Foo/Bar.pm` on Perl's `@INC` search path |
| Loading mechanism | Compile-time loading via `use Module;`; run-time loading via `require 'Module/Name.pm'` or `require Module::Name` |
| True-value terminator | Must end with a true value - conventionally bare `1;` - so the caller can confirm the file loaded without error |
| Version targeting | Minimum Perl version declared with `use v5.xx;` or `use 5.010;`; no file-format version of its own |
| Typical file size | 1 KB - 200 KB per module |
| Export mechanism | Subroutines and variables are selectively exposed to callers via the `Exporter` module using `@EXPORT` and `@EXPORT_OK` arrays |
| Documentation embedding | Inline Plain Old Documentation (POD) blocks, delimited by `=pod` / `=cut`; parsed by `perldoc` and POD renderers |
| Byte-code cache | Perl may store a pre-compiled form alongside the source as a `.pmc` file; the `.pm` itself is never compiled to a standalone binary |
| Obfuscation / encryption | Plain text by default; optional source filtering via modules such as `Filter::Crypto` or `Filter::Util::Call` |
| Associated platforms | Linux, macOS, Windows (Strawberry Perl / ActivePerl), and any other OS where Perl is installed |
| Выпущен | 1987 (Perl 1.0); the .pm module convention dates to Perl 5 (1994) |
| Последняя версия | Perl 5.40 (2024); Perl modules remain the standard library packaging unit |
| Открыть стандартное | Да · без роялти |
| Спецификация | perldoc.perl.org |
Конвертации PM
Вопросы и ответы сообщества
спрошено пользователямиВопросов пока нет - станьте первым, кто спросит о файлах PM.