http://www.perlmonks.org?node_id=265034


in reply to (jeffa) Re: OO style question: how much information to hide?
in thread OO style question: how much information to hide?

Hear, hear. Simple interfaces should ascribe to the Perl philosophy of DWIM. If a sensible user would say, "well, duh, of course I can't delete attrs from end tags, because they don't have any," then the module should just shield the user from this aggravation. Check for end-tags inside the appropriate *_attr calls and return undef.

Since there's no data loss in deleting what's never there (and could never be there), just ignore it. I'd say the same thing of attaching data to things which can't accept attachments (attrs on end tags), though I might suggest that such a call return undef on failure and non-undef on success. The quietest possible error.

If the user chooses a lint/debugging mode for the object or package, then you could carp a warning. But simple interfaces should say "no harm, no foul" to irrelevant calls.

--
[ e d @ h a l l e y . c c ]