John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

package Method::Signatures::Simple; BEGIN { $Method::Signatures::Simple::VERSION = '0.06'; } use warnings; use strict;
Why does this package access the package's hash like that, instead of just defining $VERSION in the usual way?

Replies are listed 'Best First'.
Re: Another VERSION variation?
by thargas (Deacon) on Apr 08, 2011 at 13:24 UTC

    It's not accessing the package's symbol table (which is what I interpret from your "... the packages's hash ..."). It's simply fully qualifying the $VERSION variable. It can't do my or local because $VERSION needs to be a package variable so that it can be accessed outside the package. This is simply one of the possible ways to declare this.

    They could have done any of the following:

    • $PackageName::VERSION = whatever;
    • our $VERSION = whatever;
    • use vars qw( $VERSION ); $VERSION = whatever;

      I see; thanks for clarifying that.
Re: Another VERSION variation?
by JavaFan (Canon) on Apr 08, 2011 at 10:40 UTC
    Ask the author, I would suggest. Since it hardly matters one way or the other, I don't think you'll get the answer here, unless the author replies to your post.
Re: Another VERSION variation?
by Anonymous Monk on Apr 08, 2011 at 10:29 UTC
    Because it can, John, full name and all that :)
Re: Another VERSION variation?
by ikegami (Patriarch) on Apr 08, 2011 at 18:06 UTC

    I don't know why the author chose to use the full name of the variable. There's no requirement to do so, and it even adds redundancy. But regardless, the package must be accessed. That's where package variables reside.

Re: Another VERSION variation?
by Anonymous Monk on Apr 11, 2011 at 06:32 UTC
    The package is likely developed with Dist::Zilla using the PkgVersion plugin. It's a nifty development tool and the plugin has to generate code that'll safely set $VERSION for the author.