| 1 | 51 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | |||||||||||
| 3 | package HTML::FormFu::Element::Multi; | ||||||||||
| 4 | 51 | $HTML::FormFu::Element::Multi::VERSION = '2.06'; | |||||||||
| 5 | # ABSTRACT: Combine multiple fields in a single element | ||||||||||
| 6 | |||||||||||
| 7 | 51 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 51 | ▶ | use MooseX::Attribute::Chained; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 51 | extends 'HTML::FormFu::Element::Block'; | |||||||||
| 10 | |||||||||||
| 11 | 51 | with | |||||||||
| 12 | 'HTML::FormFu::Role::Element::Field', | ||||||||||
| 13 | 'HTML::FormFu::Role::Element::SingleValueField'; | ||||||||||
| 14 | |||||||||||
| 15 | use HTML::FormFu::Util | ||||||||||
| 16 | 51 | ▶ | qw( append_xml_attribute xml_escape process_attrs _parse_args _get_elements _filter_components ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 51 | ▶ | use Clone (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | after BUILD => sub { | ||||||||||
| 20 | 108 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 21 | |||||||||||
| 22 | 108 | $self->comment_attributes( {} ); | |||||||||
| 23 | 108 | $self->container_attributes( {} ); | |||||||||
| 24 | 108 | $self->label_attributes( {} ); | |||||||||
| 25 | 108 | $self->layout_field_filename('field_layout_multi_field'); | |||||||||
| 26 | 108 | $self->label_tag('label'); | |||||||||
| 27 | |||||||||||
| 28 | 108 | return; | |||||||||
| 29 | 51 | }; | |||||||||
| 30 | |||||||||||
| 31 | sub get_fields { | ||||||||||
| 32 | 596 | ▶ | my $self = shift; | ||||||||
|
Subroutine
get_fields: called CC=1 SCAR=0.0
| |||||||||||
| 33 | 596 | my %args = _parse_args(@_); | |||||||||
| 34 | |||||||||||
| 35 | 596 | my $f = $self->SUPER::get_fields(@_); | |||||||||
| 36 | |||||||||||
| 37 | 596 | unshift @$f, $self; | |||||||||
| 38 | |||||||||||
| 39 | 596 | return _get_elements( \%args, $f ); | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | sub get_deflators { | ||||||||||
| 43 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
get_deflators: not called CC=1 SCAR=6.9
| |||||||||||
| 44 | 0 | my %args = _parse_args(@_); | |||||||||
| 45 | |||||||||||
| 46 | 0 | my @x = @{ $self->_deflators }; | |||||||||
| 47 | |||||||||||
| 48 | 0 | push @x, map { @{ $_->get_deflators(@_) } } @{ $self->_elements }; | |||||||||
| 49 | |||||||||||
| 50 | 0 | return _filter_components( \%args, \@x ); | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | sub get_filters { | ||||||||||
| 54 | 12 | ▶ | my $self = shift; | ||||||||
|
Subroutine
get_filters: called CC=1 SCAR=0.0
| |||||||||||
| 55 | 12 | my %args = _parse_args(@_); | |||||||||
| 56 | |||||||||||
| 57 | 12 | my @x = @{ $self->_filters }; | |||||||||
| 58 | |||||||||||
| 59 | 12 | push @x, map { @{ $_->get_filters(@_) } } @{ $self->_elements }; | |||||||||
| 60 | |||||||||||
| 61 | 12 | return _filter_components( \%args, \@x ); | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | sub get_constraints { | ||||||||||
| 65 | 12 | ▶ | my $self = shift; | ||||||||
|
Subroutine
get_constraints: called CC=1 SCAR=0.0
| |||||||||||
| 66 | 12 | my %args = _parse_args(@_); | |||||||||
| 67 | |||||||||||
| 68 | 12 | my @x = @{ $self->_constraints }; | |||||||||
| 69 | |||||||||||
| 70 | 12 | push @x, map { @{ $_->get_constraints(@_) } } @{ $self->_elements }; | |||||||||
| 71 | |||||||||||
| 72 | 12 | return _filter_components( \%args, \@x ); | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | sub get_inflators { | ||||||||||
| 76 | 11 | ▶ | my $self = shift; | ||||||||
|
Subroutine
get_inflators: called CC=1 SCAR=0.0
| |||||||||||
| 77 | 11 | my %args = _parse_args(@_); | |||||||||
| 78 | |||||||||||
| 79 | 11 | my @x = @{ $self->_inflators }; | |||||||||
| 80 | |||||||||||
| 81 | 11 | push @x, map { @{ $_->get_inflators(@_) } } @{ $self->_elements }; | |||||||||
| 82 | |||||||||||
| 83 | 11 | return _filter_components( \%args, \@x ); | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | sub get_validators { | ||||||||||
| 87 | 11 | ▶ | my $self = shift; | ||||||||
|
Subroutine
get_validators: called CC=1 SCAR=0.0
| |||||||||||
| 88 | 11 | my %args = _parse_args(@_); | |||||||||
| 89 | |||||||||||
| 90 | 11 | my @x = @{ $self->_validators }; | |||||||||
| 91 | |||||||||||
| 92 | 11 | push @x, map { @{ $_->get_validators(@_) } } @{ $self->_elements }; | |||||||||
| 93 | |||||||||||
| 94 | 11 | return _filter_components( \%args, \@x ); | |||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | sub get_transformers { | ||||||||||
| 98 | 11 | ▶ | my $self = shift; | ||||||||
|
Subroutine
get_transformers: called CC=1 SCAR=0.0
| |||||||||||
| 99 | 11 | my %args = _parse_args(@_); | |||||||||
| 100 | |||||||||||
| 101 | 11 | my @x = @{ $self->_transformers }; | |||||||||
| 102 | |||||||||||
| 103 | 11 | push @x, map { @{ $_->get_transformers(@_) } } @{ $self->_elements }; | |||||||||
| 104 | |||||||||||
| 105 | 11 | return _filter_components( \%args, \@x ); | |||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | sub get_errors { | ||||||||||
| 109 | 317 | ▶ | my $self = shift; | ||||||||
|
Subroutine
get_errors: called CC=2 SCAR=6.9
| |||||||||||
| 110 | 317 | my %args = _parse_args(@_); | |||||||||
| 111 | |||||||||||
| 112 | 317 | my @x = @{ $self->_errors }; | |||||||||
| 113 | |||||||||||
| 114 | 317 | push @x, map { @{ $_->get_errors(@_) } } @{ $self->_elements }; | |||||||||
| 115 | |||||||||||
| 116 | 317 | _filter_components( \%args, \@x ); | |||||||||
| 117 | |||||||||||
| 118 | 317 | ▶ | if ( !$args{forced} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 119 | 230 | @x = grep { !$_->forced } @x; | |||||||||
| 120 | } | ||||||||||
| 121 | |||||||||||
| 122 | 317 | return \@x; | |||||||||
| 123 | } | ||||||||||
| 124 | |||||||||||
| 125 | sub clear_errors { | ||||||||||
| 126 | 82 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
clear_errors: called CC=1 SCAR=0.0
| |||||||||||
| 127 | |||||||||||
| 128 | 82 | $self->_errors( [] ); | |||||||||
| 129 | |||||||||||
| 130 | 82 | map { $_->clear_errors } @{ $self->_elements }; | |||||||||
| 131 | |||||||||||
| 132 | 82 | return; | |||||||||
| 133 | } | ||||||||||
| 134 | |||||||||||
| 135 | sub render_data { | ||||||||||
| 136 | 34 | ▶ | my $self = shift; | ||||||||
|
Subroutine
render_data: called CC=2 SCAR=7.0
| |||||||||||
| 137 | |||||||||||
| 138 | 34 | my $render = $self->SUPER::render_data(@_); | |||||||||
| 139 | |||||||||||
| 140 | 34 | ▶ | map { delete $_->{container_tag} } @{ $render->{elements} || [] }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 141 | |||||||||||
| 142 | 34 | return $render; | |||||||||
| 143 | } | ||||||||||
| 144 | |||||||||||
| 145 | sub render_data_non_recursive { | ||||||||||
| 146 | 87 | ▶ | my $self = shift; | ||||||||
|
Subroutine
render_data_non_recursive: called CC=1 SCAR=0.0
| |||||||||||
| 147 | |||||||||||
| 148 | 87 | my $render = $self->SUPER::render_data_non_recursive(@_); | |||||||||
| 149 | |||||||||||
| 150 | 87 | append_xml_attribute( $render->{attributes}, 'class', 'elements' ); | |||||||||
| 151 | |||||||||||
| 152 | 87 | return $render; | |||||||||
| 153 | } | ||||||||||
| 154 | |||||||||||
| 155 | sub _parse_layout_field { | ||||||||||
| 156 | 73 | ▶ | my ( $self, $render ) = @_; | ||||||||
|
Subroutine
_parse_layout_field: called CC=3 SCAR=11.0
| |||||||||||
| 157 | |||||||||||
| 158 | 73 | my @html = ( sprintf "<span%s>", process_attrs( $render->{attributes} ), ); | |||||||||
| 159 | |||||||||||
| 160 | 73 | for my $elem ( @{ $self->get_elements } ) { | |||||||||
| 161 | 218 | my $render = $elem->render_data; | |||||||||
| 162 | |||||||||||
| 163 | 218 | ▶ | next if !defined $render; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 164 | |||||||||||
| 165 | 217 | $render->{container_tag} = undef; | |||||||||
| 166 | |||||||||||
| 167 | 217 | push @html, | |||||||||
| 168 | $elem->string( | ||||||||||
| 169 | { render_data => $render, layout => $elem->multi_layout } ); | ||||||||||
| 170 | } | ||||||||||
| 171 | |||||||||||
| 172 | 73 | push @html, "</span>"; | |||||||||
| 173 | |||||||||||
| 174 | 73 | return join "\n", @html; | |||||||||
| 175 | } | ||||||||||
| 176 | |||||||||||
| 177 | sub clone { | ||||||||||
| 178 | 9 | ▶ | my $self = shift; | ||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
| |||||||||||
| 179 | |||||||||||
| 180 | 9 | my $clone = $self->SUPER::clone(@_); | |||||||||
| 181 | |||||||||||
| 182 | 9 | $clone->comment_attributes( Clone::clone( $self->comment_attributes ) ); | |||||||||
| 183 | 9 | $clone->container_attributes( Clone::clone( $self->container_attributes ) ); | |||||||||
| 184 | 9 | $clone->label_attributes( Clone::clone( $self->label_attributes ) ); | |||||||||
| 185 | |||||||||||
| 186 | 9 | return $clone; | |||||||||
| 187 | } | ||||||||||
| 188 | |||||||||||
| 189 | 51 | __PACKAGE__->meta->make_immutable; | |||||||||
| 190 | |||||||||||
| 191 | 51 | 1; | |||||||||
| 192 | |||||||||||
| 193 | __END__ | ||||||||||
| 194 | |||||||||||
| 195 | =pod | ||||||||||
| 196 | |||||||||||
| 197 | =encoding UTF-8 | ||||||||||
| 198 | |||||||||||
| 199 | =head1 NAME | ||||||||||
| 200 | |||||||||||
| 201 | HTML::FormFu::Element::Multi - Combine multiple fields in a single element | ||||||||||
| 202 | |||||||||||
| 203 | =head1 VERSION | ||||||||||
| 204 | |||||||||||
| 205 | version 2.06 | ||||||||||
| 206 | |||||||||||
| 207 | =head1 SYNOPSIS | ||||||||||
| 208 | |||||||||||
| 209 | my $e = $form->element( Multi => 'foo' ); | ||||||||||
| 210 | |||||||||||
| 211 | =head1 DESCRIPTION | ||||||||||
| 212 | |||||||||||
| 213 | Combine multiple form fields in a single logical element. | ||||||||||
| 214 | |||||||||||
| 215 | Non-field elements cannot be added as children of the Multi element. | ||||||||||
| 216 | |||||||||||
| 217 | =head1 RENDERING NOTES | ||||||||||
| 218 | |||||||||||
| 219 | If the Multi element is rendered with the default 'string' render-method, | ||||||||||
| 220 | all child fields will be rendered with the 'string' render-method, regardless | ||||||||||
| 221 | of their L<HTML::FormFu/render_method> value. | ||||||||||
| 222 | |||||||||||
| 223 | Likewise, if the Multi element is rendered with the 'tt' render-method, | ||||||||||
| 224 | all child fields will be rendered with the 'tt' render-method, regardless of | ||||||||||
| 225 | their L<HTML::FormFu/render_method> value. | ||||||||||
| 226 | |||||||||||
| 227 | =head1 SEE ALSO | ||||||||||
| 228 | |||||||||||
| 229 | Is a sub-class of, and inherits methods from | ||||||||||
| 230 | L<HTML::FormFu::Role::Element::Field>, | ||||||||||
| 231 | L<HTML::FormFu::Element> | ||||||||||
| 232 | |||||||||||
| 233 | L<HTML::FormFu> | ||||||||||
| 234 | |||||||||||
| 235 | =head1 AUTHOR | ||||||||||
| 236 | |||||||||||
| 237 | Carl Franks, C<cfranks@cpan.org> | ||||||||||
| 238 | |||||||||||
| 239 | =head1 LICENSE | ||||||||||
| 240 | |||||||||||
| 241 | This library is free software, you can redistribute it and/or modify it under | ||||||||||
| 242 | the same terms as Perl itself. | ||||||||||
| 243 | |||||||||||
| 244 | =head1 AUTHOR | ||||||||||
| 245 | |||||||||||
| 246 | Carl Franks <cpan@fireartist.com> | ||||||||||
| 247 | |||||||||||
| 248 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 249 | |||||||||||
| 250 | This software is copyright (c) 2018 by Carl Franks. | ||||||||||
| 251 | |||||||||||
| 252 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 253 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 254 | |||||||||||
| 255 | =cut | ||||||||||