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

Re: The "right" way to make your script run with old versions of perl

by Athanasius (Archbishop)
on Jun 08, 2016 at 15:33 UTC ( [id://1165152]=note: print w/replies, xml ) Need Help??


in reply to The "right" way to make your script run with old versions of perl

Hello xorl,

You can make this kind of code cleaner by taking an OO approach. Create an abstract class Module with the common interface, and subclass it as Module::SuperCool, Module::AlmostCool, and Module::Uncool. Then create a Module object once:

use Module; use Module::SuperCool; use Module::AlmostCool; use Module::Uncool; my $module_instance = ($] > 5.010) ? Module::SuperCool->new(...) : (($] <= 5.010) && ($] > 5.008)) ? Module::AlmostCool->new(...) : Module::Uncool->new(...); ... $module_instance->frobnicate(...);

and use it as needed — there will be no need for switch statements using a $supercool flag.

Of course, Module::SuperCool will be implemented using super cool functions provided by cutting-edge CPAN modules; Module::AlmostCool will be implemented using less cool functions from older CPAN modules; and Module::Uncool will be implemented using your 10,000 lines of code.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-04-19 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found