Debian Codegraph @

lib/HTML/FormHandler/Widget/Theme/BootstrapFormMessages.pm

raw
1 package HTML::FormHandler::Widget::Theme::BootstrapFormMessages;
2 # ABSTRACT: role to render form messages using Bootstrap styling
3 $HTML::FormHandler::Widget::Theme::BootstrapFormMessages::VERSION = '0.410002';
4 use Moose::Role;
5 use HTML::Entities qw( encode_entities );
6
7
8 sub render_form_messages {
9 my ( $self, $result ) = @_;
10
11 return '' if $self->get_tag('no_form_message_div');
12
13 $result ||= $self->result;
14 my $output = '';
15 if ( $result->has_form_errors || $result->has_errors ) {
16 my $alert_error_class = $self->form_messages_alert_error_class;
17 $output = qq{\n<div class="alert $alert_error_class">};
18 my $msg = $self->error_message;
19 $msg ||= 'There were errors in your form';
20 $msg = encode_entities($self->_localize($msg));
21 $output .= qq{\n<span class="error_message">$msg</span>};
22 $output .= qq{\n<span class="error_message">$_</span>}
23 for map { encode_entities($_) } $result->all_form_errors;
24 $output .= "\n</div>";
25 }
26 elsif ( $result->validated ) {
27 my $msg = $self->success_message;
28 $msg ||= "Your form was successfully submitted";
29 $msg = encode_entities($self->_localize($msg));
30 $output = qq{\n<div class="alert alert-success">};
31 $output .= qq{\n<span>$msg</span>};
32 $output .= "\n</div>";
33 }
34 if ( $self->has_info_message && $self->info_message ) {
35 my $msg = $self->info_message;
36 $msg = encode_entities($self->_localize($msg));
37 $output = qq{\n<div class="alert alert-info">};
38 $output .= qq{\n<span>$msg</span>};
39 $output .= "\n</div>";
40 }
41 return $output;
42 }
43
44 sub form_messages_alert_error_class { 'alert-error' }
45
46 1;
47
48 __END__
49
50 =pod
51
52 =encoding UTF-8
53
54 =head1 NAME
55
56 HTML::FormHandler::Widget::Theme::BootstrapFormMessages - role to render form messages using Bootstrap styling
57
58 =head1 VERSION
59
60 version 0.410002
61
62 =head1 DESCRIPTION
63
64 Role to render form messages using Bootstrap styling.
65
66 =head1 NAME
67
68 HTML::FormHandler::Widget::Theme::BootstrapFormMessages
69
70 =head1 AUTHOR
71
72 FormHandler Contributors - see HTML::FormHandler
73
74 =head1 COPYRIGHT AND LICENSE
75
76 This software is copyright (c) 2017 by Gerda Shank.
77
78 This is free software; you can redistribute it and/or modify it under
79 the same terms as the Perl 5 programming language system itself.
80
81 =cut