Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: How Critical is Critic?

by Bod (Parson)
on May 29, 2023 at 18:03 UTC ( [id://11152473]=note: print w/replies, xml ) Need Help??


in reply to Re: How Critical is Critic?
in thread How Critical is Critic?

I would certainly grill you during our code review meeting to "please explain" why on earth you're resorting to the dreaded stringy eval for such a simple chore

The answer would be because I understand that is what I am supposed to do because Perl uses underscores in the version number to indicate a development release. This release is currently a development release 0.1_1 with an underscore.

I strongly suspect that it was you eyepopslikeamosquito who directed me towards this practice as you were the one who helpfully provided the information I needed to publish my first module Business::Stripe::WebCheckout. I used almost exclusively the links you provided to do that which included adding $VERSION.

I cannot find the original code but here is an article that advises using this technique...

Replies are listed 'Best First'.
Re^3: How Critical is Critic?
by eyepopslikeamosquito (Archbishop) on May 29, 2023 at 21:42 UTC
      I would conclude our code review meeting by reaching for a towel to wipe the egg off my face. :)

      ...and I would ensure you save face by asking for your expert opinion on what you would do if you were me when this situation recurs...

      Which of these do you suggest I use and why? I am not entirely sure of the practical differences.

      our $VERSION = '0.1_1'; $VERSION = eval $VERSION;
      or perhaps
      our $VERSION = '0.1_1'; $VERSION = eval { $VERSION };
      or maybe
      use version; our $VERSION = version->parse('0.1_1');
      or something else entirely...

      I believe that eval { ... }; is compiled just once whereas eval ...; is compiled each time the module is instantiated. This may make a difference if the module is created for each use like MIME::Lite. However, this module should only be created once and subsequent method calls achieve everything it does.

      I don't see the point in fetching in the version module (even though it is core) to do something that can be done in two lines of simple code. Perhaps it does something more that I'm not aware of?

        The reasonable version of this idiom is:
        our $VERSION = '0.1_1'; $VERSION =~ tr/_//d;
        % perl -wle ' our $VERSION = "0.1_1"; $VERSION = eval $VERSION; if ($VERSION > 0.1 && $VERSION < 0.2) { print "ok"; } else { print "not ok"; } ' ok % perl -wle ' our $VERSION = "0.1_1"; $VERSION = eval { $VERSION }; if ($VERSION > 0.1 && $VERSION < 0.2) { print "ok"; } else { print "not ok"; } ' Argument "0.1_1" isn't numeric in numeric gt (>) at -e line 4. not ok %

        eval STRING and eval BLOCK do different things. In this case the BLOCK form is effectively a no-op, so the string is numified using standard coercion during the comparison, and yields the value 0.1 (plus a warning). The string form means "take this string and interpret it as a program" - and Perl code lets us put underscores in numbers, even though the standard coercion rejects them, so it evaluates as the value 0.11.

        I don't know about the version->parse variant, but I imagine that PAUSE would not find a version number to parse, so the module would not be indexed correctly.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2024-04-19 08:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found