Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: How do you use the if pragma?

by tobyink (Abbot)
on Apr 08, 2013 at 23:27 UTC ( #1027609=note: print w/ replies, xml ) Need Help??


in reply to How do you use the if pragma?

My most frequent uses of if seem to be:

# Loading either "mro" or "MRO::Compat" depending # on Perl version... # use if $] >= 5.010, 'mro'; use if $] < 5.010, 'MRO::Compat'; # Load UNIVERSAL::DOES for Perl prior to 5.10. # use if $] < 5.010, 'UNIVERSAL::DOES';

It's pretty easy to emulate it anyway:

# Loading either "mro" or "MRO::Compat" depending # on Perl version... # BEGIN { if ($] >= 5.010) { require mro; mro->import } else { require MRO::Compat; MRO::Compat->import } }; # Load UNIVERSAL::DOES for Perl prior to 5.10. # BEGIN { require 'UNIVERSAL::DOES' if $] < 5.010; };

CPAN also has unless.

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


Comment on Re: How do you use the if pragma?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (18)
As of 2015-07-07 17:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (92 votes), past polls