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 # FIXME - has '+attr' broken, copied from Reaction::InterfaceModel::Action
9 #has '+target_model' => (isa => SearchSpec);
14 metaclass => 'Reaction::Meta::Attribute'
17 requires '_reflection_info';
19 override BUILDARGS => method () {
21 my $model = $args->{target_model};
22 my $reflected = $self->_reflection_info;
23 foreach my $attr (@{$reflected->{empty}||[]}) {
24 if ($model->${\"has_${attr}"}) {
25 $args->{$attr} = $model->$attr;
30 foreach my $attr (@{$reflected->{normal}||[]}) {
31 my $has = $model->can("has_${attr}")||sub {1};
32 $args->{$attr} = $model->$attr if $model->$has;
38 my $data = $self->parameter_hashref;
39 my $spec = $self->target_model;
40 foreach my $name (keys %$data) {
41 # note: this assumes plain is => 'rw' attrs on the backend
42 # which is safe since we control it. Also, we assume '' means
43 # clear - this may not be safe later but is for now
44 if (length(my $value = $data->{$name})) {
47 $spec->${\"clear_${name}"};