Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadonlyX clashes with Readonly being used internally by other modules #37

Open
gwselke opened this issue Oct 14, 2020 · 1 comment
Open

Comments

@gwselke
Copy link

gwselke commented Oct 14, 2020

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.

@rlauer6
Copy link

rlauer6 commented Jul 15, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants