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_fail => 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 adopt_value => as {};
19 implements _build_name => as { shift->attribute->name };
21 implements _build_value_string => as {
23 return $self->has_value? $self->value : '';
26 implements _build_label => as {
27 join(' ', map { ucfirst } split('_', shift->name));
30 implements BUILD => as {
32 my $reader = $self->attribute->get_read_method;
33 my $predicate = $self->attribute->predicate;
35 if (!$predicate || $self->model->$predicate
36 || ($self->attribute->is_lazy
37 && !$self->attribute->is_lazy_fail)
39 my $value = $self->model->$reader;
40 if ( $self->attribute->is_required ) {
41 $self->value($value) if defined $value;
56 Reaction::UI::ViewPort::Field
76 See L<Reaction::Class> for authors.
80 See L<Reaction::Class> for the license.