Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Problem with perlcritic when using Moose object

by haj (Vicar)
on Oct 04, 2018 at 16:09 UTC ( [id://1223539]=note: print w/replies, xml ) Need Help??


in reply to Problem with perlcritic when using Moose object

Edited (again): As haukex points out in his reply, I've apparently just been paranoiac without a good reason. There's nothing wrong with an unquoted shift within braces, the following advice can safely be scratched.

Instead of if($hash->{shift}) { $Person->shift( $hash->{shift} ); } use:
if($hash->{'shift'}) { $Person->shift( $hash->{'shift'} ); }
The Perl parser could confuse the bareword shift in the braces with its core function shift instead of converting it to a string. (edited because I tested the stuff and found out that it does not confuse it right now).

Replies are listed 'Best First'.
Re^2: Problem with perlcritic when using Moose object
by haukex (Archbishop) on Oct 05, 2018 at 15:07 UTC
    The Perl parser could confuse the bareword shift in the braces with its core function shift instead of converting it to a string.

    I'm pretty sure that Perl will always take $hash{shift} to mean the hash key "shift", although adding any other characters will change that ($hash{+shift}, $hash{shift()}, etc.) See also.

      I'm pretty sure that Perl will always take $hash{shift} to mean the hash key "shift", although adding any other characters will change that ($hash{+shift}, $hash{shift()}, etc.)

      I guess you're right. I've posted from memory because I thought that I had been bitten by something like that in the past. However, I failed to find any evidence, nor could I construct any test supporting my case. Quite on the contrary, I found that some other characters won't even prevent stringification, as is demonstrated by Tk's habit of having $hashref->{-option} reliably interpreted as $hashref->{'-option'}.

      Thanks for the correction!

        $hashref->{-option} reliably interpreted as $hashref->{'-option'}

        Interestingly, the former is actually interpreted as an expression (note the "negate" below), but the because of the properties of unary -, -bareword is the same as "-bareword". As of v5.26, "Bareword constant strings are now permitted to take part in constant folding."

        $ perlbrew exec --with 5.24.4,5.26.2 perl -MO=Concise -wMstrict -e 'my + %hash; print $hash{-foo}' perl-5.24.4 ========== b <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 2 -e:1) v:*,&,{,x*,x&,x$,$ ->3 3 <0> padhv[%hash:2,3] vM/LVINTRO ->4 4 <;> nextstate(main 3 -e:1) v:*,&,{,x*,x&,x$,$ ->5 a <@> print vK ->b 5 <0> pushmark s ->6 9 <2> helem sK/2 ->a 6 <0> padhv[%hash:2,3] sR ->7 8 <1> negate[t2] sK/1 ->9 7 <$> const(PV "foo") s/BARE ->8 -e syntax OK perl-5.26.2 ========== 8 <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 2 <;> nextstate(main 2 -e:1) v:*,&,{,x*,x&,x$,$ ->3 3 <0> padhv[%hash:2,3] vM/LVINTRO ->4 4 <;> nextstate(main 3 -e:1) v:*,&,{,x*,x&,x$,$ ->5 7 <@> print vK ->8 5 <0> pushmark s ->6 - <1> ex-helem sK/2 ->7 6 <+> multideref($hash{"-foo"}) sK ->7 - <0> ex-padhv sR ->6 -e syntax OK
Re^2: Problem with perlcritic when using Moose object
by Anonymous Monk on Oct 05, 2018 at 20:04 UTC
    Nope. A false positive is a false positive. Thats a poorly written critic policy

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2026-04-11 17:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.