| 1 | package Form::Factory::Action; | ||||||||||||||||||||
| 2 | 1 | $Form::Factory::Action::VERSION = '0.022'; | |||||||||||||||||||
| 3 | 1 | ▶ | use Moose::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 1 | ▶ | use Carp (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use Form::Factory::Feature::Functional; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use Form::Factory::Result::Gathered; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use Form::Factory::Result::Single; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | #requires qw( run ); | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | # ABSTRACT: Role implemented by actions | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 1 | has form_interface => ( | |||||||||||||||||||
| 16 | is => 'ro', | ||||||||||||||||||||
| 17 | does => 'Form::Factory::Interface', | ||||||||||||||||||||
| 18 | required => 1, | ||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | has globals => ( | ||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||
| 24 | isa => 'HashRef[Str]', | ||||||||||||||||||||
| 25 | required => 1, | ||||||||||||||||||||
| 26 | 14 | ▶ | default => sub { {} }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | 1 | ); | |||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | has results => ( | ||||||||||||||||||||
| 31 | is => 'rw', | ||||||||||||||||||||
| 32 | isa => 'Form::Factory::Result', | ||||||||||||||||||||
| 33 | required => 1, | ||||||||||||||||||||
| 34 | lazy => 1, | ||||||||||||||||||||
| 35 | 14 | ▶ | default => sub { Form::Factory::Result::Gathered->new }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 36 | 1 | handles => [ qw( | |||||||||||||||||||
| 37 | is_valid is_success is_failure | ||||||||||||||||||||
| 38 | is_validated is_outcome_known | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | all_messages regular_messages field_messages | ||||||||||||||||||||
| 41 | info_messages warning_messages error_messages | ||||||||||||||||||||
| 42 | regular_info_messages regular_warning_messages regular_error_messages | ||||||||||||||||||||
| 43 | field_info_messages field_warning_messages field_error_messages | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | content | ||||||||||||||||||||
| 46 | ) ], | ||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | has result => ( | ||||||||||||||||||||
| 51 | is => 'rw', | ||||||||||||||||||||
| 52 | isa => 'Form::Factory::Result::Single', | ||||||||||||||||||||
| 53 | required => 1, | ||||||||||||||||||||
| 54 | lazy => 1, | ||||||||||||||||||||
| 55 | 11 | ▶ | default => sub { Form::Factory::Result::Single->new }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 56 | 1 | handles => [ qw( | |||||||||||||||||||
| 57 | success failure | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | add_message | ||||||||||||||||||||
| 60 | info warning error | ||||||||||||||||||||
| 61 | field_info field_warning field_error | ||||||||||||||||||||
| 62 | ) ], | ||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | has features => ( | ||||||||||||||||||||
| 67 | is => 'ro', | ||||||||||||||||||||
| 68 | isa => 'ArrayRef', | ||||||||||||||||||||
| 69 | required => 1, | ||||||||||||||||||||
| 70 | lazy => 1, | ||||||||||||||||||||
| 71 | initializer => '_init_features', | ||||||||||||||||||||
| 72 | 14 | ▶ | default => sub { [] }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 73 | 1 | ); | |||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 14 | ▶ | sub _meta_features { | ||||||||||||||||||
|
Subroutine
_meta_features: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 76 | 14 | my $self = shift; | |||||||||||||||||||
| 77 | 14 | my $all_features = $self->meta->get_all_features; | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 14 | my @features; | |||||||||||||||||||
| 80 | 14 | for my $feature_name (keys %$all_features) { | |||||||||||||||||||
| 81 | 7 | my $feature_options = $all_features->{ $feature_name }; | |||||||||||||||||||
| 82 | 7 | my $feature_class = Form::Factory->feature_class($feature_name); | |||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 7 | my $feature = $feature_class->new( | |||||||||||||||||||
| 85 | %$feature_options, | ||||||||||||||||||||
| 86 | action => $self, | ||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||
| 88 | 7 | push @features, $feature; | |||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 14 | return \@features; | |||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 14 | ▶ | sub _init_features { | ||||||||||||||||||
|
Subroutine
_init_features: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 95 | 14 | my ($self, $features, $set, $attr) = @_; | |||||||||||||||||||
| 96 | 14 | push @$features, @{ $self->_meta_features }; | |||||||||||||||||||
| 97 | 14 | $set->($features); | |||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 1 | has controls => ( | |||||||||||||||||||
| 102 | is => 'ro', | ||||||||||||||||||||
| 103 | isa => 'HashRef', | ||||||||||||||||||||
| 104 | required => 1, | ||||||||||||||||||||
| 105 | lazy => 1, | ||||||||||||||||||||
| 106 | builder => '_build_controls', | ||||||||||||||||||||
| 107 | ); | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 14 | ▶ | sub _build_controls { | ||||||||||||||||||
|
Subroutine
_build_controls: called CC=11 SCAR=24.0
| |||||||||||||||||||||
| 110 | 14 | my $self = shift; | |||||||||||||||||||
| 111 | 14 | my $interface = $self->form_interface; | |||||||||||||||||||
| 112 | 14 | my $features = $self->features; | |||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 14 | my %controls; | |||||||||||||||||||
| 115 | 14 | my @meta_controls = $self->meta->get_controls; | |||||||||||||||||||
| 116 | 14 | for my $meta_control (@meta_controls) { | |||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | # Construct any deferred options | ||||||||||||||||||||
| 119 | 75 | my %options = %{ $meta_control->options }; | |||||||||||||||||||
| 120 | 75 | OPTION: for my $key (keys %options) { | |||||||||||||||||||
| 121 | 27 | my $value = $options{$key}; | |||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 27 | ▶ | next OPTION unless blessed $value; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 124 | 1 | ▶ | next OPTION unless $value->isa('Form::Factory::Processor::DeferredValue'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 1 | $options{$key} = $value->code->($self, $key); | |||||||||||||||||||
| 127 | } | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | # Build the control constructor arguments | ||||||||||||||||||||
| 130 | 75 | my $control_name = $meta_control->name; | |||||||||||||||||||
| 131 | 75 | ▶ | my %control_args = ( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 132 | control => $meta_control->control, | ||||||||||||||||||||
| 133 | options => { | ||||||||||||||||||||
| 134 | name => $control_name, | ||||||||||||||||||||
| 135 | action => $self, | ||||||||||||||||||||
| 136 | ($meta_control->has_documentation | ||||||||||||||||||||
| 137 | ? (documentation => $meta_control->documentation) : ()), | ||||||||||||||||||||
| 138 | %options, | ||||||||||||||||||||
| 139 | }, | ||||||||||||||||||||
| 140 | ); | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | # Let any BuildControl features modify the constructor arguments | ||||||||||||||||||||
| 143 | 75 | my %feature_classes; | |||||||||||||||||||
| 144 | 75 | my $meta_features = $meta_control->features; | |||||||||||||||||||
| 145 | 75 | for my $feature_name (keys %$meta_features) { | |||||||||||||||||||
| 146 | 46 | my $feature_class = Form::Factory->control_feature_class($feature_name); | |||||||||||||||||||
| 147 | 46 | $feature_classes{$feature_name} = $feature_class; | |||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | 46 | ▶ | next unless $feature_class->does('Form::Factory::Feature::Role::BuildControl'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | $feature_class->build_control( | ||||||||||||||||||||
| 152 | 1 | $meta_features->{$feature_name}, $self, $control_name, \%control_args | |||||||||||||||||||
| 153 | ); | ||||||||||||||||||||
| 154 | } | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | # Construct the control | ||||||||||||||||||||
| 157 | my $control = $interface->new_control( | ||||||||||||||||||||
| 158 | $control_args{control} => $control_args{options}, | ||||||||||||||||||||
| 159 | 75 | ); | |||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | # Construct and attach the features for the control | ||||||||||||||||||||
| 162 | 75 | my @init_control_features; | |||||||||||||||||||
| 163 | 75 | for my $feature_name (keys %$meta_features) { | |||||||||||||||||||
| 164 | 46 | my $feature_class = $feature_classes{$feature_name}; | |||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | my $feature = $feature_class->new( | ||||||||||||||||||||
| 167 | 46 | %{ $meta_features->{$feature_name} }, | |||||||||||||||||||
| 168 | action => $self, | ||||||||||||||||||||
| 169 | control => $control, | ||||||||||||||||||||
| 170 | ); | ||||||||||||||||||||
| 171 | 46 | push @$features, $feature; | |||||||||||||||||||
| 172 | 46 | push @{ $control->features }, $feature; | |||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | 46 | ▶ | push @init_control_features, $feature | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 175 | if $feature->does('Form::Factory::Feature::Role::InitializeControl'); | ||||||||||||||||||||
| 176 | } | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | # Have InitializeControl features work on the constructed control | ||||||||||||||||||||
| 179 | 75 | for my $feature (@init_control_features) { | |||||||||||||||||||
| 180 | 8 | $feature->initialize_control; | |||||||||||||||||||
| 181 | } | ||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | # Add the control to the list | ||||||||||||||||||||
| 184 | 75 | $controls{ $meta_control->name } = $control; | |||||||||||||||||||
| 185 | } | ||||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | 14 | return \%controls; | |||||||||||||||||||
| 188 | } | ||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | |||||||||||||||||||||
| 191 | 0 | ▶ | sub stash { | ||||||||||||||||||
|
Subroutine
stash: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 192 | 0 | my ($self, $moniker) = @_; | |||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | 0 | my $controls = $self->controls; | |||||||||||||||||||
| 195 | 0 | my %controls; | |||||||||||||||||||
| 196 | 0 | for my $control_name (keys %$controls) { | |||||||||||||||||||
| 197 | 0 | my $control = $controls->{ $control_name }; | |||||||||||||||||||
| 198 | 0 | $controls{$control_name}{value} = $control->value; | |||||||||||||||||||
| 199 | } | ||||||||||||||||||||
| 200 | |||||||||||||||||||||
| 201 | 0 | my %stash = ( | |||||||||||||||||||
| 202 | globals => $self->globals, | ||||||||||||||||||||
| 203 | controls => \%controls, | ||||||||||||||||||||
| 204 | results => $self->results, | ||||||||||||||||||||
| 205 | result => $self->result, | ||||||||||||||||||||
| 206 | ); | ||||||||||||||||||||
| 207 | |||||||||||||||||||||
| 208 | 0 | $self->form_interface->stash($moniker => \%stash); | |||||||||||||||||||
| 209 | } | ||||||||||||||||||||
| 210 | |||||||||||||||||||||
| 211 | |||||||||||||||||||||
| 212 | 0 | ▶ | sub unstash { | ||||||||||||||||||
|
Subroutine
unstash: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||
| 213 | 0 | my ($self, $moniker) = @_; | |||||||||||||||||||
| 214 | |||||||||||||||||||||
| 215 | 0 | my $stash = $self->form_interface->unstash($moniker); | |||||||||||||||||||
| 216 | 0 | ▶ | return unless defined $stash; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 217 | |||||||||||||||||||||
| 218 | 0 | ▶ | my $globals = $stash->{globals} || {}; | ||||||||||||||||||
|
Condition0%0/2
$stash->{'globals'} || {}
MC/DC0%0/1
$stash->{'globals'} || {}
$stash->{'globals'}
Truth table0%0/2
A
A= $stash->{'globals'}
| |||||||||||||||||||||
| 219 | 0 | for my $key (keys %$globals) { | |||||||||||||||||||
| 220 | 0 | $self->globals->{$key} = $globals->{$key}; | |||||||||||||||||||
| 221 | } | ||||||||||||||||||||
| 222 | |||||||||||||||||||||
| 223 | 0 | my $controls = $self->controls; | |||||||||||||||||||
| 224 | 0 | ▶ | my $controls_state = $stash->{controls} || {}; | ||||||||||||||||||
|
Condition0%0/2
$stash->{'controls'} || {}
MC/DC0%0/1
$stash->{'controls'} || {}
$stash->{'controls'}
Truth table0%0/2
A
A= $stash->{'controls'}
| |||||||||||||||||||||
| 225 | 0 | for my $control_name (keys %$controls) { | |||||||||||||||||||
| 226 | 0 | my $state = $controls_state->{$control_name}; | |||||||||||||||||||
| 227 | 0 | my $control = $controls->{$control_name}; | |||||||||||||||||||
| 228 | 0 | eval { $control->value($state->{value}) }; | |||||||||||||||||||
| 229 | } | ||||||||||||||||||||
| 230 | |||||||||||||||||||||
| 231 | 0 | ▶ | $self->results($stash->{results} || Form::Factory::Result::Gathered->new); | ||||||||||||||||||
|
Condition0%0/3
$stash->{'results'} || 'Form::Factory::Result::Gathered'->new
MC/DC0%0/2
$stash->{'results'} || 'Form::Factory::Result::Gathered'->new
$stash->{'results'}
'Form::Factory::Result::Gathered'->new
Truth table0%0/3
A || B
A= $stash->{'results'}B= 'Form::Factory::Result::Gathered'->new
| |||||||||||||||||||||
| 232 | 0 | ▶ | $self->result($stash->{result} || Form::Factory::Result::Single->new); | ||||||||||||||||||
|
Condition0%0/3
$stash->{'result'} || 'Form::Factory::Result::Single'->new
MC/DC0%0/2
$stash->{'result'} || 'Form::Factory::Result::Single'->new
$stash->{'result'}
'Form::Factory::Result::Single'->new
Truth table0%0/3
A || B
A= $stash->{'result'}B= 'Form::Factory::Result::Single'->new
| |||||||||||||||||||||
| 233 | } | ||||||||||||||||||||
| 234 | |||||||||||||||||||||
| 235 | |||||||||||||||||||||
| 236 | 21 | ▶ | sub clear { | ||||||||||||||||||
|
Subroutine
clear: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 237 | 21 | my ($self) = @_; | |||||||||||||||||||
| 238 | |||||||||||||||||||||
| 239 | 21 | %{ $self->globals } = (); | |||||||||||||||||||
| 240 | |||||||||||||||||||||
| 241 | 21 | my $controls = $self->controls; | |||||||||||||||||||
| 242 | 21 | for my $control_name (keys %$controls) { | |||||||||||||||||||
| 243 | 141 | my $control = $controls->{ $control_name }; | |||||||||||||||||||
| 244 | 141 | delete $control->{value}; | |||||||||||||||||||
| 245 | } | ||||||||||||||||||||
| 246 | |||||||||||||||||||||
| 247 | 21 | $self->results->clear_all; | |||||||||||||||||||
| 248 | 21 | $self->result(Form::Factory::Result::Single->new); | |||||||||||||||||||
| 249 | } | ||||||||||||||||||||
| 250 | |||||||||||||||||||||
| 251 | |||||||||||||||||||||
| 252 | 1 | ▶ | sub render { | ||||||||||||||||||
|
Subroutine
render: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||
| 253 | 1 | my $self = shift; | |||||||||||||||||||
| 254 | 1 | my %params = @_; | |||||||||||||||||||
| 255 | 0 | my @names = defined $params{controls} ? @{ delete $params{controls} } | |||||||||||||||||||
| 256 | 1 | ▶ | : map { $_->name } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 257 | $self->meta->get_controls | ||||||||||||||||||||
| 258 | ; | ||||||||||||||||||||
| 259 | |||||||||||||||||||||
| 260 | 1 | $params{results} = $self->results; | |||||||||||||||||||
| 261 | |||||||||||||||||||||
| 262 | 1 | my $controls = $self->controls; | |||||||||||||||||||
| 263 | 1 | $self->form_interface->render_control($controls->{$_}, %params) for @names; | |||||||||||||||||||
| 264 | 1 | return; | |||||||||||||||||||
| 265 | } | ||||||||||||||||||||
| 266 | |||||||||||||||||||||
| 267 | |||||||||||||||||||||
| 268 | 0 | ▶ | sub setup_and_render { | ||||||||||||||||||
|
Subroutine
setup_and_render: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 269 | 0 | my ($self, %options) = @_; | |||||||||||||||||||
| 270 | |||||||||||||||||||||
| 271 | 0 | $self->unstash($options{moniker}); | |||||||||||||||||||
| 272 | 0 | ▶ | my %globals = %{ $options{globals} || {} }; | ||||||||||||||||||
|
Condition0%0/2
$options{'globals'} || {}
MC/DC0%0/1
$options{'globals'} || {}
$options{'globals'}
Truth table0%0/2
A
A= $options{'globals'}
| |||||||||||||||||||||
| 273 | 0 | for my $key (keys %globals) { | |||||||||||||||||||
| 274 | 0 | $self->globals->{$key} = $globals{$key}; | |||||||||||||||||||
| 275 | } | ||||||||||||||||||||
| 276 | 0 | $self->render(%options); | |||||||||||||||||||
| 277 | 0 | $self->results->clear_all; | |||||||||||||||||||
| 278 | 0 | $self->stash($options{moniker}); | |||||||||||||||||||
| 279 | |||||||||||||||||||||
| 280 | 0 | return; | |||||||||||||||||||
| 281 | } | ||||||||||||||||||||
| 282 | |||||||||||||||||||||
| 283 | |||||||||||||||||||||
| 284 | 1 | ▶ | sub render_control { | ||||||||||||||||||
|
Subroutine
render_control: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 285 | 1 | my ($self, $name, $options, %params) = @_; | |||||||||||||||||||
| 286 | |||||||||||||||||||||
| 287 | 1 | ▶ | my %options = %{ $options || {} }; | ||||||||||||||||||
|
Condition50%1/2
$options || {}
MC/DC0%0/1
$options || {}
$options
Truth table50%1/2
A
A= $options
| |||||||||||||||||||||
| 288 | 1 | $options{action} = $self; | |||||||||||||||||||
| 289 | |||||||||||||||||||||
| 290 | 1 | $params{results} = $self->results; | |||||||||||||||||||
| 291 | |||||||||||||||||||||
| 292 | 1 | my $interface = $self->form_interface; | |||||||||||||||||||
| 293 | 1 | my $control = $interface->new_control($name => \%options); | |||||||||||||||||||
| 294 | |||||||||||||||||||||
| 295 | 1 | $interface->render_control($control, %params); | |||||||||||||||||||
| 296 | |||||||||||||||||||||
| 297 | 1 | return $control; | |||||||||||||||||||
| 298 | } | ||||||||||||||||||||
| 299 | |||||||||||||||||||||
| 300 | |||||||||||||||||||||
| 301 | 36 | ▶ | sub consume { | ||||||||||||||||||
|
Subroutine
consume: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 302 | 36 | my $self = shift; | |||||||||||||||||||
| 303 | 36 | my %params = @_; | |||||||||||||||||||
| 304 | 15 | my @names = defined $params{controls} ? @{ delete $params{controls} } | |||||||||||||||||||
| 305 | 36 | ▶ | : map { $_->name } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 306 | $self->meta->get_controls | ||||||||||||||||||||
| 307 | ; | ||||||||||||||||||||
| 308 | |||||||||||||||||||||
| 309 | 36 | my $controls = $self->controls; | |||||||||||||||||||
| 310 | 36 | $self->form_interface->consume_control($controls->{$_}, %params) for @names; | |||||||||||||||||||
| 311 | } | ||||||||||||||||||||
| 312 | |||||||||||||||||||||
| 313 | |||||||||||||||||||||
| 314 | 2 | ▶ | sub consume_control { | ||||||||||||||||||
|
Subroutine
consume_control: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 315 | 2 | my ($self, $name, $options, %params) = @_; | |||||||||||||||||||
| 316 | |||||||||||||||||||||
| 317 | 2 | ▶ | my %options = %{ $options || {} }; | ||||||||||||||||||
|
Condition50%1/2
$options || {}
MC/DC0%0/1
$options || {}
$options
Truth table50%1/2
A
A= $options
| |||||||||||||||||||||
| 318 | 2 | $options{action} = $self; | |||||||||||||||||||
| 319 | |||||||||||||||||||||
| 320 | 2 | $params{results} = $self->results; | |||||||||||||||||||
| 321 | |||||||||||||||||||||
| 322 | 2 | my $interface = $self->form_interface; | |||||||||||||||||||
| 323 | 2 | my $control = $interface->new_control($name => \%options); | |||||||||||||||||||
| 324 | |||||||||||||||||||||
| 325 | 2 | $interface->consume_control($control, %params); | |||||||||||||||||||
| 326 | |||||||||||||||||||||
| 327 | 2 | return $control; | |||||||||||||||||||
| 328 | } | ||||||||||||||||||||
| 329 | |||||||||||||||||||||
| 330 | |||||||||||||||||||||
| 331 | { | ||||||||||||||||||||
| 332 | 82 | ▶ | sub _run_features { | ||||||||||||||||||
|
Subroutine
_run_features: called CC=8 SCAR=20.8
| |||||||||||||||||||||
| 333 | 82 | my $self = shift; | |||||||||||||||||||
| 334 | 82 | my $method = shift; | |||||||||||||||||||
| 335 | 82 | my %params = @_; | |||||||||||||||||||
| 336 | 82 | my $features = $self->features; | |||||||||||||||||||
| 337 | |||||||||||||||||||||
| 338 | # Only run the requested control-specific features | ||||||||||||||||||||
| 339 | 82 | ▶ | if (defined $params{controls}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 340 | 30 | my %names = map { $_ => 1 } @{ $params{controls} }; | |||||||||||||||||||
| 341 | |||||||||||||||||||||
| 342 | 30 | for my $feature (@$features) { | |||||||||||||||||||
| 343 | 210 | ▶ | next unless $feature->does('Form::Factory::Feature::Role::Control'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 344 | 210 | ▶ | next unless $feature->does( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 345 | Form::Factory::_class_name_from_name('Feature::Role', $method) | ||||||||||||||||||||
| 346 | ); | ||||||||||||||||||||
| 347 | 90 | ▶ | next unless $names{ $feature->control->name }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 348 | |||||||||||||||||||||
| 349 | 15 | $feature->$method; | |||||||||||||||||||
| 350 | } | ||||||||||||||||||||
| 351 | } | ||||||||||||||||||||
| 352 | |||||||||||||||||||||
| 353 | # Run all features now | ||||||||||||||||||||
| 354 | else { | ||||||||||||||||||||
| 355 | 52 | for my $feature (@$features) { | |||||||||||||||||||
| 356 | 104 | ▶ | next unless $feature->does( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 357 | Form::Factory::_class_name_from_name('Feature::Role', $method) | ||||||||||||||||||||
| 358 | ); | ||||||||||||||||||||
| 359 | |||||||||||||||||||||
| 360 | 51 | $feature->$method; | |||||||||||||||||||
| 361 | } | ||||||||||||||||||||
| 362 | } | ||||||||||||||||||||
| 363 | } | ||||||||||||||||||||
| 364 | } | ||||||||||||||||||||
| 365 | |||||||||||||||||||||
| 366 | 1 | ▶ | sub clean { | ||||||||||||||||||
|
Subroutine
clean: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 367 | 36 | my $self = shift; | |||||||||||||||||||
| 368 | 36 | $self->_run_features(clean => @_); | |||||||||||||||||||
| 369 | } | ||||||||||||||||||||
| 370 | |||||||||||||||||||||
| 371 | |||||||||||||||||||||
| 372 | 36 | ▶ | sub check { | ||||||||||||||||||
|
Subroutine
check: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 373 | 36 | my $self = shift; | |||||||||||||||||||
| 374 | 36 | $self->_run_features(check => @_); | |||||||||||||||||||
| 375 | |||||||||||||||||||||
| 376 | 36 | $self->gather_results; | |||||||||||||||||||
| 377 | } | ||||||||||||||||||||
| 378 | |||||||||||||||||||||
| 379 | |||||||||||||||||||||
| 380 | 7 | ▶ | sub process { | ||||||||||||||||||
|
Subroutine
process: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 381 | 7 | my $self = shift; | |||||||||||||||||||
| 382 | 7 | ▶ | return unless $self->is_valid; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 383 | |||||||||||||||||||||
| 384 | 5 | $self->set_attributes_from_controls; | |||||||||||||||||||
| 385 | |||||||||||||||||||||
| 386 | 5 | $self->_run_features('pre_process'); | |||||||||||||||||||
| 387 | 5 | $self->run; | |||||||||||||||||||
| 388 | 5 | $self->_run_features('post_process'); | |||||||||||||||||||
| 389 | |||||||||||||||||||||
| 390 | 5 | $self->gather_results; | |||||||||||||||||||
| 391 | |||||||||||||||||||||
| 392 | 5 | my @errors = $self->error_messages; | |||||||||||||||||||
| 393 | 5 | $self->result->is_success(@errors == 0); | |||||||||||||||||||
| 394 | } | ||||||||||||||||||||
| 395 | |||||||||||||||||||||
| 396 | |||||||||||||||||||||
| 397 | 7 | ▶ | sub consume_and_clean_and_check_and_process { | ||||||||||||||||||
|
Subroutine
consume_and_clean_and_check_and_process: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 398 | 7 | my $self = shift; | |||||||||||||||||||
| 399 | 7 | $self->consume(@_); | |||||||||||||||||||
| 400 | 7 | $self->clean; | |||||||||||||||||||
| 401 | 7 | $self->check; | |||||||||||||||||||
| 402 | 7 | $self->process; | |||||||||||||||||||
| 403 | } | ||||||||||||||||||||
| 404 | |||||||||||||||||||||
| 405 | |||||||||||||||||||||
| 406 | 0 | ▶ | sub set_attribute_from_control { | ||||||||||||||||||
|
Subroutine
set_attribute_from_control: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 407 | 0 | my ($self, $name) = @_; | |||||||||||||||||||
| 408 | 0 | my $meta = $self->meta; | |||||||||||||||||||
| 409 | |||||||||||||||||||||
| 410 | 0 | my $control = $self->control->{$name}; | |||||||||||||||||||
| 411 | 0 | my $attribute = $meta->find_attribute_by_name($name); | |||||||||||||||||||
| 412 | 0 | $control->set_attribute_value($self, $attribute); | |||||||||||||||||||
| 413 | } | ||||||||||||||||||||
| 414 | |||||||||||||||||||||
| 415 | |||||||||||||||||||||
| 416 | 5 | ▶ | sub set_attributes_from_controls { | ||||||||||||||||||
|
Subroutine
set_attributes_from_controls: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 417 | 5 | my $self = shift; | |||||||||||||||||||
| 418 | 5 | my $meta = $self->meta; | |||||||||||||||||||
| 419 | |||||||||||||||||||||
| 420 | 5 | my $controls = $self->controls; | |||||||||||||||||||
| 421 | 5 | ▶ | while (my ($name, $control) = each %$controls) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 422 | 21 | my $attribute = $meta->find_attribute_by_name($name); | |||||||||||||||||||
| 423 | 21 | ▶ | Carp::croak("attribute for control $name not found on $self") | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 424 | unless defined $attribute; | ||||||||||||||||||||
| 425 | 21 | $control->set_attribute_value($self, $attribute); | |||||||||||||||||||
| 426 | } | ||||||||||||||||||||
| 427 | } | ||||||||||||||||||||
| 428 | |||||||||||||||||||||
| 429 | |||||||||||||||||||||
| 430 | 41 | ▶ | sub gather_results { | ||||||||||||||||||
|
Subroutine
gather_results: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 431 | 41 | my $self = shift; | |||||||||||||||||||
| 432 | 41 | my $controls = $self->controls; | |||||||||||||||||||
| 433 | $self->results->gather_results( | ||||||||||||||||||||
| 434 | $self->result, | ||||||||||||||||||||
| 435 | 41 | map { $_->result } @{ $self->features } | |||||||||||||||||||
| 436 | ); | ||||||||||||||||||||
| 437 | } | ||||||||||||||||||||
| 438 | |||||||||||||||||||||
| 439 | |||||||||||||||||||||
| 440 | 1 | 1; | |||||||||||||||||||
| 441 | |||||||||||||||||||||
| 442 | __END__ | ||||||||||||||||||||