File Coverage

blib/lib/Form/Factory/Message.pm
Criterion Covered Total %
statement 9 13 69.2
branch 0 2 0.0
condition n/a
subroutine 3 4 75.0
pod 1 1 100.0
total 13 20 65.0


line stmt bran cond sub pod time code
1             package Form::Factory::Message;
2             $Form::Factory::Message::VERSION = '0.022';
3 1     1   4 use Moose;
  1         1  
  1         6  
4              
5 1     1   4512 use Moose::Util::TypeConstraints;
  1         1  
  1         8  
6             enum 'Form::Factory::Message::Type' => [qw( info warning error )];
7 1     1   1429 no Moose::Util::TypeConstraints;
  1         1  
  1         4  
8              
9             # ABSTRACT: Handy class for encapsulating messages
10              
11              
12             has field => (
13             is => 'rw',
14             isa => 'Str',
15             predicate => 'is_tied_to_field',
16             );
17              
18              
19             has message => (
20             is => 'rw',
21             isa => 'Str',
22             required => 1,
23             );
24              
25              
26             has type => (
27             is => 'rw',
28             isa => 'Form::Factory::Message::Type',
29             required => 1,
30             default => 'info',
31             );
32              
33              
34             sub english_message {
35 0     0 1   my $self = shift;
36 0           my $message = ucfirst $self->message;
37 0 0         $message .= '.' if $message =~ /(?:[\w\s])$/;
38 0           return $message;
39             }
40              
41             __PACKAGE__->meta->make_immutable;
42              
43             __END__
44              
45             =pod
46              
47             =encoding UTF-8
48              
49             =head1 NAME
50              
51             Form::Factory::Message - Handy class for encapsulating messages
52              
53             =head1 VERSION
54              
55             version 0.022
56              
57             =head1 SYNOPSIS
58              
59             my $message = Form::Factory::Message->new(
60             field => 'foo',
61             type => 'warning',
62             message => 'Blah blah blah',
63             );
64              
65             if ($message->type eq 'warning' or $message->type eq 'error') {
66             print uc($message->type);
67             }
68              
69             if ($message->is_tied_to_field) {
70             print $message->field, ": ", $message->message, "\n";
71             }
72              
73             =head1 DESCRIPTION
74              
75             This is used to store messages that describe the outcome of the various parts of the action workflow.
76              
77             =head1 ATTRIBUTES
78              
79             =head2 field
80              
81             This is the name of the field the message belongs with. If set the C<is_tied_to_field> predicate will return true.
82              
83             =head2 message
84              
85             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.
86              
87             =head2 type
88              
89             This is the type of message. Must be one of: info, warning, or error.
90              
91             =head1 METHODS
92              
93             =head2 english_message
94              
95             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.
96              
97             =head1 AUTHOR
98              
99             Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
100              
101             =head1 COPYRIGHT AND LICENSE
102              
103             This software is copyright (c) 2015 by Qubling Software LLC.
104              
105             This is free software; you can redistribute it and/or modify it under
106             the same terms as the Perl 5 programming language system itself.
107              
108             =cut