1 package Reaction::InterfaceModel::Search::UpdateSpec;
4 use Method::Signatures::Simple;
5 use aliased 'Reaction::InterfaceModel::Search::Spec', 'SearchSpec';
6 use namespace::clean -except => 'meta';
8 has '+target_model' => (isa => SearchSpec);
10 requires '_reflection_info';
12 override BUILDARGS => method () {
14 my $model = $args->{target_model};
15 my $reflected = $self->_reflection_info;
16 foreach my $attr (@{$reflected->{empty}||[]}) {
17 if ($model->${\"has_${attr}"}) {
18 $args->{$attr} = $model->$attr;
23 foreach my $attr (@{$reflected->{normal}||[]}) {
24 my $has = $model->can("has_${attr}")||sub {1};
25 $args->{$attr} = $model->$attr if $model->$has;
31 my $data = $self->parameter_hashref;
32 my $spec = $self->target_model;
33 foreach my $name (keys %$data) {
34 # note: this assumes plain is => 'rw' attrs on the backend
35 # which is safe since we control it. Also, we assume '' means
36 # clear - this may not be safe later but is for now
37 if (length(my $value = $data->{$name})) {
40 $spec->${\"clear_${name}"};