Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Perl::Critic error "Readonly version 21 required"

by tobyink (Abbot)
on Feb 15, 2013 at 06:53 UTC ( #1018850=note: print w/ replies, xml ) Need Help??


in reply to Perl::Critic error "Readonly version 21 required"

Note:

0x15 == 21
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name


Comment on Re: Perl::Critic error "Readonly version 21 required"
Download Code
Re^2: Perl::Critic error "Readonly version 21 required"
by tobyink (Abbot) on Feb 15, 2013 at 10:06 UTC

    It seems Exporter (which Readonly, and many, many, many, many other modules use internally) has a weird feature (in my opinion a misfeature) where it does its own module version number checking.

    Normally when you write:

    use Module 1.23;

    ... perl will catch the version number, and not treat it as an argument to Module->import, instead passing it to Module->VERSION to act as a version number check.

    However, it seems Exporter makes an attempt to catch number-like arguments that perl has missed, and do its own version checking with them. Notice the difference between the following two examples; the first one where the version check is done by perl, and the second where it's done by Exporter.pm

    $ perl -e'use Carp 100 ()' Carp version 100 required--this is only version 1.26 at -e line 1. BEGIN failed--compilation aborted at -e line 1. $ perl -e'use Carp () => 100' Carp version 100 required--this is only version 1.26 at /home/tai/perl +5/perlbrew/perls/perl-5.16.2/lib/5.16.2/Exporter/Heavy.pm line 120. BEGIN failed--compilation aborted at -e line 1.

    In your original example, this line:

    use Readonly my $unprintable => 0x15;

    ... is run as:

    use Readonly undef => 0x15;

    ... because the variable is undefined. So Exporter's version number check kicks in, even though the 0x15 was clearly never intended as a module version number.

    Yet another reason to avoid using Exporter and use something sane like Sub::Exporter.

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
      Sheesh. I had no idea what your previous post meant. Thanks for the explanation.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1018850]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2014-08-28 01:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (255 votes), past polls