File Coverage

blib/lib/HTML/FormFu/Role/Filter/Compound.pm
Criterion Covered Total %
statement 22 22 100.0
branch 5 6 83.3
condition n/a
subroutine 3 3 100.0
pod n/a
total 30 31 96.7


line stmt bran cond sub pod time code
1 8     8   4540 use strict;
  8         21  
  8         601  
2              
3             package HTML::FormFu::Role::Filter::Compound;
4             $HTML::FormFu::Role::Filter::Compound::VERSION = '2.07';
5             # ABSTRACT: Role for Compound filters
6              
7 8     8   53 use Moose::Role;
  8         18  
  8         81  
8              
9             has field_order => ( is => 'rw', traits => ['Chained'] );
10              
11             sub _get_values {
12 7     7   28 my ( $self, $value ) = @_;
13              
14 7         22 my ( $multi, @fields ) = @{ $self->parent->get_fields };
  7         28  
15              
16 7 100       260 if ( my $order = $self->field_order ) {
17 2         4 my @new_order;
18              
19             FIELD:
20 2         7 for my $i (@$order) {
21 5         7 for my $field (@fields) {
22 9 100       24 if ( $field->name eq $i ) {
23 5         10 push @new_order, $field;
24 5         15 next FIELD;
25             }
26             }
27             }
28              
29 2         6 @fields = @new_order;
30             }
31              
32 7         24 my @names = map { $_->name } @fields;
  17         47  
33              
34 7 50       30 return map { defined $_ ? $_ : '' } @{$value}{@names};
  17         64  
  7         27  
35             }
36              
37             1;
38              
39             __END__
40              
41             =pod
42              
43             =encoding UTF-8
44              
45             =head1 NAME
46              
47             HTML::FormFu::Role::Filter::Compound - Role for Compound filters
48              
49             =head1 VERSION
50              
51             version 2.07
52              
53             =head1 METHODS
54              
55             =head2 field_order
56              
57             Arguments: \@order
58              
59             If the submitted parts should be joined in an order different than that of the
60             order of the fields, you must provide an arrayref containing the names, in the
61             order they should be joined.
62              
63             ---
64             element:
65             - type: Multi
66             name: address
67              
68             elements:
69             - name: street
70             - name: number
71              
72             filter:
73             - type: CompoundJoin
74             field_order:
75             - number
76             - street
77              
78             =head1 AUTHOR
79              
80             Carl Franks, C<cfranks@cpan.org>
81              
82             =head1 LICENSE
83              
84             This library is free software, you can redistribute it and/or modify it under
85             the same terms as Perl itself.
86              
87             =head1 AUTHOR
88              
89             Carl Franks <cpan@fireartist.com>
90              
91             =head1 COPYRIGHT AND LICENSE
92              
93             This software is copyright (c) 2018 by Carl Franks.
94              
95             This is free software; you can redistribute it and/or modify it under
96             the same terms as the Perl 5 programming language system itself.
97              
98             =cut