Re: [CDBI] Inflating/deflating with Storable

[prev] [thread] [next] [Date index for 2006/02/21]

From: Marius Feraru
Subject: Re: [CDBI] Inflating/deflating with Storable
Date: 01:20 on 21 Feb 2006
This is a cryptographically signed message in MIME format.

--===============1685699023==
Content-Type: multipart/signed; protocol="application/x-pkcs7-signature";
	micalg=sha1; boundary="------------ms080503070700000501060206"

This is a cryptographically signed message in MIME format.

--------------ms080503070700000501060206
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dan Lenski wrote:
> The problem is that the output of the freeze() function is simply a
> string, and the output of thaw() can have pretty much any type at all.
>  Class::DBI::Relationship::HasA doesn't like this state of affairs
> since it expects a specific class.
> 
> First, I tried this:
> 
> __PACKAGE__->has_a(udata => 'UNIVERSAL', inflate => sub { freeze
> \shift }, deflate => sub { my $d=shift; $d and ${thaw $d} });
> 
> This doesn't work, it complains about "unable to find new method for
> UNIVERSAL class".  Plus, it won't work at all if the inflated item
> happens not to be a blessed reference :-(

1) thaw/freeze - inflate/deflate, that's the right process ;-)
2) forgot to bless the inflated reference:

__PACKAGE__->has_a(
    udata   => 'MyFridge',
    inflate => sub { bless thaw(shift), 'MyFridge' },
    deflate => sub { freeze(shift) }
);

now you have it...

> So, next I tried making a stupid little wrapper class
... so I agree on its quality (err, usefulness?) ;-)

> Now, I can access the data via $obj->udata->data
$obj->udata is enough now.

> but when I modify the data with the accessor, Class::DBI doesn't
> realize it has changed and won't actually update the database :-(
If you mean something like

  $obj->udata->{foo} = 'bar';

then remember the "udata" just provides access to that _reference_
(which will not be noticed by CDBI whenever you modify something "inside").

Else, if you meant (which you should've):

  $obj->udata({foo => 'bar'});

you should add a trigger to take care of preparing your data, as
(obviously) CDBI expects your data to be already inflated upon "set":

__PACKAGE__->add_trigger(before_set_udata => sub {
    my ($self, $value) = @_;
    if (!defined $value || !ref $value) {
        $self->_croak('I only work with data references!');
    }
    if (!blessed($value) || ref $value ne 'MyFridge') {
        my $blessed_value = bless $value, 'MyFridge';
        $self->_attribute_store({ udata => $blessed_value });
    }
});

("blessed" is in Scalar::Util - core module)

cheers
- --
Marius Feraru
-----BEGIN PGP SIGNATURE-----

iD8DBQFD+mrMtZHp/AYZiNkRAk6EAJ9x4mlycvtDuppybO08kEVTNqY2dQCfdHbz
tNsppv0rEakBSc9SIb3yGD0=
=66xz
-----END PGP SIGNATURE-----

--------------ms080503070700000501060206
Content-Type: application/x-pkcs7-signature; name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"
Content-Description: S/MIME Cryptographic Signature

MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIII4TCC
AsswggI0oAMCAQICAw+1MzANBgkqhkiG9w0BAQQFADBiMQswCQYDVQQGEwJaQTElMCMGA1UE
ChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0eSkgTHRkLjEsMCoGA1UEAxMjVGhhd3RlIFBlcnNv
bmFsIEZyZWVtYWlsIElzc3VpbmcgQ0EwHhcNMDUxMDIwMTE1NjAxWhcNMDYxMDIwMTE1NjAx
WjBBMR8wHQYDVQQDExZUaGF3dGUgRnJlZW1haWwgTWVtYmVyMR4wHAYJKoZIhvcNAQkBFg9h
bHRibHVlQG4waS5uZXQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDO/J6A4U8P
T0IC1dji+zdzE9pIw9Wy2JC0dN0kS92KOQuRtmWKVdbyi5XJiZH8QgySY88NwQHNVHC3ieRY
aahE5+SbS76nVqX6wAfa7Pv0NRsEF/IZeHC2nXBM6NFDrpyQUNmbQuHCwkw+Hms5A05y4nmC
RMroZ542/IDnb3sC2TEwsAI2IqfK6UVnFna7sTt8+3XxhGKcuL7VrHggc6RZvkC1FIuW5odZ
Zx58pTPMyaHXbUMVIxYE1ZiN1gCK6uzk4XLz4MjrDL8rq1QxEsWhZJkUErdeY2nDzLpeEAl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cgQ0ECAw+1MzANBgkqhkiG9w0BAQEFAASCAQCJ3nuZaIX6CQwlXId854aR
+iAWO9AxXR3AZfH7XeFCsBDzr6SxDhUmaxpJ+lxB96+l9VIghhK0y5RyIA5CKaVQqzKpHjlX
VGkZuZtX6I7laOnJ6k+/KY5V/uY3U/j6kXZQqDRalt+c2V4jMLkt+34ze8Gmp2g17gg+vC4i
IbtCexCVR4OVqvLhQUR1r2PL72eFkxQOm6vVFLqTnsBHbK+MhENU1rebeWrblcBkUhwOzqQB
j2ihXLe5ZnZPuqIp4HlfhlZLH5esJmVwKd/Vb9YqRw59uiSC1cBYz1JQ9TAd0kP9g/OPeWdn
kvAhovZ17/wJfzFSBdpHVBH8E3WgG3ckAAAAAAAA
--------------ms080503070700000501060206--


--===============1685699023==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

--===============1685699023==--

[CDBI] Inflating/deflating with Storable
Dan Lenski 08:11 on 17 Feb 2006

[CDBI] Re: Inflating/deflating with Storable
Edward J. Sabol 23:02 on 17 Feb 2006

Re: [CDBI] Inflating/deflating with Storable
Marius Feraru 01:20 on 21 Feb 2006

Generated at 12:31 on 28 Feb 2006 by mariachi v0.52