Module...ERSION(3pm)

✨ NAME ✨

Module::Extract::VERSION β€” it pulls a module's version out of its source code, and it does it safely πŸ’… (this is a 3pm page from the User Contributed Perl Documentation, bestie, so it's a Perl module manual, and we are gonna read it together)


🌸 SYNOPSIS 🌸

use Module::Extract::VERSION;

my $version   # just the version
        = Module::Extract::VERSION->parse_version_safely( $file );

my @version_info # extra info
        = Module::Extract::VERSION->parse_version_safely( $file );

πŸŽ€ DESCRIPTION πŸŽ€

Okay so picture this: you've got module source code, and buried in there somewhere is the version number. This module's whole job is fishing that version number out for you. ✨

It assumes two things, and you need to know them, no cap:

  • there is only one $VERSION in the file
  • the entire $VERSION statement lives on one single line

🧚 Class methods

  • $class->parse_version_safely( FILE ); β€” hand it a module file, get the module version back. It works exactly the same way "mldistwatch" in PAUSE works. The vibe: it finds the one line holding the $VERSION statement, extracts it, evals it inside a Safe compartment, and returns whatever comes out. 🫢

Now here's the context tea, because it matters:

  • In scalar context, you just get the version as a string. Simple. Iconic.
  • In list context, you get a whole list of goodies:
sigil
fully-qualified variable name
version value
file name
line number of $VERSION

πŸ¦‹ SOURCE AVAILABILITY πŸ¦‹

This code lives on Github, go be nosy:

https://github.com/briandfoy/module-extract-version.git

πŸ‘‘ AUTHOR πŸ‘‘

brian d foy, "<briandfoy@pobox.com>"

Real talk though, some of this code was stolen from "mldistwatch" in the PAUSE code by Andreas KΓΆnig β€” but our guy moved most of it around, so it's a remix. 😭

And shoutout to Andrey Starodubtsev, who added code to handle the v5.12 and v5.14 "package" syntax. The way that syntax needed handling… ate. πŸ’…


Copyright Β© 2008-2026, brian d foy "<briandfoy@pobox.com>". All rights reserved.

You may redistribute this under the Artistic License 2.0. Periodt.


friendly little reminder bestie: it needs exactly one $VERSION and that whole statement has to sit on a single line, or this whole thing gets sad πŸ™ˆ

stay slay, run your version checks, and remember β€” this page is perl v5.40.1, dated 2026-06-21, and it's the Module::Extract::VERSION 3pm manual πŸ’œ

πŸ“¦ where this page comes from