Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Perl::Critic error "Readonly version 21 required"

by 7stud (Deacon)
on Feb 15, 2013 at 05:02 UTC ( #1018843=perlquestion: print w/ replies, xml ) Need Help??
7stud has asked for the wisdom of the Perl Monks concerning the following question:

First try with Perl::Critic. According to cpan here, the latest version of Readonly is 1.03. How do I get rid of the Readonly error along with the rest of them:

package CriticMy; use strict; use warnings; use 5.010; use criticism 'gentle'; use Readonly my $unprintable => 0x15; #***LINE 8***** our $VERSION = 1.00; 1; --output:-- Use of uninitialized value $_ in pattern match (m//) at /Users/7stud/p +erl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/Exporter.pm line 57. Use of uninitialized value $_ in exists at /Users/7stud/perl5/perlbrew +/perls/perl-5.16.0/lib/5.16.0/Exporter.pm line 57. Use of uninitialized value $_ in pattern match (m//) at CriticMy.pm li +ne 8. Use of uninitialized value $sym in hash element at CriticMy.pm line 8. Use of uninitialized value $sym in pattern match (m//) at CriticMy.pm +line 8. Use of uninitialized value $sym in substitution (s///) at CriticMy.pm +line 8. Use of uninitialized value $sym in hash element at CriticMy.pm line 8. Use of uninitialized value $sym in concatenation (.) or string at Crit +icMy.pm line 8. Readonly version 21 required--this is only version 1.03 at /Users/7stu +d/perl5/perlbrew/perls/perl-5.16.0/lib/5.16.0/Exporter/Heavy.pm line +120. BEGIN failed--compilation aborted at CriticMy.pm line 8.

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

    G'day 7stud,

    I think you're main problem there is syntax. Compare

    $ perl -Mstrict -Mwarnings -e ' use Readonly my $unprintable => 0x15; ' Readonly version 21 required--this is only version 1.03 at /Users/ken/ +perl5/perlbrew/perls/perl-5.14.2_WITH_THREADS/lib/5.14.2/Exporter/Hea +vy.pm line 120. BEGIN failed--compilation aborted at -e line 2.

    with

    $ perl -Mstrict -Mwarnings -e ' use Readonly; Readonly my $unprintable => 0x15; '

    I don't have the criticism module installed; however, I don't think the problem is related to Perl::Critic. See how you go with the altered syntax.

    -- Ken

      Arghh! Thanks. After changing that, and then changing my constant to all upper case, I didn't get any errors. But when I use criticism 'brutal', I get:

      Code is not tidy at CriticMy.pm line 1.

      I think I should be able to sort that out.

Re: Perl::Critic error "Readonly version 21 required"
by tobyink (Abbot) on Feb 15, 2013 at 06:53 UTC

    Note:

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

      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: perlquestion [id://1018843]
Approved by vinoth.ree
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2014-07-12 22:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (241 votes), past polls