logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Role::HasMessage::Errf - a thing with a String::Errf-powered message

Author

       Ricardo Signes <cpan@semiotic.systems>

Description

       Role::HasMessage::Errf is an implementation of Role::HasMessage that uses String::Errf to format
       "sprintf"-like message strings.  It adds a "message_fmt" attribute, initialized by the "message"
       argument.  The value should be a String::Errf format string.

       When the provided "message" method is called, it will fill in the format string with the hashref returned
       by calling the "payload" method, which mustbeimplementedbytheincludingclass.

       Role::HasMessage::Errf is a parameterized role.  The "default" parameter lets you set a default format
       string or callback.  The "lazy" parameter sets whether or not the "message_fmt" attribute is lazy.
       Setting it lazy will require that a default is provided.

Name

       Role::HasMessage::Errf - a thing with a String::Errf-powered message

Perl Version

       This library should run on perls released even a long time ago.  It should work on any version of perl
       released in the last five years.

       Although it may work on older versions of perl, no guarantee is made that the minimum required version
       will not be increased.  The version may be increased for any reason, and there is no promise that patches
       will be accepted to lower the minimum required perl.

Synopsis

       In your class...

         package Errfy;
         use Moose;

         with 'Role::HasMessage::Errf';

         has payload => (
           is  => 'ro',
           isa => 'HashRef',
           required => 1,
         );

       Then...

         my $thing = Errfy->new({
           message => "%{error_count;error}n encountered at %{when}t",
           payload => {
             error_count => 2,
             when        => time,
           },
         });

         # prints: 2 errors encountered at 2010-10-20 19:23:42
         print $thing->message;

Version

       version 0.007

See Also