readonly icon indicating copy to clipboard operation
readonly copied to clipboard

Readonly 2.02+ not working with Storable

Open ksmadsen opened this issue 9 years ago • 5 comments

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.

ksmadsen avatar Dec 22 '16 08:12 ksmadsen

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?

ksmadsen avatar Dec 22 '16 10:12 ksmadsen

You're free to fork, repair, and submit a PR.

sanko avatar Dec 22 '16 15:12 sanko

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.

offsides avatar Dec 03 '21 21:12 offsides

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?

offsides avatar Dec 03 '21 22:12 offsides

Pull requests with tests welcome.

sanko avatar Dec 04 '21 06:12 sanko