From: Chris W. <ch...@cw...> - 2004-01-22 22:34:07
|
On Jan 22, 2004, at 5:19 PM, Vsevolod (Simon) Ilyushchenko wrote: > A minor annoyance - the generated mutator methods do not assign the > undef value to attributes. Sometimes it's a desired behavior. It would > be cool if this could be turned on or off via a configuration option. I actually did think of this one -- in the docs for SPOPS.pm is the following: ---------- You should use the hash interface to get and set values in your object -- it is easier. However, SPOPS will also create an accessor/mutator/clearing-mutator for you on demand -- just call a method with the same name as one of your properties and two methods ('${fieldname}' and '${fieldname}_clear') will be created. Similar to other libraries in Perl (e.g., L<Class::Accessor|Class::Accessor>) the accessor and mutator share a method, with the mutator only being used if you pass a defined value as the second argument: ... # This won't do what you want (clear the field value)... $object->fieldname( undef ); # ... but this will $object->fieldname_clear; ---------- So you should be able to call $object->foo_clear and assign 'foo' undef. Chris -- Chris Winters Creating enterprise-capable snack systems since 1988 |