Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Storable CPAN distribution.

Report information
The Basics
Id: 48320
Status: rejected
Priority: 0/
Queue: Storable

People
Owner: Nobody in particular
Requestors: STBEY [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 2.20
Fixed in: (no value)



Subject: STORABLE_thaw hook breaks encapsulation of OO Modules (e.g. Bit::Vector)
Download (untitled) / with headers
text/plain 891b
By proving a generic constructor for blessed objects, the STORABLE_thaw hook breaks the encapsulation of OO modules, some of which use a proprietary constructor for a good reason. For instance Bit::Vector creates objects outside of the Perl-managed memory space, and therefore needs a special constructor of its own. The "fake" Bit::Vector object created by STORABLE_thaw is then very hard to turn into a "real" Bit::Vector object (requires an ugly workaround). If - as suggested in http://rt.cpan.org/Public/Bug/Display.html?id=6641 - Storable would return whatever STORABLE_thaw returns, and only would return the generically created blessed object if STORABLE_thaw returned nothing, this would probably not break existing code (or at least necessitate only a short one-liner to correct, in each module affected), and would solve the problem for modules with a non-standard constructor.
Subject: Vector.pm
Download Vector.pm
text/x-perl 1.5k
############################################################################### ## ## ## Copyright (c) 1995 - 2009 by Steffen Beyer. ## ## All rights reserved. ## ## ## ## This package is free software; you can redistribute it ## ## and/or modify it under the same terms as Perl itself. ## ## ## ############################################################################### package Bit::Vector; use strict; use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION @CONFIG); require Exporter; require DynaLoader; @ISA = qw(Exporter DynaLoader); @EXPORT = qw(); @EXPORT_OK = qw(); $VERSION = '6.6'; bootstrap Bit::Vector $VERSION; sub STORABLE_freeze { my($self, $cloning) = @_; return( Storable::freeze( [ $self->Size(), $self->Block_Read() ] ) ); } sub STORABLE_thaw { my($self, $cloning, $string) = @_; my($size,$buffer) = @{ Storable::thaw($string) }; $self->Unfake($size); # Undocumented new feature (slightly dangerous!) only for @%$&*# Storable! (Grrr) $self->Block_Store($buffer); } # Why can't Storable just use a module's constructor and provides one of its own instead?!?! # This breaks the encapsulation of other modules which have their own constructor for a good reason! 1; __END__
Download (untitled) / with headers
text/plain 613b
The broken encapsulation is necessary to support circular references (and thus the full richness of arbitrary data structures) then you should be using STORABLE_attach instead of STORABLE_thaw. STORABLE_attach was created for exactly your use case, specialised objects (file handles, database handles, singletons, chunks of C-stuff, and other magic things). In return for giving up certain capabilities on the freeze size (which I think is tolerable in your case) you can rebuild your object any way you like. Flagging as rejected, please reply to reopen this bug if STORABLE_attach does not do what you need.
OK, apparently I lack permissions to flag as rejected. Can someone with permission please do it.
Rejecting on behalf of Adam.
Download (untitled) / with headers
text/plain 883b
On Thu Aug 06 01:21:26 2009, ADAMK wrote: Show quoted text
> The broken encapsulation is necessary to support circular references > (and thus the full richness of arbitrary data structures) then you > should be using STORABLE_attach instead of STORABLE_thaw. > > STORABLE_attach was created for exactly your use case, specialised > objects (file handles, database handles, singletons, chunks of > C-stuff, and other magic things). > > In return for giving up certain capabilities on the freeze size > (which I think is tolerable in your case) you can rebuild your > object any way you like. > > Flagging as rejected, please reply to reopen this bug if > STORABLE_attach does not do what you need.
Ok, thanks a lot for this info! Are there any code snippets as an example of how to actually use STORABLE_attach? The man page is rather scarce on this matter. Thanks a lot again! Cheers, Steffen
Download (untitled) / with headers
text/plain 613b
On Fri Aug 07 17:00:30 2009, STBEY wrote: Show quoted text
> Are there any code snippets as an example of how to actually use > STORABLE_attach? The man page is rather scarce on this matter. > Thanks a lot! > Cheers, Steffen
Never mind the code snippets, friendly Google did the trick! However, I still think the manpage would benefit from a short example, such as maybe: sub STORABLE_attach { my($class, $clone, $string) = @_; my $self = { $string => $string }; # do something more useful here return bless( $self, $class ); } In either case thanks a lot for a very nice and useful module! Best regards, Steffen


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.