Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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 ( #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
Node Status?
node history
Node Type: note [id://1165152]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2021-05-14 14:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (150 votes). Check out past polls.

    Notices?