readonly icon indicating copy to clipboard operation
readonly copied to clipboard

ReadonlyX clashes with Readonly being used internally by other modules

Open gwselke opened this issue 5 years ago • 1 comments

I have a script directly using ReadonlyX and also using another module which, in turn, uses Readonly (note: no "X"). This leads to a bunch of warnings of the following kind:

Prototype mismatch: sub Readonly::Scalar ($$) vs ($;$) at C:/perl/perl/site/lib/ReadonlyX.pm line 19. Prototype mismatch: sub Readonly::Readonly ([$@%]@) vs ([%@$]$) at C:/perl/perl/site/lib/ReadonlyX.pm line 20. Subroutine Array redefined at C:/perl/perl/site/lib/ReadonlyX.pm line 22. Subroutine Hash redefined at C:/perl/perl/site/lib/ReadonlyX.pm line 32. Prototype mismatch: sub Readonly::Scalar ($$) vs ($;$) at C:/perl/perl/site/lib/ReadonlyX.pm line 50. Subroutine Scalar redefined at C:/perl/perl/site/lib/ReadonlyX.pm line 42. Prototype mismatch: sub Readonly::Readonly ([$@%]@) vs ([%@$]$) at C:/perl/perl/site/lib/ReadonlyX.pm line 58. Subroutine Readonly redefined at C:/perl/perl/site/lib/ReadonlyX.pm line 52. Subroutine Clone redefined at C:/perl/perl/site/lib/ReadonlyX.pm line 95.

To reproduce:

use strict;
use warnings;
use ReadonlyX;
use Graph::Dijkstra;

In this specific case, I can just skip using ReadonlyX and revert my script to Readonly, since I control this script. Conceivably however, one might run into the situation where one third-party module's use of Readonly clashes with another third party module's use of ReadonlyX. I'm not sure I would call this a bug in ReadonlyX, but it's certainly an issue.

gwselke avatar Oct 14 '20 09:10 gwselke

Here's what seems to work...but apparently there are differences between ReadonlyX and Readonly that might trip you up if you rely on the nuances/bugs of Readonly.

BEGIN {                                                                                                                                                                                   
  use Module::Loaded;                                                                                                                                                                     
  use ReadonlyX;
  
 mark_as_loaded('Readonly');
}

This also gets you the speed improvements of using ReadonlyX vs Readonly.

1/14/23 - follow - up

Readonly and ReadonlyX are not necessarily drop in replacements as I said above, so the technique used here might have to be reversed...that is use Readonly and mark ReadonlyX as loaded...I found this when maintaining some code that uses File::BOM which uses Readonly and in a manner incompatible with ReadonlyX.

rlauer6 avatar Jul 15 '22 18:07 rlauer6