Perl v5.12 adds the package NAME VERSION syntax

Perl v5.12 modifies the package statement to take a version as well as a name. This allows you to implicitly declare the $VERSION variable:


package Some::Package 1.23;

This is the same as setting $VERSION explicitly:

package Some::Package;

our $VERSION = '1.23';

or the older, pre-our way:

package Some::Package;
use vars qw($VERSION);

$VERSION = '1.23';

Remember, the package statement merely changes the default package. There’s not much more magic than that. If you declare multiple versions, the last one wins even if it’s lower than the ones that came before (and there’s no warning), but everything is still in the same package:

use v5.12;

package Local::foo 1.23;

sub show_version {
	say "Version is " . Local::foo->VERSION;
	}

__PACKAGE__->show_version;

package Local::foo 1.24;

__PACKAGE__->show_version;

package Local::foo 1.22;

__PACKAGE__->show_version;
Leave a comment

0 Comments.

Leave a Reply


[ Ctrl + Enter ]