1 package Reaction::UI::ViewPort::Field;
4 use aliased 'Reaction::InterfaceModel::Object';
5 use aliased 'Reaction::Meta::InterfaceModel::Object::ParameterAttribute';
7 class Field is 'Reaction::UI::ViewPort', which {
9 has value => (is => 'rw', lazy_build => 1, clearer => 'clear_value');
10 has name => (is => 'rw', isa => 'Str', lazy_build => 1);
11 has label => (is => 'rw', isa => 'Str', lazy_build => 1);
12 has value_string => (is => 'rw', isa => 'Str', lazy_build => 1);
14 has model => (is => 'ro', isa => Object, required => 1);
15 has attribute => (is => 'ro', isa => ParameterAttribute, required => 1);
17 implements adopt_value => as {};
19 implements _build_name => as { shift->attribute->name };
21 implements _build_label => as {
22 join(' ', map { ucfirst } split('_', shift->name));
25 implements _build_value => as {
27 my $reader = $self->attribute->get_read_method;
28 return $self->model->$reader;
31 implements _model_has_value => as {
33 my $predicate = $self->attribute->predicate;
35 if (!$predicate || $self->model->$predicate
36 || ($self->attribute->is_lazy
37 && !$self->attribute->is_lazy_fail)
39 # either model attribute has a value now or can build it
45 implements _build_value_string => as {
47 # XXX need the defined test because the IM lazy builds from
48 # the model and DBIC can have nullable fields and DBIC doesn't
49 # have a way to tell us that doesn't force value inflation (extra
50 # SELECTs for belongs_to) so basically we're screwed.
51 return ($self->_model_has_value && defined($self->value)
52 ? $self->_value_string_from_value
53 : $self->_empty_string_value);
56 implements _value_string_from_value => as {
60 implements _empty_string_value => as { '' };
69 Reaction::UI::ViewPort::Field
89 See L<Reaction::Class> for authors.
93 See L<Reaction::Class> for the license.