1

I have exercised a lot of features of this module, but sometimes have to install into an environment that has an older version of the module that doesn't have the features I have implemented.

So what's the best way to handle this? - Version check? - try{} catch{}?

Scransom
  • 3,175
  • 3
  • 31
  • 51
tomatoguy
  • 31
  • 1

1 Answers1

2

All perl objects extend from the UNIVERSAL module which

is the base class from which all blessed references inherit

You can call can on the module to test to see if a particular method is implemented in the package.

perl -MExcel::Writer::XLSX -e 'if (Excel::Writer::XLSX->can("set_vba_name")) {print "It can";}';

perl -MExcel::Writer::XLSX -e '$xlsx = Excel::Writer::XLSX->new("/tmp/file");  if ($xlsx->can("add_worksheet")) {print "It can"}';

I'd avoid using version checking, it makes testing and development much harder, but can work in a pinch.

Ultimately, you want a consistent runtime environment, so you could create a makefile that installs all of the dependencies at the version you need.

Trenton Trama
  • 4,890
  • 1
  • 22
  • 27
  • Thanks very much! Oh, if only I could dictate the environment! But, I can't always. :( And my dev environment can get ahead of production. And I implement based on the latest features available in my dev. At least this way I can sense whether something is not possible and ignore it. – tomatoguy May 21 '20 at 21:27