I'd do it something like this in Lisp (not very tested):
(defclass sum ()
((a :accessor a :initarg :a :initform 0)
(b :accessor b :initarg :b :initform 0)
(c :reader c)))
(defmethod compute ((self sum))
(setf (slot-value self 'c) (+ (a self) (b self))))
(defmethod initialize-instance :after ((self sum) &key &allow-other-ke
+ys)
(compute self))
(defmethod (setf a) :after (val (self sum))
(declare (ignore val))
(compute self))
(defmethod (setf b) :after (val (self sum))
(declare (ignore val))
(compute self))
Content of marginal relevance to Perl: Maybe there's something out there that implements something akin to Lisp's :after methods in Perl that would do what you want. I don't know, though.