Form::Factory::Message - Handy class for encapsulating messages


Form-Factory documentation Contained in the Form-Factory distribution.

Index


Code Index:

NAME

Top

Form::Factory::Message - Handy class for encapsulating messages

VERSION

Top

version 0.020

SYNOPSIS

Top

  my $message = Form::Factory::Message->new(
      field   => 'foo',
      type    => 'warning',
      message => 'Blah blah blah',
  );

  if ($message->type eq 'warning' or $message->type eq 'error') {
      print uc($message->type);
  }

  if ($message->is_tied_to_field) {
      print $message->field, ": ", $message->message, "\n";
  }

DESCRIPTION

Top

This is used to store messages that describe the outcome of the various parts of the action workflow.

ATTRIBUTES

Top

field

This is the name of the field the message belongs with. If set the is_tied_to_field predicate will return true.

message

This is the message itself. By convention, the message is expected to be formatted with the initial caps left off and no ending punctuation. This allows it to be more easily formatted or embedded into larger error messages, if necessary.

type

This is the type of message. Must be one of: info, warning, or error.

METHODS

Top

english_message

This capitalizes the first character of the message and adds a period at the end of the last character is a word or space character.

AUTHOR

Top

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

Top


Form-Factory documentation Contained in the Form-Factory distribution.
package Form::Factory::Message;
BEGIN {
  $Form::Factory::Message::VERSION = '0.020';
}
use Moose;

use Moose::Util::TypeConstraints;
enum 'Form::Factory::Message::Type' => qw( info warning error );
no Moose::Util::TypeConstraints;

has field => (
    is       => 'rw',
    isa      => 'Str',
    predicate => 'is_tied_to_field',
);

has message => (
    is       => 'rw',
    isa      => 'Str',
    required => 1,
);

has type => (
    is       => 'rw',
    isa      => 'Form::Factory::Message::Type',
    required => 1,
    default  => 'info',
);

sub english_message {
    my $self = shift;
    my $message = ucfirst $self->message;
    $message .= '.' if $message =~ /(?:[\w\s])$/;
    return $message;
}

1;