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';
10 has value => (is => 'rw', lazy_build => 1);
11 has name => (is => 'rw', isa => 'Str', lazy_build => 1);
12 has label => (is => 'rw', isa => 'Str', lazy_build => 1);
13 has value_string => (is => 'rw', isa => 'Str', lazy_build => 1);
15 has model => (is => 'ro', isa => Object, required => 1);
16 has attribute => (is => 'ro', isa => ParameterAttribute, required => 1);
18 sub _build_name { shift->attribute->name };
21 join(' ', map { ucfirst } split('_', shift->name));
26 my $reader = $self->attribute->get_read_method;
27 return $self->model->$reader;
30 sub _model_has_value {
32 my $predicate = $self->attribute->get_predicate_method;
34 if (!$predicate || $self->model->$predicate
35 # || ($self->attribute->is_lazy
36 # && !$self->attribute->is_lazy_fail)
38 # edenc -- uncommented the lazy checks above
39 # model->$predicate returns false if the value isn't set
40 # but has a lazy builder
42 # either model attribute has a value now or can build it
48 sub _build_value_string {
50 # XXX need the defined test because the IM lazy builds from
51 # the model and DBIC can have nullable fields and DBIC doesn't
52 # have a way to tell us that doesn't force value inflation (extra
53 # SELECTs for belongs_to) so basically we're screwed.
54 return ($self->_model_has_value && defined($self->_build_value)
55 ? $self->_value_string_from_value
56 : $self->_empty_string_value);
59 sub _value_string_from_value {
63 sub _empty_string_value { '' }
65 sub value_is_required {
67 $self->model->attribute_is_required($self->attribute);
70 __PACKAGE__->meta->make_immutable;
78 Reaction::UI::ViewPort::Field
98 See L<Reaction::Class> for authors.
102 See L<Reaction::Class> for the license.