1 package Reaction::UI::ViewPort::Field;
4 use aliased 'Reaction::InterfaceModel::Object';
5 use aliased 'Reaction::Meta::InterfaceModel::Object::ParameterAttribute';
7 use namespace::clean -except => [ qw(meta) ];
8 extends 'Reaction::UI::ViewPort';
12 has value => (is => 'rw', lazy_build => 1);
13 has name => (is => 'rw', isa => 'Str', lazy_build => 1);
14 has label => (is => 'rw', isa => 'Str', lazy_build => 1);
15 has value_string => (is => 'rw', isa => 'Str', lazy_build => 1);
17 has model => (is => 'ro', isa => Object, required => 1);
18 has attribute => (is => 'ro', isa => ParameterAttribute, required => 1);
19 sub _build_name { shift->attribute->name };
21 join(' ', map { ucfirst } split('_', shift->name));
25 my $reader = $self->attribute->get_read_method;
26 return $self->model->$reader;
28 sub _model_has_value {
30 my $predicate = $self->attribute->get_predicate_method;
32 if (!$predicate || $self->model->$predicate
33 #|| ($self->attribute->is_lazy
34 # && !$self->attribute->is_lazy_fail)
36 # either model attribute has a value now or can build it
41 sub _build_value_string {
43 # XXX need the defined test because the IM lazy builds from
44 # the model and DBIC can have nullable fields and DBIC doesn't
45 # have a way to tell us that doesn't force value inflation (extra
46 # SELECTs for belongs_to) so basically we're screwed.
47 return ($self->_model_has_value && defined($self->_build_value)
48 ? $self->_value_string_from_value
49 : $self->_empty_string_value);
51 sub _value_string_from_value {
54 sub _empty_string_value { '' };
55 sub value_is_required {
56 shift->attribute->is_required;
59 __PACKAGE__->meta->make_immutable;
67 Reaction::UI::ViewPort::Field
87 See L<Reaction::Class> for authors.
91 See L<Reaction::Class> for the license.