in reply to (jeffa) Re: is this a perversion of OO principles?
in thread is this a perversion of OO principles?

Thanks for the feedback... and just to clarify, when it comes to tailoring errors I am not actually adding code within the MessageLibrary class itself, but specifying it in the object constructors, something like this:

my $error_messages = MessageLibrary->new({ file_open_error => sub{"Couldn't open $_[0]: $!"}, bad_token => sub{"Invalid token $_[0] encountered on line $_[1]"}, bad_file_format => "Invalid file format", }); my $status_messages = MessageLibrary->new({ starting_parse_phase => "Starting parser...", generating_results => sub {"Generating results for element $_[0]"}, });
So basically the only stuff in the class package is just a constructor, an AUTOLOAD method, and a couple of little utility methods.

Update: While rereading this response, I realized there was an aspect of jeffa's point about not having to tailor error messages that I only partially answered. Although you can define error messages in the object constructor, the object also provides default handling for any method you might call. So you could do this: print $status_messages->undefined_msg($a_param, $another); and get a reasonable result. (You can also override this default behavior in the object constructor.)