[Pharo-users] How to intercept instvar write - MetaLinks + anonymous subclass problem

Steven Costiou steven.costiou at kloum.io
Sat Feb 2 13:01:32 EST 2019

> Le 2019-02-02 16:26, Petr Fischer via Pharo-users a écrit : 
> Thanks for answer! I want to detect instvar writes only for objects (instances), that was previously fetched from external "datastore" (DB like), so I can persist changed objects only back to the datastore at the end of transaction. These objects can be any existing class (Pharo classes, some 3rd party libs classes, everything), so 1) injecting a class is overkill (affects all objects in the image) 2) impossible to rewrite #class method for every existing class.
> Injecting object-centric metalinks via anonymous subclass breaks up many things, when I want to treat injected object like any othres (IMHO).
> If you will be able to avoid this issue, that would be extra cool :-]
> Note: for now, best for my "instvar writes detection" would be probably hack Object>>#attemptToAssign:withIndex: or ProtoObject>>#modificationForbiddenFor:index:value: and make my "datastore fetched objects" read only (via Object>>#setIsReadOnlyObject.
> pf

I will look into that yes, however object-centric metalinks are not
really meant to affect all instnces, only specific ones. That is more
the purpose of "standard" metalinks. 

Could standard metalinks not work? Since in any case you have to have
your hand on those objects, so instead of putting an object-centric
metalink you could ask for the class and install a normal metalink on
write access there, which would affect all instances of that class. You
would also have to keep some kind of record of which class you
instrumented, so you do not install the link multiple times. 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-users_lists.pharo.org/attachments/20190202/75465981/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smiley-smile.gif
Type: image/gif
Size: 344 bytes
Desc: not available
URL: <http://lists.pharo.org/pipermail/pharo-users_lists.pharo.org/attachments/20190202/75465981/attachment.gif>

More information about the Pharo-users mailing list