has model => (is => 'ro', isa => Object, required => 1);
has attribute => (is => 'ro', isa => ParameterAttribute, required => 1);
- implements adopt_value => as {};
-
implements _build_name => as { shift->attribute->name };
- implements _build_value_string => as { shift->value };
implements _build_label => as {
join(' ', map { ucfirst } split('_', shift->name));
};
- #unlazify and move it to build. to deal with array use typeconstraints and coercions
implements _build_value => as {
my ($self) = @_;
my $reader = $self->attribute->get_read_method;
- my $predicate = $self->attribute->predicate;
- #this is bound to blow the fuck if !model->$predicate what to do?
- return $self->model->$reader if (!$predicate || $self->model->$predicate);
- return;
+ return $self->model->$reader;
};
- implements adopt_value => as {
+ implements _model_has_value => as {
my ($self) = @_;
- $self->needs_sync(1) if $self->has_attribute;
- };
-
- implements value_string => as { shift->value };
+ my $predicate = $self->attribute->get_predicate_method;
- implements sync_to_action => as {
- my ($self) = @_;
- return unless $self->needs_sync && $self->has_attribute && $self->has_value;
- my $attr = $self->attribute;
- if (my $tc = $attr->type_constraint) {
- my $value = $self->value;
- if ($tc->has_coercion) {
- $value = $tc->coercion->coerce($value);
- }
- my $error = $tc->validate($self->value);
- if (defined $error) {
- $self->message($error);
- return;
- }
+ if (!$predicate || $self->model->$predicate
+ #|| ($self->attribute->is_lazy
+ # && !$self->attribute->is_lazy_fail)
+ ) {
+ # either model attribute has a value now or can build it
+ return 1;
}
- my $writer = $attr->get_write_method;
- confess "No writer for attribute" unless defined($writer);
- $self->action->$writer($self->value);
- $self->needs_sync(0);
+ return 0;
};
- implements sync_from_action => as {
+ implements _build_value_string => as {
my ($self) = @_;
- return unless !$self->needs_sync && $self->has_attribute;
- $self->message($self->action->error_for($self->attribute)||'');
+ # XXX need the defined test because the IM lazy builds from
+ # the model and DBIC can have nullable fields and DBIC doesn't
+ # have a way to tell us that doesn't force value inflation (extra
+ # SELECTs for belongs_to) so basically we're screwed.
+ return ($self->_model_has_value && defined($self->_build_value)
+ ? $self->_value_string_from_value
+ : $self->_empty_string_value);
+ };
+
+ implements _value_string_from_value => as {
+ shift->value;
};
- override accept_events => sub { ('value', super()) };
+ implements _empty_string_value => as { '' };
+
+ implements value_is_required => as {
+ shift->attribute->is_required;
+ };
};
1;
+__END__;
+
+=head1 NAME
+
+Reaction::UI::ViewPort::Field
+
+=head1 DESCRIPTION
+
+=head1 ATTRIBUTES
+
+=head2 model
+
+=head2 attribute
+
+=head2 value
+
+=head2 name
+
+=head2 label
+
+=head2 value_string
+
+=head1 AUTHORS
+
+See L<Reaction::Class> for authors.
+
+=head1 LICENSE
+
+See L<Reaction::Class> for the license.
+
+=cut