package HTML::FormFu::Filter::CompoundSprintf;
use strict;
use base 'HTML::FormFu::Filter::_Compound';
use Carp qw( croak );
__PACKAGE__->mk_accessors(qw/ sprintf /);
sub filter {
my ( $self, $value ) = @_;
return unless defined $value && $value ne "";
my $sprintf = $self->sprintf;
croak 'sprintf pattern required' if !defined $sprintf;
my @values = $self->_get_values($value);
$value = CORE::sprintf( $sprintf, @values );
return $value;
}
1;
__END__
=head1 NAME
HTML::FormFu::Filter::CompoundSprintf - CompoundSprintf filter
=head1 SYNOPSIS
---
element:
- type: Multi
name: date
elements:
- name: day
- name: month
- name: year
filter:
- type: CompoundSprintf
sprintf: '%02d-%02d-%04d'
# get the compound-value
my $date = $form->param_value('date');
=head1 DESCRIPTION
For use with a L group of fields.
Uses a sprintf pattern to join the input from several fields into a single
value.
=head1 METHODS
=head2 sprintf
Arguments: $string
C pattern used to join the individually submitted parts.
The pattern is passed to the perl-core C function.
=head2 field_order
Inherited. See L for details.
---
element:
- type: Multi
name: date
elements:
- name: month
- name: day
- name year
filter:
- type: CompoundSprintf
field_order:
- day
- month
- year
=head1 AUTHOR
Carl Franks, C
=head1 LICENSE
This library is free software, you can redistribute it and/or modify it under
the same terms as Perl itself.
=cut