Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2022-05-27 07:16 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (94 votes). Check out past polls.