Wolfman via RT wrote:
Show quoted text> This is bare minimum code for how Readonly is supposed to be used for
> constants. However, running perlcritic -4 (down to -1) FILE reports this:
>
> Subroutine "Readonly" is neither declared nor explicitly imported at
> line 3, column 1. This might be a major bug. (Severity: 4)
>
> Please confirm I'm using the syntax right.
Ooh. You're using P::C::StricterSubs. You're really going in for the serious stuff. :]
One hint: put "verbose = %f: %m at line %l, column %c. %e. (Severity: %s, %p)\n" (yes, the characters "\" and "n" in there) into your perlcriticrc. The "%p" will give you the short name of the policy in question.
Anyway, Perl::Critic::Policy::Subroutines::ProhibitCallsToUndeclaredSubs doesn't take Readonly into account, unfortunately. However, it does have an exempt_subs option. So, in your perlcriticrc, you can put something like this:
[Subroutines::ProhibitCallsToUndeclaredSubs]
exempt_subs = Readonly::Readonly
On the other hand, you may just want to disable this policy altogether; it was written for some people who have some very strict requirements for their code. (I personally don't use any of StricterSubs.)
[-Subroutines::ProhibitCallsToUndeclaredSubs]
Ignoring P::C, if you're using Readonly, you might want to consider using Readonly::XS; it's a /lot/ faster for scalars. It doesn't compile on 5.10 out of the box, but the fix is really simple if you look at the code. However, for R::XS to take effect, you've got to use the full Scalar() subroutine name, you can't just use "Readonly":
Readonly::Scalar my $HI => 50;
You don't need to look at Readonly::Array() or Readonly::Hash(), R::XS does nothing in terms of optimizing those.