Error Messages

package Your::Point;
use base 'Badger::Base';

our $THROWS   = 'point';
our $MESSAGES = {
    missing => 'No value specified for %s',
};

sub init {
    my ($self, $config) = @_;

    $self->{ x } = 
      defined $config->{ x }
            ? $config->{ x }
            : $self->error_msg( missing => 'x' );

    # ...same for y...

    return $self;
}
Thus Spake Andy:

Instead of dotting long and complication error messages all over your module (more detailed errors are better, right?), you can stuff message formats (like sprintf()) in a $MESSAGES hash and use the error_msg() method. The first argument is the format name. Remaining arguments are used to populate the message format.