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);
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 _build_name => as { shift->attribute->name };
19 implements _build_label => as {
20 join(' ', map { ucfirst } split('_', shift->name));
23 implements _build_value => as {
25 my $reader = $self->attribute->get_read_method;
26 return $self->model->$reader;
29 implements _model_has_value => as {
31 my $predicate = $self->attribute->predicate;
33 if (!$predicate || $self->model->$predicate
34 || ($self->attribute->is_lazy
35 && !$self->attribute->is_lazy_fail)
37 # either model attribute has a value now or can build it
43 implements _build_value_string => as {
45 # XXX need the defined test because the IM lazy builds from
46 # the model and DBIC can have nullable fields and DBIC doesn't
47 # have a way to tell us that doesn't force value inflation (extra
48 # SELECTs for belongs_to) so basically we're screwed.
49 return ($self->_model_has_value && defined($self->value)
50 ? $self->_value_string_from_value
51 : $self->_empty_string_value);
54 implements _value_string_from_value => as {
58 implements _empty_string_value => as { '' };
60 implements value_is_required => as {
61 shift->attribute->is_required;
71 Reaction::UI::ViewPort::Field
91 See L<Reaction::Class> for authors.
95 See L<Reaction::Class> for the license.