http://qs1969.pair.com?node_id=1165152


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,