1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
use strict;
package HTML::FormFu::Exception::Input;
# ABSTRACT: Input exception
$HTML::FormFu::Exception::Input::VERSION = '2.07';
use Moose;
use MooseX::Attribute::Chained;
extends 'HTML::FormFu::Exception';
use HTML::FormFu::Attribute qw( mk_attrs );
use HTML::FormFu::Util qw( append_xml_attribute literal xml_escape _merge_hashes );
has processor => ( is => 'rw', traits => ['Chained'] );
has forced => ( is => 'rw', traits => ['Chained'] );
__PACKAGE__->mk_attrs(qw( attributes ));
sub BUILD {
my ( $self, $args ) = @_;
$self->attributes( {} );
return;
}
sub name {
my ($self) = @_;
return $self->parent->name;
}
sub message {
my ( $self, $message ) = @_;
if ( @_ > 1 ) {
return $self->{message} = $message;
}
return $self->{message} if defined $self->{message};
return $self->processor->message if defined $self->processor->message;
my %string = (
f => defined $self->form->id ? $self->form->id : '',
n => defined $self->name ? $self->name : '',
t => defined $self->type ? lc( $self->type ) : '',
s => $self->stage,
);
$string{t} =~ s/::/_/g;
$string{t} =~ s/\+//;
my $error_message = $self->parent->auto_error_message;
$error_message =~ s/%([fnts])/$string{$1}/g;
$error_message = $self->form->localize( $error_message,
$self->processor->localize_args );
return $self->{message} = $error_message;
}
sub type {
my ($self) = @_;
return $self->processor->type;
}
sub clone {
my ($self) = @_;
my %new = %$self;
return bless \%new, ref $self;
}
around render_data_non_recursive => sub {
my ( $orig, $self, $args ) = @_;
my $render = $self->$orig(
{ processor => $self->processor,
forced => $self->forced,
name => $self->name,
message => $self->message,
type => $self->type,
$args ? %$args : (),
} );
$self->_render_attributes($render);
return $render;
};
sub _render_attributes {
my ( $self, $render ) = @_;
my $attrs = xml_escape(
$self->parent->error_attributes,
$self->attributes,
);
my $auto_error_class = $self->parent->auto_error_class;
if ( defined $auto_error_class ) {
my %string = (
f => defined $self->form->id ? $self->form->id : '',
n => defined $self->name ? $self->name : '',
t => defined $self->type ? lc( $self->type ) : '',
s => $self->stage,
);
$string{t} =~ s/::/_/g;
$string{t} =~ s/\+//;
$auto_error_class =~ s/%([fnts])/$string{$1}/g;
append_xml_attribute( $attrs, 'class', $auto_error_class );
}
$render->{attributes} = $attrs;
}
__PACKAGE__->meta->make_immutable;
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
HTML::FormFu::Exception::Input - Input exception
=head1 VERSION
version 2.07
=head1 AUTHOR
Carl Franks <cpan@fireartist.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2018 by Carl Franks.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|