| 1 | 409 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | package HTML::FormFu; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 409 | $HTML::FormFu::VERSION = '2.09'; | |||||||||||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: HTML Form Creation, Rendering and Validation Framework | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 409 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 409 | ▶ | use MooseX::Attribute::Chained; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 409 | with 'HTML::FormFu::Role::Render', | |||||||||||||||||||||||||||||||||||||||||
| 11 | 'HTML::FormFu::Role::CreateChildren', | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 'HTML::FormFu::Role::GetProcessors', | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 'HTML::FormFu::Role::ContainsElements', | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 'HTML::FormFu::Role::ContainsElementsSharedWithField', | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 'HTML::FormFu::Role::FormAndBlockMethods', | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 'HTML::FormFu::Role::FormAndElementMethods', | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 'HTML::FormFu::Role::FormBlockAndFieldMethods', | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 'HTML::FormFu::Role::NestedHashUtils', | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 'HTML::FormFu::Role::Populate', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 'HTML::FormFu::Role::CustomRoles'; | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 409 | ▶ | use HTML::FormFu::Attribute qw( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | mk_attrs | ||||||||||||||||||||||||||||||||||||||||||
| 24 | mk_attr_accessors | ||||||||||||||||||||||||||||||||||||||||||
| 25 | mk_output_accessors | ||||||||||||||||||||||||||||||||||||||||||
| 26 | mk_inherited_accessors | ||||||||||||||||||||||||||||||||||||||||||
| 27 | mk_inherited_merging_accessors | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 409 | ); | |||||||||||||||||||||||||||||||||||||||||
| 29 | 409 | ▶ | use HTML::FormFu::Constants qw( $EMPTY_STR ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 409 | ▶ | use HTML::FormFu::Constraint; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 409 | ▶ | use HTML::FormFu::Exception; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 409 | ▶ | use HTML::FormFu::FakeQuery; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 409 | ▶ | use HTML::FormFu::Filter; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 409 | ▶ | use HTML::FormFu::Inflator; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 409 | ▶ | use HTML::FormFu::Localize; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 409 | ▶ | use HTML::FormFu::ObjectUtil qw( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | form | ||||||||||||||||||||||||||||||||||||||||||
| 38 | load_config_file load_config_filestem | ||||||||||||||||||||||||||||||||||||||||||
| 39 | clone stash | ||||||||||||||||||||||||||||||||||||||||||
| 40 | parent | ||||||||||||||||||||||||||||||||||||||||||
| 41 | _load_file | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 409 | ); | |||||||||||||||||||||||||||||||||||||||||
| 43 | 409 | ▶ | use HTML::FormFu::Util qw( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | DEBUG | ||||||||||||||||||||||||||||||||||||||||||
| 45 | DEBUG_PROCESS | ||||||||||||||||||||||||||||||||||||||||||
| 46 | DEBUG_CONSTRAINTS | ||||||||||||||||||||||||||||||||||||||||||
| 47 | debug | ||||||||||||||||||||||||||||||||||||||||||
| 48 | require_class _get_elements | ||||||||||||||||||||||||||||||||||||||||||
| 49 | xml_escape split_name | ||||||||||||||||||||||||||||||||||||||||||
| 50 | _parse_args process_attrs | ||||||||||||||||||||||||||||||||||||||||||
| 51 | _filter_components | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 409 | ); | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 409 | ▶ | use Clone (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 409 | ▶ | use List::Util 1.45 qw( first any none uniq ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 409 | ▶ | use Scalar::Util qw( blessed weaken reftype ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 409 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 409 | ▶ | use overload ( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 'eq' => '_string_equals', | ||||||||||||||||||||||||||||||||||||||||||
| 61 | '==' => '_object_equals', | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 168 | ▶ | '""' => sub { return shift->render }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 29 | ▶ | 'bool' => sub {1}, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 409 | 'fallback' => 1, | |||||||||||||||||||||||||||||||||||||||||
| 65 | 409 | ); | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 409 | __PACKAGE__->mk_attr_accessors(qw( id action enctype method )); | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 409 | for my $name ( qw( | |||||||||||||||||||||||||||||||||||||||||
| 70 | _elements | ||||||||||||||||||||||||||||||||||||||||||
| 71 | _output_processors | ||||||||||||||||||||||||||||||||||||||||||
| 72 | _valid_names | ||||||||||||||||||||||||||||||||||||||||||
| 73 | _plugins | ||||||||||||||||||||||||||||||||||||||||||
| 74 | _models | ||||||||||||||||||||||||||||||||||||||||||
| 75 | ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||||||||||||||||
| 77 | has $name => ( | ||||||||||||||||||||||||||||||||||||||||||
| 78 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 1010 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 2045 | lazy => 1, | |||||||||||||||||||||||||||||||||||||||||
| 81 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | has languages => ( | ||||||||||||||||||||||||||||||||||||||||||
| 86 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 61 | ▶ | default => sub { ['en'] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 409 | lazy => 1, | |||||||||||||||||||||||||||||||||||||||||
| 89 | isa => 'ArrayRef', | ||||||||||||||||||||||||||||||||||||||||||
| 90 | traits => ['Chained'], | ||||||||||||||||||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | has input => ( | ||||||||||||||||||||||||||||||||||||||||||
| 94 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 26 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 409 | lazy => 1, | |||||||||||||||||||||||||||||||||||||||||
| 97 | isa => 'HashRef', | ||||||||||||||||||||||||||||||||||||||||||
| 98 | traits => ['Chained'], | ||||||||||||||||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | has _processed_params => ( | ||||||||||||||||||||||||||||||||||||||||||
| 102 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 409 | lazy => 1, | |||||||||||||||||||||||||||||||||||||||||
| 105 | isa => 'HashRef', | ||||||||||||||||||||||||||||||||||||||||||
| 106 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 409 | has form_error_message_class => ( | |||||||||||||||||||||||||||||||||||||||||
| 109 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 110 | default => 'form_error_message', | ||||||||||||||||||||||||||||||||||||||||||
| 111 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 409 | has repeatable_max_counter => ( | |||||||||||||||||||||||||||||||||||||||||
| 115 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 116 | default => 100, | ||||||||||||||||||||||||||||||||||||||||||
| 117 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 118 | traits => ['Chained'], | ||||||||||||||||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 409 | our @MULTIFORM_SHARED = ( qw( | |||||||||||||||||||||||||||||||||||||||||
| 122 | javascript | ||||||||||||||||||||||||||||||||||||||||||
| 123 | javascript_src | ||||||||||||||||||||||||||||||||||||||||||
| 124 | indicator | ||||||||||||||||||||||||||||||||||||||||||
| 125 | filename | ||||||||||||||||||||||||||||||||||||||||||
| 126 | query_type | ||||||||||||||||||||||||||||||||||||||||||
| 127 | force_error_message | ||||||||||||||||||||||||||||||||||||||||||
| 128 | localize_class | ||||||||||||||||||||||||||||||||||||||||||
| 129 | tt_module | ||||||||||||||||||||||||||||||||||||||||||
| 130 | nested_name | ||||||||||||||||||||||||||||||||||||||||||
| 131 | nested_subscript | ||||||||||||||||||||||||||||||||||||||||||
| 132 | default_model | ||||||||||||||||||||||||||||||||||||||||||
| 133 | tmp_upload_dir | ||||||||||||||||||||||||||||||||||||||||||
| 134 | params_ignore_underscore | ||||||||||||||||||||||||||||||||||||||||||
| 135 | ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 409 | for (@MULTIFORM_SHARED) { | |||||||||||||||||||||||||||||||||||||||||
| 138 | 5317 | has $_ => ( | |||||||||||||||||||||||||||||||||||||||||
| 139 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 140 | traits => ['Chained'], | ||||||||||||||||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 409 | has submitted => ( is => 'rw', traits => ['Chained'] ); | |||||||||||||||||||||||||||||||||||||||||
| 145 | 409 | has query => ( is => 'rw', traits => ['Chained'] ); | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 409 | has _auto_fieldset => ( is => 'rw' ); | |||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 409 | __PACKAGE__->mk_output_accessors(qw( form_error_message )); | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 409 | *elements = \&element; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 409 | *constraints = \&constraint; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 409 | *filters = \&filter; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 409 | *deflators = \&deflator; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 409 | *inflators = \&inflator; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 409 | *validators = \&validator; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 409 | *transformers = \&transformer; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 409 | *output_processors = \&output_processor; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 409 | *loc = \&localize; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 409 | *plugins = \&plugin; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 409 | *add_plugins = \&add_plugin; | |||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 409 | our $build_defaults = { | |||||||||||||||||||||||||||||||||||||||||
| 164 | action => '', | ||||||||||||||||||||||||||||||||||||||||||
| 165 | method => 'post', | ||||||||||||||||||||||||||||||||||||||||||
| 166 | filename => 'form', | ||||||||||||||||||||||||||||||||||||||||||
| 167 | render_method => 'string', | ||||||||||||||||||||||||||||||||||||||||||
| 168 | tt_args => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 169 | tt_module => 'Template', | ||||||||||||||||||||||||||||||||||||||||||
| 170 | query_type => 'CGI', | ||||||||||||||||||||||||||||||||||||||||||
| 171 | default_model => 'DBIC', | ||||||||||||||||||||||||||||||||||||||||||
| 172 | localize_class => 'HTML::FormFu::I18N', | ||||||||||||||||||||||||||||||||||||||||||
| 173 | auto_error_message => 'form_%s_%t', | ||||||||||||||||||||||||||||||||||||||||||
| 174 | error_tag => 'span', | ||||||||||||||||||||||||||||||||||||||||||
| 175 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 432 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 432 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 432 | $self->populate($build_defaults); | |||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 432 | return; | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 1042 | ▶ | sub auto_fieldset { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
auto_fieldset: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 1042 | my ( $self, $element_ref ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | # if there's no arg, just return whether there's an auto_fieldset already | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 1042 | ▶ | return $self->_auto_fieldset if !$element_ref; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | # if the argument isn't a reference, assume it's just a "1" meaning true, | ||||||||||||||||||||||||||||||||||||||||||
| 192 | # and use an empty hashref | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 87 | ▶ | if ( !ref $element_ref ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 46 | $element_ref = {}; | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 87 | $element_ref->{type} = 'Fieldset'; | |||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 87 | $self->element($element_ref); | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 87 | $self->_auto_fieldset(1); | |||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 87 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 7 | ▶ | sub default_values { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_values: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 7 | my ( $self, $default_ref ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 7 | for my $field ( @{ $self->get_fields } ) { | |||||||||||||||||||||||||||||||||||||||||
| 210 | 18 | my $name = $field->nested_name; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 18 | ▶ | next if !defined $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 18 | ▶ | next if !exists $default_ref->{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 10 | $field->default( $default_ref->{$name} ); | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 7 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 21 | ▶ | sub model { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
model: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 21 | my ( $self, $model_name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 21 | ▶ | $model_name ||= $self->default_model; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$model_name ||= $self->default_model
MC/DC0%0/2
$model_name ||= $self->default_model
$model_name
$self->default_model
Truth table66%2/3
A ||= B
A= $model_nameB= $self->default_model
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||
| 225 | # search models already loaded | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 21 | for my $model ( @{ $self->_models } ) { | |||||||||||||||||||||||||||||||||||||||||
| 227 | 14 | ▶ | return $model | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | if $model->type =~ /\Q$model_name\E$/; | ||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | # class not found, try require-ing it | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 7 | ▶ | my $class | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | = $model_name =~ s/^\+// | ||||||||||||||||||||||||||||||||||||||||||
| 234 | ? $model_name | ||||||||||||||||||||||||||||||||||||||||||
| 235 | : "HTML::FormFu::Model::$model_name"; | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 7 | require_class($class); | |||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 7 | my $model = $class->new( | |||||||||||||||||||||||||||||||||||||||||
| 240 | { type => $model_name, | ||||||||||||||||||||||||||||||||||||||||||
| 241 | parent => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 242 | } ); | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 7 | push @{ $self->_models }, $model; | |||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 7 | return $model; | |||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 480 | ▶ | sub process { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process: called CC=24 SCAR=31.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 480 | my ( $self, $query ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 480 | $self->input( {} ); | |||||||||||||||||||||||||||||||||||||||||
| 253 | 480 | $self->_processed_params( {} ); | |||||||||||||||||||||||||||||||||||||||||
| 254 | 480 | $self->_valid_names( [] ); | |||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 480 | $self->clear_errors; | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 480 | ▶ | $query ||= $self->query; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$query ||= $self->query
MC/DC100%2/2
$query ||= $self->query
$query
$self->query
Truth table100%3/3
A ||= B
A= $queryB= $self->query
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 480 | ▶ | if ( defined $query && !blessed($query) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $query and not builtin::blessed($query)
MC/DC100%2/2
defined $query and not builtin::blessed($query)
defined $query
not builtin::blessed($query)
Truth table100%3/3
A and not(B)
A= defined $queryB= not builtin::blessed($query)
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 425 | $query = HTML::FormFu::FakeQuery->new( $self, $query ); | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | # save it for further calls to process() | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 480 | ▶ | if ($query) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | 434 | ▶ | DEBUG && debug( QUERY => $query ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | 434 | $self->query($query); | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | # run all elements pre_process() methods | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 480 | for my $elem ( @{ $self->get_elements } ) { | |||||||||||||||||||||||||||||||||||||||||
| 273 | 1110 | $elem->pre_process; | |||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | # run all plugins pre_process() methods | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 480 | for my $plugin ( @{ $self->get_plugins } ) { | |||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $plugin->pre_process; | |||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | # run all elements process() methods | ||||||||||||||||||||||||||||||||||||||||||
| 282 | 480 | for my $elem ( @{ $self->get_elements } ) { | |||||||||||||||||||||||||||||||||||||||||
| 283 | 1110 | $elem->process; | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | # run all plugins process() methods | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 480 | for my $plugin ( @{ $self->get_plugins } ) { | |||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | $plugin->process; | |||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 480 | my $submitted; | |||||||||||||||||||||||||||||||||||||||||
| 292 | # refetch query in-case anything in pre_process/process changed it | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 480 | $query = $self->query; | |||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 480 | ▶ | if ( defined $query ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 434 | eval { my @params = $query->param }; | |||||||||||||||||||||||||||||||||||||||||
| 297 | 434 | ▶ | croak "Invalid query object: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 434 | $submitted = $self->_submitted($query); | |||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 480 | ▶ | DEBUG_PROCESS && debug( SUBMITTED => $submitted ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | 480 | $self->submitted($submitted); | |||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | 480 | ▶ | if ($submitted) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 429 | my %input; | |||||||||||||||||||||||||||||||||||||||||
| 308 | 429 | my @params = $query->param; | |||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 429 | for my $field ( @{ $self->get_fields } ) { | |||||||||||||||||||||||||||||||||||||||||
| 311 | 1544 | my $name = $field->nested_name; | |||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | 1544 | ▶ | next if !defined $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 1528 | ▶ | next if none { $name eq $_ } @params; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | ## CGI wants you to use $query->multi_param($foo). | ||||||||||||||||||||||||||||||||||||||||||
| 317 | ## doing so breaks CGI::Simple. So shoosh it up for now. | ||||||||||||||||||||||||||||||||||||||||||
| 318 | 1044 | local $CGI::LIST_CONTEXT_WARN = 0; | |||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 1044 | ▶ | if ( $field->nested ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | # call in list context so we know if there's more than 1 value | ||||||||||||||||||||||||||||||||||||||||||
| 323 | 255 | my @values = $query->param($name); | |||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | 255 | ▶ | my $value | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | = @values > 1 | ||||||||||||||||||||||||||||||||||||||||||
| 327 | ? \@values | ||||||||||||||||||||||||||||||||||||||||||
| 328 | : $values[0]; | ||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 255 | $self->set_nested_hash_value( \%input, $name, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 789 | my @values = $query->param($name); | |||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 789 | ▶ | $input{$name} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | = @values > 1 | ||||||||||||||||||||||||||||||||||||||||||
| 337 | ? \@values | ||||||||||||||||||||||||||||||||||||||||||
| 338 | : $values[0]; | ||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 429 | ▶ | DEBUG && debug( INPUT => \%input ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | # run all field process_input methods | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 429 | for my $field ( @{ $self->get_fields } ) { | |||||||||||||||||||||||||||||||||||||||||
| 346 | 1544 | $field->process_input( \%input ); | |||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | 429 | $self->input( \%input ); | |||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 429 | $self->_process_input; | |||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | # run all plugins post_process methods | ||||||||||||||||||||||||||||||||||||||||||
| 355 | 480 | for my $elem ( @{ $self->get_elements } ) { | |||||||||||||||||||||||||||||||||||||||||
| 356 | 1110 | $elem->post_process; | |||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 480 | for my $plugin ( @{ $self->get_plugins } ) { | |||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | $plugin->post_process; | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 480 | return; | |||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 434 | ▶ | sub _submitted { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_submitted: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | 434 | my ( $self, $query ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 434 | my $indicator = $self->indicator; | |||||||||||||||||||||||||||||||||||||||||
| 370 | 434 | my $code; | |||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 434 | ▶ | if ( defined($indicator) && ref $indicator ne 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
defined $indicator and ref $indicator ne "CODE"
MC/DC100%2/2
defined $indicator and ref $indicator ne "CODE"
defined $indicator
ref $indicator ne "CODE"
Truth table100%3/3
A and B
A= defined $indicatorB= ref $indicator ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | 7 | ▶ | DEBUG_PROCESS && debug( INDICATOR => $indicator ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | 7 | ▶ | $code = sub { return defined $query->param($indicator) }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||
| 377 | elsif ( !defined $indicator ) { | ||||||||||||||||||||||||||||||||||||||||||
| 378 | my @names = uniq | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 1466 | grep {defined} | |||||||||||||||||||||||||||||||||||||||||
| 380 | 414 | map { $_->nested_name } @{ $self->get_fields }; | |||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||
| 382 | 414 | ▶ | DEBUG_PROCESS && debug( 'no indicator, checking fields...' => \@names ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 414 | ▶ | $code = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 414 | grep { defined $query->param($_) } @names; | |||||||||||||||||||||||||||||||||||||||||
| 386 | 414 | }; | |||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 389 | 13 | $code = $indicator; | |||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 434 | return $code->( $self, $query ); | |||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 429 | ▶ | sub _process_input { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_input: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | 429 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | 429 | $self->_build_params; | |||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 429 | $self->_process_file_uploads; | |||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | 429 | $self->_filter_input; | |||||||||||||||||||||||||||||||||||||||||
| 403 | 429 | $self->_constrain_input; | |||||||||||||||||||||||||||||||||||||||||
| 404 | 429 | ▶ | $self->_inflate_input if !@{ $self->get_errors }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | 429 | ▶ | $self->_validate_input if !@{ $self->get_errors }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | 429 | ▶ | $self->_transform_input if !@{ $self->get_errors }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | 429 | $self->_build_valid_names; | |||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 429 | return; | |||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 429 | ▶ | sub _build_params { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_params: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 429 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | 429 | my %params; | |||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | 429 | for my $field ( @{ $self->get_fields } ) { | |||||||||||||||||||||||||||||||||||||||||
| 419 | 1544 | my $name = $field->nested_name; | |||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | 1544 | ▶ | next if !defined $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 1528 | ▶ | next if exists $params{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | next | ||||||||||||||||||||||||||||||||||||||||||
| 425 | 1509 | ▶ | if !$self->nested_hash_key_exists( $self->input, $name ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->nested_hash_key_exists($self->input, $name) or $field->default_empty_value
MC/DC100%2/2
$self->nested_hash_key_exists($self->input, $name) or $field->default_empty_value
$self->nested_hash_key_exists($self->input, $name)
$field->default_empty_value
Truth table100%3/3
A or B
A= $self->nested_hash_key_exists($self->input, $name)B= $field->default_empty_value
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | && !$field->default_empty_value; | ||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | 1091 | my $input = $self->get_nested_hash_value( $self->input, $name ); | |||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | 1091 | ▶ | if ( ref $input eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | # can't clone upload filehandles | ||||||||||||||||||||||||||||||||||||||||||
| 433 | # so create new arrayref of values | ||||||||||||||||||||||||||||||||||||||||||
| 434 | 62 | $input = [@$input]; | |||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 436 | ▶ | elsif ( !defined $input && $field->default_empty_value ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
not defined $input and $field->default_empty_value
MC/DC100%2/2
not defined $input and $field->default_empty_value
not defined $input
$field->default_empty_value
Truth table100%3/3
not(A) and B
A= not defined $inputB= $field->default_empty_value
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | 6 | $input = ''; | |||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | 1091 | $self->set_nested_hash_value( \%params, $name, $input, $name ); | |||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||
| 443 | 429 | $self->_processed_params( \%params ); | |||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | 429 | ▶ | DEBUG_PROCESS && debug( 'PROCESSED PARAMS' => \%params ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | 429 | return; | |||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 429 | ▶ | sub _process_file_uploads { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_file_uploads: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | 429 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | my @names = uniq | ||||||||||||||||||||||||||||||||||||||||||
| 454 | 25 | grep {defined} | |||||||||||||||||||||||||||||||||||||||||
| 455 | 25 | map { $_->nested_name } | |||||||||||||||||||||||||||||||||||||||||
| 456 | 429 | grep { $_->isa('HTML::FormFu::Element::File') } @{ $self->get_fields }; | |||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | 429 | ▶ | if (@names) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 13 | my $query_class = $self->query_type; | |||||||||||||||||||||||||||||||||||||||||
| 460 | 13 | ▶ | if ( $query_class !~ /^\+/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | 13 | $query_class = "HTML::FormFu::QueryType::$query_class"; | |||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||
| 463 | 13 | require_class($query_class); | |||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 13 | my $params = $self->_processed_params; | |||||||||||||||||||||||||||||||||||||||||
| 466 | 13 | my $input = $self->input; | |||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | 13 | for my $name (@names) { | |||||||||||||||||||||||||||||||||||||||||
| 469 | 24 | ▶ | next if !$self->nested_hash_key_exists( $input, $name ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | 21 | my $values = $query_class->parse_uploads( $self, $name ); | |||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | 21 | $self->set_nested_hash_value( $params, $name, $values ); | |||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | 429 | return; | |||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | 429 | ▶ | sub _filter_input { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_filter_input: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | 429 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | 429 | my $params = $self->_processed_params; | |||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||
| 485 | 429 | for my $filter ( @{ $self->get_filters } ) { | |||||||||||||||||||||||||||||||||||||||||
| 486 | 62 | my $name = $filter->nested_name; | |||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | 62 | ▶ | next if !defined $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | 62 | ▶ | next if !$self->nested_hash_key_exists( $params, $name ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | 59 | $filter->process( $self, $params ); | |||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | 429 | return; | |||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||
| 497 | 429 | ▶ | sub _constrain_input { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_constrain_input: called CC=11 SCAR=25.9
| |||||||||||||||||||||||||||||||||||||||||||
| 498 | 429 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | 429 | my $params = $self->_processed_params; | |||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | 429 | for my $constraint ( @{ $self->get_constraints } ) { | |||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | 594 | ▶ | DEBUG_CONSTRAINTS && debug( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | 'FIELD NAME' => $constraint->field->nested_name, | ||||||||||||||||||||||||||||||||||||||||||
| 506 | 'CONSTRAINT TYPE' => $constraint->type, | ||||||||||||||||||||||||||||||||||||||||||
| 507 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | 594 | $constraint->pre_process; | |||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||
| 511 | 594 | my @errors = eval { $constraint->process($params) }; | |||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | 594 | ▶ | DEBUG_CONSTRAINTS && debug( ERRORS => \@errors ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 514 | 594 | ▶ | DEBUG_CONSTRAINTS && debug( '$@' => $@ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||
| 516 | 594 | ▶ | if ( blessed $@ && $@->isa('HTML::FormFu::Exception::Constraint') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
builtin::blessed($@) and $@->isa("HTML::FormFu::Exception::Constraint")
MC/DC0%0/2
builtin::blessed($@) and $@->isa("HTML::FormFu::Exception::Constraint")
builtin::blessed($@)
$@->isa("HTML::FormFu::Exception::Constraint")
Truth table33%1/3
A and B
A= builtin::blessed($@)B= $@->isa("HTML::FormFu::Exception::Constraint")
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | push @errors, $@; | |||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||
| 519 | elsif ($@) { | ||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | push @errors, HTML::FormFu::Exception::Constraint->new; | |||||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | 594 | for my $error (@errors) { | |||||||||||||||||||||||||||||||||||||||||
| 524 | 233 | ▶ | if ( !$error->parent ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 525 | 165 | $error->parent( $constraint->parent ); | |||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||
| 527 | 233 | ▶ | if ( !$error->constraint ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 528 | 233 | $error->constraint($constraint); | |||||||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | 233 | $error->parent->add_error($error); | |||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | 429 | return; | |||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | 286 | ▶ | sub _inflate_input { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_inflate_input: called CC=11 SCAR=26.0
| |||||||||||||||||||||||||||||||||||||||||||
| 539 | 286 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | 286 | my $params = $self->_processed_params; | |||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||
| 543 | 286 | for my $inflator ( @{ $self->get_inflators } ) { | |||||||||||||||||||||||||||||||||||||||||
| 544 | 27 | my $name = $inflator->nested_name; | |||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||
| 546 | 27 | ▶ | next if !defined $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | 27 | ▶ | next if !$self->nested_hash_key_exists( $params, $name ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | ▶ | next if any {defined} @{ $inflator->parent->get_errors }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||
| 550 | 26 | my $value = $self->get_nested_hash_value( $params, $name ); | |||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||
| 552 | 26 | my @errors; | |||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||
| 554 | 26 | ( $value, @errors ) = eval { $inflator->process($value) }; | |||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||
| 556 | 26 | ▶ | if ( blessed $@ && $@->isa('HTML::FormFu::Exception::Inflator') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
builtin::blessed($@) and $@->isa("HTML::FormFu::Exception::Inflator")
MC/DC0%0/2
builtin::blessed($@) and $@->isa("HTML::FormFu::Exception::Inflator")
builtin::blessed($@)
$@->isa("HTML::FormFu::Exception::Inflator")
Truth table33%1/3
A and B
A= builtin::blessed($@)B= $@->isa("HTML::FormFu::Exception::Inflator")
| |||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | push @errors, $@; | |||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||
| 559 | elsif ($@) { | ||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | push @errors, HTML::FormFu::Exception::Inflator->new; | |||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | 26 | for my $error (@errors) { | |||||||||||||||||||||||||||||||||||||||||
| 564 | 3 | ▶ | $error->parent( $inflator->parent ) if !$error->parent; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 565 | 3 | ▶ | $error->inflator($inflator) if !$error->inflator; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | 3 | $error->parent->add_error($error); | |||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||
| 570 | 26 | $self->set_nested_hash_value( $params, $name, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | 286 | return; | |||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||
| 576 | 283 | ▶ | sub _validate_input { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_input: called CC=11 SCAR=27.2
| |||||||||||||||||||||||||||||||||||||||||||
| 577 | 283 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||
| 579 | 283 | my $params = $self->_processed_params; | |||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | 283 | for my $validator ( @{ $self->get_validators } ) { | |||||||||||||||||||||||||||||||||||||||||
| 582 | 8 | my $name = $validator->nested_name; | |||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||
| 584 | 8 | ▶ | next if !defined $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 585 | 8 | ▶ | next if !$self->nested_hash_key_exists( $params, $name ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | ▶ | next if any {defined} @{ $validator->parent->get_errors }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||
| 588 | 8 | my @errors = eval { $validator->process($params) }; | |||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||
| 590 | 8 | ▶ | if ( blessed $@ && $@->isa('HTML::FormFu::Exception::Validator') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
builtin::blessed($@) and $@->isa("HTML::FormFu::Exception::Validator")
MC/DC0%0/2
builtin::blessed($@) and $@->isa("HTML::FormFu::Exception::Validator")
builtin::blessed($@)
$@->isa("HTML::FormFu::Exception::Validator")
Truth table33%1/3
A and B
A= builtin::blessed($@)B= $@->isa("HTML::FormFu::Exception::Validator")
| |||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | push @errors, $@; | |||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||
| 593 | elsif ($@) { | ||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | push @errors, HTML::FormFu::Exception::Validator->new; | |||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||
| 597 | 8 | for my $error (@errors) { | |||||||||||||||||||||||||||||||||||||||||
| 598 | 1 | ▶ | $error->parent( $validator->parent ) if !$error->parent; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 599 | 1 | ▶ | $error->validator($validator) if !$error->validator; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||
| 601 | 1 | $error->parent->add_error($error); | |||||||||||||||||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | 283 | return; | |||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||
| 608 | 282 | ▶ | sub _transform_input { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_transform_input: called CC=11 SCAR=30.8
| |||||||||||||||||||||||||||||||||||||||||||
| 609 | 282 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | 282 | my $params = $self->_processed_params; | |||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||
| 613 | 282 | for my $transformer ( @{ $self->get_transformers } ) { | |||||||||||||||||||||||||||||||||||||||||
| 614 | 5 | my $name = $transformer->nested_name; | |||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||
| 616 | 5 | ▶ | next if !defined $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 617 | 5 | ▶ | next if !$self->nested_hash_key_exists( $params, $name ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | ▶ | next if any {defined} @{ $transformer->parent->get_errors }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||
| 620 | 5 | my $value = $self->get_nested_hash_value( $params, $name ); | |||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||
| 622 | 5 | my (@errors) = eval { $transformer->process( $value, $params ) }; | |||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||
| 624 | 5 | ▶ | if ( blessed $@ && $@->isa('HTML::FormFu::Exception::Transformer') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
builtin::blessed($@) and $@->isa("HTML::FormFu::Exception::Transformer")
MC/DC0%0/2
builtin::blessed($@) and $@->isa("HTML::FormFu::Exception::Transformer")
builtin::blessed($@)
$@->isa("HTML::FormFu::Exception::Transformer")
Truth table33%1/3
A and B
A= builtin::blessed($@)B= $@->isa("HTML::FormFu::Exception::Transformer")
| |||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | push @errors, $@; | |||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||
| 627 | elsif ($@) { | ||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | push @errors, HTML::FormFu::Exception::Transformer->new; | |||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||
| 631 | 5 | for my $error (@errors) { | |||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | ▶ | $error->parent( $transformer->parent ) if !$error->parent; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | ▶ | $error->transformer($transformer) if !$error->transformer; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | $error->parent->add_error($error); | |||||||||||||||||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||
| 639 | 282 | return; | |||||||||||||||||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||
| 642 | 429 | ▶ | sub _build_valid_names { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_valid_names: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 643 | 429 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||
| 645 | 429 | my $params = $self->_processed_params; | |||||||||||||||||||||||||||||||||||||||||
| 646 | 429 | my $skip_private = $self->params_ignore_underscore; | |||||||||||||||||||||||||||||||||||||||||
| 647 | 429 | my @errors = $self->has_errors; | |||||||||||||||||||||||||||||||||||||||||
| 648 | 429 | my @names; | |||||||||||||||||||||||||||||||||||||||||
| 649 | my %non_param; | ||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||
| 651 | 429 | for my $field ( @{ $self->get_fields } ) { | |||||||||||||||||||||||||||||||||||||||||
| 652 | 1544 | my $name = $field->nested_name; | |||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | 1544 | ▶ | next if !defined $name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 655 | 1528 | ▶ | next if $skip_private && $field->name =~ /^_/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$skip_private and $field->name =~ /^_/
MC/DC100%2/2
$skip_private and $field->name =~ /^_/
$skip_private
$field->name =~ /^_/
Truth table100%3/3
A and B
A= $skip_privateB= $field->name =~ /^_/
| |||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||
| 657 | 1527 | ▶ | if ( $field->non_param ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 658 | 6 | $non_param{$name} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||||||||||||||||
| 660 | elsif ( $self->nested_hash_key_exists( $params, $name ) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 661 | 1083 | push @names, $name; | |||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||
| 665 | push @names, uniq | ||||||||||||||||||||||||||||||||||||||||||
| 666 | 1105 | grep { ref $params->{$_} ne 'HASH' } | |||||||||||||||||||||||||||||||||||||||||
| 667 | 1106 | ▶ | grep { !( $skip_private && /^_/ ) } | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$skip_private && /^_/
MC/DC100%2/2
$skip_private && /^_/
$skip_private
/^_/
Truth table100%3/3
A && B
A= $skip_privateB= /^_/
| |||||||||||||||||||||||||||||||||||||||||||
| 668 | 429 | grep { !exists $non_param{$_} } | |||||||||||||||||||||||||||||||||||||||||
| 669 | keys %$params; | ||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||
| 671 | 429 | my %valid; | |||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||
| 673 | CHECK: | ||||||||||||||||||||||||||||||||||||||||||
| 674 | 429 | for my $name (@names) { | |||||||||||||||||||||||||||||||||||||||||
| 675 | 2115 | for my $error (@errors) { | |||||||||||||||||||||||||||||||||||||||||
| 676 | 918 | ▶ | next CHECK if $name eq $error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 677 | } | ||||||||||||||||||||||||||||||||||||||||||
| 678 | 1839 | $valid{$name}++; | |||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||
| 680 | 429 | my @valid = keys %valid; | |||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||
| 682 | 429 | $self->_valid_names( \@valid ); | |||||||||||||||||||||||||||||||||||||||||
| 683 | |||||||||||||||||||||||||||||||||||||||||||
| 684 | 429 | return; | |||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||
| 687 | 4 | ▶ | sub _hash_keys { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hash_keys: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 688 | 4 | my ( $hash, $subscript ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 689 | 4 | my @names; | |||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||
| 691 | 4 | for my $key ( keys %$hash ) { | |||||||||||||||||||||||||||||||||||||||||
| 692 | 10 | ▶ | if ( ref $hash->{$key} eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 693 | push @names, | ||||||||||||||||||||||||||||||||||||||||||
| 694 | 4 | ▶ | map { $subscript ? "${key}[${_}]" : "$key.$_" } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 695 | 2 | _hash_keys( $hash->{$key}, $subscript ); | |||||||||||||||||||||||||||||||||||||||||
| 696 | } | ||||||||||||||||||||||||||||||||||||||||||
| 697 | elsif ( ref $hash->{$key} eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 698 | push @names, | ||||||||||||||||||||||||||||||||||||||||||
| 699 | 4 | ▶ | map { $subscript ? "${key}[${_}]" : "$key.$_" } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 700 | 2 | _array_indices( $hash->{$key}, $subscript ); | |||||||||||||||||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||||||||||||||||
| 702 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 703 | 6 | push @names, $key; | |||||||||||||||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||||||||||||||||
| 705 | } | ||||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||
| 707 | 4 | return @names; | |||||||||||||||||||||||||||||||||||||||||
| 708 | } | ||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||
| 710 | 2 | ▶ | sub _array_indices { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_array_indices: called CC=6 SCAR=24.2
| |||||||||||||||||||||||||||||||||||||||||||
| 711 | 2 | my ( $array, $subscript ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||
| 713 | 2 | my @names; | |||||||||||||||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||||||||||||||||
| 715 | 2 | for my $i ( 0 .. $#{$array} ) { | |||||||||||||||||||||||||||||||||||||||||
| 716 | 4 | ▶ | if ( ref $array->[$i] eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 717 | push @names, | ||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | ▶ | map { $subscript ? "${i}[${_}]" : "$i.$_" } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 719 | _hash_keys( $array->[$i], $subscript ); | ||||||||||||||||||||||||||||||||||||||||||
| 720 | } | ||||||||||||||||||||||||||||||||||||||||||
| 721 | elsif ( ref $array->[$i] eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 722 | push @names, | ||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | ▶ | map { $subscript ? "${i}[${_}]" : "$i.$_" } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 724 | _array_indices( $array->[$i], $subscript ); | ||||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||
| 726 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 727 | 4 | push @names, $i; | |||||||||||||||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||
| 731 | 2 | return @names; | |||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||
| 733 | |||||||||||||||||||||||||||||||||||||||||||
| 734 | 115 | ▶ | sub submitted_and_valid { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
submitted_and_valid: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 735 | 115 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||
| 737 | 115 | ▶ | return $self->submitted && !$self->has_errors; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->submitted && !$self->has_errors
MC/DC100%2/2
$self->submitted && !$self->has_errors
$self->submitted
!$self->has_errors
Truth table100%3/3
A && not(B)
A= $self->submittedB= !$self->has_errors
| |||||||||||||||||||||||||||||||||||||||||||
| 738 | } | ||||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||
| 740 | 79 | ▶ | sub params { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
params: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 741 | 79 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||
| 743 | 79 | ▶ | return {} if !$self->submitted; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||
| 745 | 78 | my @names = $self->valid; | |||||||||||||||||||||||||||||||||||||||||
| 746 | 78 | my %params; | |||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||
| 748 | 78 | for my $name (@names) { | |||||||||||||||||||||||||||||||||||||||||
| 749 | 189 | my @values = $self->param($name); | |||||||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||||||||
| 751 | 189 | ▶ | if ( @values > 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 752 | 13 | $self->set_nested_hash_value( \%params, $name, \@values ); | |||||||||||||||||||||||||||||||||||||||||
| 753 | } | ||||||||||||||||||||||||||||||||||||||||||
| 754 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 755 | 176 | $self->set_nested_hash_value( \%params, $name, $values[0] ); | |||||||||||||||||||||||||||||||||||||||||
| 756 | } | ||||||||||||||||||||||||||||||||||||||||||
| 757 | } | ||||||||||||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||||||||||||
| 759 | 78 | return \%params; | |||||||||||||||||||||||||||||||||||||||||
| 760 | } | ||||||||||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||||||||||
| 762 | 337 | ▶ | sub param { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
param: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 763 | 337 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||||||||||||
| 765 | 337 | ▶ | croak 'param method is readonly' if @_ > 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||||||
| 767 | 337 | ▶ | return if !$self->submitted; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||
| 769 | 337 | ▶ | if ( @_ == 2 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 770 | 332 | ▶ | return if !$self->valid($name); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||||||||||||
| 772 | 313 | my $value | |||||||||||||||||||||||||||||||||||||||||
| 773 | = $self->get_nested_hash_value( $self->_processed_params, $name ); | ||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||
| 775 | 313 | ▶ | return if !defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||||||||||||||||
| 777 | 305 | ▶ | if ( ref $value eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 778 | 20 | ▶ | return wantarray ? @$value : $value->[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 779 | } | ||||||||||||||||||||||||||||||||||||||||||
| 780 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 781 | 285 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||
| 783 | } | ||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||
| 785 | # return a list of valid names, if no $name arg | ||||||||||||||||||||||||||||||||||||||||||
| 786 | 5 | return $self->valid; | |||||||||||||||||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||
| 789 | 39 | ▶ | sub param_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
param_value: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 790 | 39 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||
| 792 | 39 | ▶ | croak 'name parameter required' if @_ != 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 793 | |||||||||||||||||||||||||||||||||||||||||||
| 794 | return undef ## no critic (ProhibitExplicitReturnUndef); | ||||||||||||||||||||||||||||||||||||||||||
| 795 | 39 | ▶ | if !$self->valid($name); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||
| 797 | # this is guaranteed to always return a single value | ||||||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||||||
| 799 | 38 | my $value = $self->get_nested_hash_value( $self->_processed_params, $name ); | |||||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||||||
| 801 | 38 | ▶ | return ref $value eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 802 | ? $value->[0] | ||||||||||||||||||||||||||||||||||||||||||
| 803 | : $value; | ||||||||||||||||||||||||||||||||||||||||||
| 804 | } | ||||||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||||||
| 806 | 7 | ▶ | sub param_array { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
param_array: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 807 | 7 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||||||||||||||||
| 809 | 7 | ▶ | croak 'name parameter required' if @_ != 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||||||||||||||||
| 811 | # guaranteed to always return an arrayref | ||||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||
| 813 | 7 | ▶ | return [] if !$self->valid($name); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||
| 815 | 6 | my $value = $self->get_nested_hash_value( $self->_processed_params, $name ); | |||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||
| 817 | 6 | ▶ | return [] if !defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||
| 819 | 6 | ▶ | return ref $value eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 820 | ? $value | ||||||||||||||||||||||||||||||||||||||||||
| 821 | : [$value]; | ||||||||||||||||||||||||||||||||||||||||||
| 822 | } | ||||||||||||||||||||||||||||||||||||||||||
| 823 | |||||||||||||||||||||||||||||||||||||||||||
| 824 | 3 | ▶ | sub param_list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
param_list: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 825 | 3 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||
| 827 | 3 | ▶ | croak 'name parameter required' if @_ != 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||
| 829 | # guaranteed to always return an arrayref | ||||||||||||||||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||||||||||||||||
| 831 | 3 | ▶ | return if !$self->valid($name); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||||||||
| 833 | 2 | my $value = $self->get_nested_hash_value( $self->_processed_params, $name ); | |||||||||||||||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||||||||||||||||
| 835 | 2 | ▶ | return if !defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||||||||||||||||
| 837 | 2 | ▶ | return ref $value eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 838 | ? @$value | ||||||||||||||||||||||||||||||||||||||||||
| 839 | : $value; | ||||||||||||||||||||||||||||||||||||||||||
| 840 | } | ||||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||
| 842 | 1007 | ▶ | sub valid { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
valid: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 843 | 1007 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||||||
| 845 | 1007 | ▶ | return if !$self->submitted; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||||||||||||||||
| 847 | 1007 | my @valid = @{ $self->_valid_names }; | |||||||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||||||||
| 849 | 1007 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 850 | 830 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||||||||||||||||
| 852 | 830 | ▶ | return 1 if any { $name eq $_ } @valid; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||||||||||||||||
| 854 | # not found - see if it's the name of a nested block | ||||||||||||||||||||||||||||||||||||||||||
| 855 | 111 | my $parent; | |||||||||||||||||||||||||||||||||||||||||
| 856 | |||||||||||||||||||||||||||||||||||||||||||
| 857 | 111 | ▶ | if ( defined $self->nested_name && $self->nested_name eq $name ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->nested_name and $self->nested_name eq $name
MC/DC0%0/2
defined $self->nested_name and $self->nested_name eq $name
defined $self->nested_name
$self->nested_name eq $name
Truth table33%1/3
A and B
A= defined $self->nested_nameB= $self->nested_name eq $name
| |||||||||||||||||||||||||||||||||||||||||||
| 858 | 0 | $parent = $self; | |||||||||||||||||||||||||||||||||||||||||
| 859 | } | ||||||||||||||||||||||||||||||||||||||||||
| 860 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 861 | ($parent) | ||||||||||||||||||||||||||||||||||||||||||
| 862 | 107 | ▶ | = first { $_->isa('HTML::FormFu::Element::Block') } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 863 | 111 | @{ $self->get_all_elements( { nested_name => $name, } ) }; | |||||||||||||||||||||||||||||||||||||||||
| 864 | } | ||||||||||||||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||||||||||||||
| 866 | 111 | ▶ | if ( defined $parent ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 867 | 3 | ▶ | my $fail = any {defined} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 868 | 5 | map { @{ $_->get_errors } } @{ $parent->get_fields }; | |||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||
| 870 | 5 | ▶ | return 1 if !$fail; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 871 | } | ||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||
| 873 | 109 | return; | |||||||||||||||||||||||||||||||||||||||||
| 874 | } | ||||||||||||||||||||||||||||||||||||||||||
| 875 | |||||||||||||||||||||||||||||||||||||||||||
| 876 | # return a list of valid names, if no $name arg | ||||||||||||||||||||||||||||||||||||||||||
| 877 | 177 | return @valid; | |||||||||||||||||||||||||||||||||||||||||
| 878 | } | ||||||||||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||||||||||
| 880 | 925 | ▶ | sub has_errors { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_errors: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 881 | 925 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||||||||||||||||
| 883 | 925 | ▶ | return if !$self->submitted; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||||
| 885 | 413 | my @names = map { $_->nested_name } | |||||||||||||||||||||||||||||||||||||||||
| 886 | 2805 | grep { @{ $_->get_errors } } | |||||||||||||||||||||||||||||||||||||||||
| 887 | 781 | grep { defined $_->nested_name } @{ $self->get_fields }; | |||||||||||||||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||||||||||||||||
| 889 | 781 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 890 | 143 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 891 | 143 | ▶ | return 1 if any {/\Q$name/} @names; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 892 | 89 | return; | |||||||||||||||||||||||||||||||||||||||||
| 893 | } | ||||||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||||||
| 895 | # return list of names with errors, if no $name arg | ||||||||||||||||||||||||||||||||||||||||||
| 896 | 638 | return @names; | |||||||||||||||||||||||||||||||||||||||||
| 897 | } | ||||||||||||||||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||||||||||||||||
| 899 | 4 | ▶ | sub add_valid { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_valid: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 900 | 4 | my ( $self, $key, $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 901 | |||||||||||||||||||||||||||||||||||||||||||
| 902 | 4 | ▶ | croak 'add_valid requires arguments ($key, $value)' if @_ != 3; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||||||||||||
| 904 | 4 | $self->set_nested_hash_value( $self->input, $key, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 905 | |||||||||||||||||||||||||||||||||||||||||||
| 906 | 4 | $self->set_nested_hash_value( $self->_processed_params, $key, $value ); | |||||||||||||||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||||||||||||||||
| 908 | 4 | ▶ | if ( none { $_ eq $key } @{ $self->_valid_names } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 909 | 4 | push @{ $self->_valid_names }, $key; | |||||||||||||||||||||||||||||||||||||||||
| 910 | } | ||||||||||||||||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||||||||||||||||
| 912 | 4 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 913 | } | ||||||||||||||||||||||||||||||||||||||||||
| 914 | |||||||||||||||||||||||||||||||||||||||||||
| 915 | 1 | ▶ | sub _single_plugin { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_single_plugin: called CC=7 SCAR=21.6
| |||||||||||||||||||||||||||||||||||||||||||
| 916 | 1 | my ( $self, $arg_ref ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||||||||||||||||
| 918 | 1 | ▶ | if ( !ref $arg_ref ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 919 | 0 | $arg_ref = { type => $arg_ref }; | |||||||||||||||||||||||||||||||||||||||||
| 920 | } | ||||||||||||||||||||||||||||||||||||||||||
| 921 | elsif ( ref $arg_ref eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||
| 923 | # shallow clone | ||||||||||||||||||||||||||||||||||||||||||
| 924 | 1 | $arg_ref = {%$arg_ref}; | |||||||||||||||||||||||||||||||||||||||||
| 925 | } | ||||||||||||||||||||||||||||||||||||||||||
| 926 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 927 | 0 | croak 'invalid args'; | |||||||||||||||||||||||||||||||||||||||||
| 928 | } | ||||||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||||||
| 930 | 1 | my $type = delete $arg_ref->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 931 | 1 | my @return; | |||||||||||||||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||||||||||||||||
| 933 | 1 | ▶ | my @names = map { ref $_ ? @$_ : $_ } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 934 | 1 | grep {defined} ( delete $arg_ref->{name}, delete $arg_ref->{names} ); | |||||||||||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||||||||||||
| 936 | 1 | ▶ | if (@names) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 937 | |||||||||||||||||||||||||||||||||||||||||||
| 938 | # add plugins to appropriate fields | ||||||||||||||||||||||||||||||||||||||||||
| 939 | 1 | for my $x (@names) { | |||||||||||||||||||||||||||||||||||||||||
| 940 | 1 | for my $field ( @{ $self->get_fields( { nested_name => $x } ) } ) { | |||||||||||||||||||||||||||||||||||||||||
| 941 | 1 | my $new = $field->_require_plugin( $type, $arg_ref ); | |||||||||||||||||||||||||||||||||||||||||
| 942 | 1 | push @{ $field->_plugins }, $new; | |||||||||||||||||||||||||||||||||||||||||
| 943 | 1 | push @return, $new; | |||||||||||||||||||||||||||||||||||||||||
| 944 | } | ||||||||||||||||||||||||||||||||||||||||||
| 945 | } | ||||||||||||||||||||||||||||||||||||||||||
| 946 | } | ||||||||||||||||||||||||||||||||||||||||||
| 947 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||||||||||||||||
| 949 | # add plugin directly to form | ||||||||||||||||||||||||||||||||||||||||||
| 950 | 0 | my $new = $self->_require_plugin( $type, $arg_ref ); | |||||||||||||||||||||||||||||||||||||||||
| 951 | |||||||||||||||||||||||||||||||||||||||||||
| 952 | 0 | push @{ $self->_plugins }, $new; | |||||||||||||||||||||||||||||||||||||||||
| 953 | 0 | push @return, $new; | |||||||||||||||||||||||||||||||||||||||||
| 954 | } | ||||||||||||||||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||||||||||||||||
| 956 | 1 | return @return; | |||||||||||||||||||||||||||||||||||||||||
| 957 | } | ||||||||||||||||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||||||||||||||||
| 959 | 174 | ▶ | around render => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 960 | 174 | my $orig = shift; | |||||||||||||||||||||||||||||||||||||||||
| 961 | 174 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||||||||||
| 963 | 174 | my $plugins = $self->get_plugins; | |||||||||||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||||||||||||
| 965 | 174 | for my $plugin (@$plugins) { | |||||||||||||||||||||||||||||||||||||||||
| 966 | 0 | $plugin->render; | |||||||||||||||||||||||||||||||||||||||||
| 967 | } | ||||||||||||||||||||||||||||||||||||||||||
| 968 | |||||||||||||||||||||||||||||||||||||||||||
| 969 | 174 | my $output = $self->$orig; | |||||||||||||||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||||||||||||||||
| 971 | 174 | for my $plugin (@$plugins) { | |||||||||||||||||||||||||||||||||||||||||
| 972 | 0 | $plugin->post_render( \$output ); | |||||||||||||||||||||||||||||||||||||||||
| 973 | } | ||||||||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||||||||
| 975 | 174 | return $output; | |||||||||||||||||||||||||||||||||||||||||
| 976 | 409 | }; | |||||||||||||||||||||||||||||||||||||||||
| 977 | |||||||||||||||||||||||||||||||||||||||||||
| 978 | 12 | ▶ | sub render_data { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_data: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 979 | 12 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||||||||||||||||
| 981 | my $render = $self->render_data_non_recursive( | ||||||||||||||||||||||||||||||||||||||||||
| 982 | 12 | ▶ | { elements => [ map { $_->render_data } @{ $self->_elements } ], | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 983 | $args ? %$args : (), | ||||||||||||||||||||||||||||||||||||||||||
| 984 | } ); | ||||||||||||||||||||||||||||||||||||||||||
| 985 | |||||||||||||||||||||||||||||||||||||||||||
| 986 | 12 | return $render; | |||||||||||||||||||||||||||||||||||||||||
| 987 | } | ||||||||||||||||||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||||||||||||||||
| 989 | 189 | ▶ | sub render_data_non_recursive { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_data_non_recursive: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 990 | 189 | my ( $self, $args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 991 | |||||||||||||||||||||||||||||||||||||||||||
| 992 | 189 | ▶ | my %render = ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 993 | filename => $self->filename, | ||||||||||||||||||||||||||||||||||||||||||
| 994 | javascript => $self->javascript, | ||||||||||||||||||||||||||||||||||||||||||
| 995 | javascript_src => $self->javascript_src, | ||||||||||||||||||||||||||||||||||||||||||
| 996 | attributes => xml_escape( $self->attributes ), | ||||||||||||||||||||||||||||||||||||||||||
| 997 | stash => $self->stash, | ||||||||||||||||||||||||||||||||||||||||||
| 998 | $args ? %$args : (), | ||||||||||||||||||||||||||||||||||||||||||
| 999 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1000 | |||||||||||||||||||||||||||||||||||||||||||
| 1001 | 189 | $render{form} = \%render; | |||||||||||||||||||||||||||||||||||||||||
| 1002 | 189 | weaken( $render{form} ); | |||||||||||||||||||||||||||||||||||||||||
| 1003 | |||||||||||||||||||||||||||||||||||||||||||
| 1004 | 189 | $render{object} = $self; | |||||||||||||||||||||||||||||||||||||||||
| 1005 | |||||||||||||||||||||||||||||||||||||||||||
| 1006 | 189 | ▶ | if ($self->force_error_message | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$self->force_error_message or $self->has_errors and defined $self->form_error_message
$self->has_errors and defined $self->form_error_message
MC/DC100%3/3
$self->force_error_message or $self->has_errors and defined $self->form_error_message
$self->force_error_message
$self->has_errors
defined $self->form_error_message
Truth table100%4/4
A or B and C
A= $self->force_error_messageB= $self->has_errorsC= defined $self->form_error_message
| |||||||||||||||||||||||||||||||||||||||||||
| 1007 | || ( $self->has_errors | ||||||||||||||||||||||||||||||||||||||||||
| 1008 | && defined $self->form_error_message ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 1009 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1010 | 3 | $render{form_error_message} = xml_escape( $self->form_error_message ); | |||||||||||||||||||||||||||||||||||||||||
| 1011 | 3 | $render{form_error_message_class} = $self->form_error_message_class; | |||||||||||||||||||||||||||||||||||||||||
| 1012 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1013 | |||||||||||||||||||||||||||||||||||||||||||
| 1014 | 189 | return \%render; | |||||||||||||||||||||||||||||||||||||||||
| 1015 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1016 | |||||||||||||||||||||||||||||||||||||||||||
| 1017 | 171 | ▶ | sub string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
string: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1018 | 171 | my ( $self, $args_ref ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1019 | |||||||||||||||||||||||||||||||||||||||||||
| 1020 | 171 | ▶ | $args_ref ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args_ref ||= {}
MC/DC0%0/1
$args_ref ||= {}
$args_ref
Truth table50%1/2
A
A= $args_ref
| |||||||||||||||||||||||||||||||||||||||||||
| 1021 | |||||||||||||||||||||||||||||||||||||||||||
| 1022 | 171 | my $html = $self->_string_form_start($args_ref); | |||||||||||||||||||||||||||||||||||||||||
| 1023 | |||||||||||||||||||||||||||||||||||||||||||
| 1024 | # form template | ||||||||||||||||||||||||||||||||||||||||||
| 1025 | |||||||||||||||||||||||||||||||||||||||||||
| 1026 | 171 | $html .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1027 | |||||||||||||||||||||||||||||||||||||||||||
| 1028 | 171 | for my $element ( @{ $self->get_elements } ) { | |||||||||||||||||||||||||||||||||||||||||
| 1029 | |||||||||||||||||||||||||||||||||||||||||||
| 1030 | # call render, so that child elements can use a different renderer | ||||||||||||||||||||||||||||||||||||||||||
| 1031 | 240 | my $element_html = $element->render; | |||||||||||||||||||||||||||||||||||||||||
| 1032 | |||||||||||||||||||||||||||||||||||||||||||
| 1033 | # skip Blank fields | ||||||||||||||||||||||||||||||||||||||||||
| 1034 | 240 | ▶ | if ( length $element_html ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1035 | 239 | $html .= $element_html . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1036 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1037 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||||||||||||||||
| 1039 | 171 | $html .= $self->_string_form_end($args_ref); | |||||||||||||||||||||||||||||||||||||||||
| 1040 | 171 | $html .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 1041 | |||||||||||||||||||||||||||||||||||||||||||
| 1042 | 171 | return $html; | |||||||||||||||||||||||||||||||||||||||||
| 1043 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1044 | |||||||||||||||||||||||||||||||||||||||||||
| 1045 | 177 | ▶ | sub _string_form_start { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_string_form_start: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 1046 | 177 | my ( $self, $args_ref ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1047 | |||||||||||||||||||||||||||||||||||||||||||
| 1048 | # start_form template | ||||||||||||||||||||||||||||||||||||||||||
| 1049 | |||||||||||||||||||||||||||||||||||||||||||
| 1050 | my $render_ref | ||||||||||||||||||||||||||||||||||||||||||
| 1051 | = exists $args_ref->{render_data} | ||||||||||||||||||||||||||||||||||||||||||
| 1052 | ? $args_ref->{render_data} | ||||||||||||||||||||||||||||||||||||||||||
| 1053 | 177 | ▶ | : $self->render_data_non_recursive; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1054 | |||||||||||||||||||||||||||||||||||||||||||
| 1055 | 177 | my $html = sprintf "<form%s>", process_attrs( $render_ref->{attributes} ); | |||||||||||||||||||||||||||||||||||||||||
| 1056 | |||||||||||||||||||||||||||||||||||||||||||
| 1057 | 177 | ▶ | if ( defined $render_ref->{form_error_message} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1058 | $html .= sprintf qq{\n<div class="%s">%s</div>}, | ||||||||||||||||||||||||||||||||||||||||||
| 1059 | $render_ref->{form_error_message_class}, | ||||||||||||||||||||||||||||||||||||||||||
| 1060 | $render_ref->{form_error_message}, | ||||||||||||||||||||||||||||||||||||||||||
| 1061 | 3 | ; | |||||||||||||||||||||||||||||||||||||||||
| 1062 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1063 | |||||||||||||||||||||||||||||||||||||||||||
| 1064 | 177 | ▶ | if ( defined $render_ref->{javascript_src} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1065 | 2 | my $uri = $render_ref->{javascript_src}; | |||||||||||||||||||||||||||||||||||||||||
| 1066 | |||||||||||||||||||||||||||||||||||||||||||
| 1067 | 2 | ▶ | my @uris = ref $uri eq 'ARRAY' ? @$uri : ($uri); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1068 | |||||||||||||||||||||||||||||||||||||||||||
| 1069 | 2 | for my $uri (@uris) { | |||||||||||||||||||||||||||||||||||||||||
| 1070 | 3 | $html .= sprintf | |||||||||||||||||||||||||||||||||||||||||
| 1071 | qq{\n<script type="text/javascript" src="%s">\n</script>}, | ||||||||||||||||||||||||||||||||||||||||||
| 1072 | $uri, | ||||||||||||||||||||||||||||||||||||||||||
| 1073 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 1074 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1075 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1076 | |||||||||||||||||||||||||||||||||||||||||||
| 1077 | 177 | ▶ | if ( defined $render_ref->{javascript} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1078 | $html .= sprintf | ||||||||||||||||||||||||||||||||||||||||||
| 1079 | qq{\n<script type="text/javascript">\n%s\n</script>}, | ||||||||||||||||||||||||||||||||||||||||||
| 1080 | $render_ref->{javascript}, | ||||||||||||||||||||||||||||||||||||||||||
| 1081 | 3 | ; | |||||||||||||||||||||||||||||||||||||||||
| 1082 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1083 | |||||||||||||||||||||||||||||||||||||||||||
| 1084 | 177 | return $html; | |||||||||||||||||||||||||||||||||||||||||
| 1085 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||||||||||||||||
| 1087 | 177 | ▶ | sub _string_form_end { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_string_form_end: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1088 | 177 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1089 | |||||||||||||||||||||||||||||||||||||||||||
| 1090 | # end_form template | ||||||||||||||||||||||||||||||||||||||||||
| 1091 | |||||||||||||||||||||||||||||||||||||||||||
| 1092 | 177 | return "</form>"; | |||||||||||||||||||||||||||||||||||||||||
| 1093 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1094 | |||||||||||||||||||||||||||||||||||||||||||
| 1095 | 6 | ▶ | sub start { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1096 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1097 | |||||||||||||||||||||||||||||||||||||||||||
| 1098 | 6 | ▶ | if ( 'tt' eq $self->render_method ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1099 | 0 | return $self->tt( | |||||||||||||||||||||||||||||||||||||||||
| 1100 | { filename => 'start_form', | ||||||||||||||||||||||||||||||||||||||||||
| 1101 | render_data => $self->render_data_non_recursive, | ||||||||||||||||||||||||||||||||||||||||||
| 1102 | } ); | ||||||||||||||||||||||||||||||||||||||||||
| 1103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1104 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1105 | 6 | return $self->_string_form_start(@_); | |||||||||||||||||||||||||||||||||||||||||
| 1106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1108 | |||||||||||||||||||||||||||||||||||||||||||
| 1109 | 6 | ▶ | sub end { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
end: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1110 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1111 | |||||||||||||||||||||||||||||||||||||||||||
| 1112 | 6 | ▶ | if ( 'tt' eq $self->render_method ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1113 | 0 | return $self->tt( | |||||||||||||||||||||||||||||||||||||||||
| 1114 | { filename => 'end_form', | ||||||||||||||||||||||||||||||||||||||||||
| 1115 | render_data => $self->render_data_non_recursive, | ||||||||||||||||||||||||||||||||||||||||||
| 1116 | } ); | ||||||||||||||||||||||||||||||||||||||||||
| 1117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1118 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1119 | 6 | return $self->_string_form_end(@_); | |||||||||||||||||||||||||||||||||||||||||
| 1120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1122 | |||||||||||||||||||||||||||||||||||||||||||
| 1123 | 1 | ▶ | sub hidden_fields { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hidden_fields: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1124 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1125 | |||||||||||||||||||||||||||||||||||||||||||
| 1126 | return join $EMPTY_STR, | ||||||||||||||||||||||||||||||||||||||||||
| 1127 | 1 | map { $_->render } @{ $self->get_fields( { type => 'Hidden' } ) }; | |||||||||||||||||||||||||||||||||||||||||
| 1128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1129 | |||||||||||||||||||||||||||||||||||||||||||
| 1130 | 3 | ▶ | sub output_processor { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
output_processor: called CC=3 SCAR=12.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1131 | 3 | my ( $self, $arg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1132 | 3 | my @return; | |||||||||||||||||||||||||||||||||||||||||
| 1133 | |||||||||||||||||||||||||||||||||||||||||||
| 1134 | 3 | ▶ | if ( ref $arg eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1135 | 0 | push @return, map { $self->_single_output_processor($_) } @$arg; | |||||||||||||||||||||||||||||||||||||||||
| 1136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1137 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1138 | 3 | push @return, $self->_single_output_processor($arg); | |||||||||||||||||||||||||||||||||||||||||
| 1139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1140 | |||||||||||||||||||||||||||||||||||||||||||
| 1141 | 3 | ▶ | return @return == 1 ? $return[0] : @return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1143 | |||||||||||||||||||||||||||||||||||||||||||
| 1144 | 3 | ▶ | sub _single_output_processor { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_single_output_processor: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 1145 | 3 | my ( $self, $arg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1146 | |||||||||||||||||||||||||||||||||||||||||||
| 1147 | 3 | ▶ | if ( !ref $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1148 | 2 | $arg = { type => $arg }; | |||||||||||||||||||||||||||||||||||||||||
| 1149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1150 | elsif ( ref $arg eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 1151 | 1 | $arg = Clone::clone($arg); | |||||||||||||||||||||||||||||||||||||||||
| 1152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1153 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 1154 | 0 | croak 'invalid args'; | |||||||||||||||||||||||||||||||||||||||||
| 1155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1156 | |||||||||||||||||||||||||||||||||||||||||||
| 1157 | 3 | my $type = delete $arg->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 1158 | |||||||||||||||||||||||||||||||||||||||||||
| 1159 | 3 | my $new = $self->_require_output_processor( $type, $arg ); | |||||||||||||||||||||||||||||||||||||||||
| 1160 | |||||||||||||||||||||||||||||||||||||||||||
| 1161 | 3 | push @{ $self->_output_processors }, $new; | |||||||||||||||||||||||||||||||||||||||||
| 1162 | |||||||||||||||||||||||||||||||||||||||||||
| 1163 | 3 | return $new; | |||||||||||||||||||||||||||||||||||||||||
| 1164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1165 | |||||||||||||||||||||||||||||||||||||||||||
| 1166 | 3 | ▶ | sub _require_output_processor { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_require_output_processor: called CC=6 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 1167 | 3 | my ( $self, $type, $opt ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1168 | |||||||||||||||||||||||||||||||||||||||||||
| 1169 | 3 | ▶ | croak 'required arguments: $self, $type, \%options' if @_ != 3; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1170 | |||||||||||||||||||||||||||||||||||||||||||
| 1171 | 3 | ▶ | croak "options argument must be hash-ref" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1172 | if reftype($opt) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||
| 1173 | |||||||||||||||||||||||||||||||||||||||||||
| 1174 | 3 | my $class = $type; | |||||||||||||||||||||||||||||||||||||||||
| 1175 | 3 | ▶ | if ( not $class =~ s/^\+// ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1176 | 3 | $class = "HTML::FormFu::OutputProcessor::$class"; | |||||||||||||||||||||||||||||||||||||||||
| 1177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1178 | |||||||||||||||||||||||||||||||||||||||||||
| 1179 | 3 | $type =~ s/^\+//; | |||||||||||||||||||||||||||||||||||||||||
| 1180 | |||||||||||||||||||||||||||||||||||||||||||
| 1181 | 3 | require_class($class); | |||||||||||||||||||||||||||||||||||||||||
| 1182 | |||||||||||||||||||||||||||||||||||||||||||
| 1183 | 3 | my $object = $class->new( | |||||||||||||||||||||||||||||||||||||||||
| 1184 | { type => $type, | ||||||||||||||||||||||||||||||||||||||||||
| 1185 | parent => $self, | ||||||||||||||||||||||||||||||||||||||||||
| 1186 | } ); | ||||||||||||||||||||||||||||||||||||||||||
| 1187 | |||||||||||||||||||||||||||||||||||||||||||
| 1188 | # handle default_args | ||||||||||||||||||||||||||||||||||||||||||
| 1189 | 3 | my $parent = $self->parent; | |||||||||||||||||||||||||||||||||||||||||
| 1190 | |||||||||||||||||||||||||||||||||||||||||||
| 1191 | 3 | ▶ | if ( $parent && exists $parent->default_args->{output_processor}{$type} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$parent and exists $parent->default_args->{"output_processor"}{$type}
MC/DC0%0/2
$parent and exists $parent->default_args->{"output_processor"}{$type}
$parent
exists $parent->default_args->{"output_processor"}{$type}
Truth table33%1/3
A and B
A= $parentB= exists $parent->default_args->{"output_processor"}{$type}
| |||||||||||||||||||||||||||||||||||||||||||
| 1192 | %$opt | ||||||||||||||||||||||||||||||||||||||||||
| 1193 | 0 | = ( %{ $parent->default_args->{output_processor}{$type} }, %$opt ); | |||||||||||||||||||||||||||||||||||||||||
| 1194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1195 | |||||||||||||||||||||||||||||||||||||||||||
| 1196 | 3 | $object->populate($opt); | |||||||||||||||||||||||||||||||||||||||||
| 1197 | |||||||||||||||||||||||||||||||||||||||||||
| 1198 | 3 | return $object; | |||||||||||||||||||||||||||||||||||||||||
| 1199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1200 | |||||||||||||||||||||||||||||||||||||||||||
| 1201 | 1139 | ▶ | sub get_output_processors { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_output_processors: called CC=2 SCAR=7.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1202 | 1139 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1203 | 1139 | my %args = _parse_args(@_); | |||||||||||||||||||||||||||||||||||||||||
| 1204 | |||||||||||||||||||||||||||||||||||||||||||
| 1205 | 1139 | my @x = @{ $self->_output_processors }; | |||||||||||||||||||||||||||||||||||||||||
| 1206 | |||||||||||||||||||||||||||||||||||||||||||
| 1207 | 1139 | ▶ | if ( exists $args{type} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1208 | 0 | @x = grep { $_->type eq $args{type} } @x; | |||||||||||||||||||||||||||||||||||||||||
| 1209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1210 | |||||||||||||||||||||||||||||||||||||||||||
| 1211 | 1139 | return \@x; | |||||||||||||||||||||||||||||||||||||||||
| 1212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1213 | |||||||||||||||||||||||||||||||||||||||||||
| 1214 | 0 | ▶ | sub get_output_processor { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_output_processor: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1215 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1216 | |||||||||||||||||||||||||||||||||||||||||||
| 1217 | 0 | my $x = $self->get_output_processors(@_); | |||||||||||||||||||||||||||||||||||||||||
| 1218 | |||||||||||||||||||||||||||||||||||||||||||
| 1219 | 0 | ▶ | return @$x ? $x->[0] : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1221 | |||||||||||||||||||||||||||||||||||||||||||
| 1222 | 409 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 1223 | |||||||||||||||||||||||||||||||||||||||||||
| 1224 | 409 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 1225 | |||||||||||||||||||||||||||||||||||||||||||
| 1226 | __END__ | ||||||||||||||||||||||||||||||||||||||||||