Readonly 2.02+ not working with Storable
When storing a Readonly variable with Storable::store, retrieving the value again using Storable::retrieve results in the error message:
Can't locate Readonly/Scalar.pm in @INC (you may need to install the Readonly::Scalar module)
The following test-script illustrates the problem:
use Storable;
use Readonly;
Readonly my $a => 1;
store(\$a, "test");
retrieve("test");
The error also appears for arrays and hashes.
Using Readonly 2.01 works, and it appears that the issue is with the stored value, as Readonly 2.02 can retrieve files stored by Readonly 2.01. Trying to retrieve a file stored by Readonly 2.02, using Readonly 2.01 gives the same error message.
I've bisected the problem, and it appears to be caused by commit 03fea5a
I'm using Perl 5.24 and Storable 2.51.
I've dug a bit deeper into it, and it appears that the following also fails with the same error message:
use Readonly;
Readonly my $a => 1;
Readonly::Clone $a;
However, if I change the declaration of the read only scalar to be Readonly::Scalar, it works.
Is this by design, and is that why you marked it wontfix?
You're free to fork, repair, and submit a PR.
This appears to be caused by the STORABLE_freeze functions, and the fact that the 3 sub-packages (Readonly::Scalar, Readonly::Hash and Readonly::Array) are contained within Readonly.pm and not separate packages (the error states that it can't locate Readonly/<TYPE>.pm). I don't know what the solution is, but I also don't know what the reason for including those functions was.
Further investigation and testing makes me wonder what the point of the STORABLE_freeze functions is, and if they were ever tested. Because commenting them out doesn't seem to break anything, and it makes Storable work again. Is there any reason not to just remove them?
Pull requests with tests welcome.