1 package Reaction::UI::ViewPort::Field;
4 use aliased 'Reaction::InterfaceModel::Object';
5 use aliased 'Reaction::Meta::InterfaceModel::Object::ParameterAttribute';
7 use MooseX::Types::Moose qw/Str/;
9 use namespace::clean -except => [ qw(meta) ];
10 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);
20 sub _build_name { shift->attribute->name };
23 join(' ', map { ucfirst } split('_', shift->name));
28 my $reader = $self->attribute->get_read_method;
29 return $self->model->$reader;
32 sub _model_has_value {
34 my $predicate = $self->attribute->get_predicate_method;
36 if (!$predicate || $self->model->$predicate
37 # || ($self->attribute->is_lazy
38 # && !$self->attribute->is_lazy_fail)
40 # edenc -- uncommented the lazy checks above
41 # model->$predicate returns false if the value isn't set
42 # but has a lazy builder
44 # either model attribute has a value now or can build it
50 sub _build_value_string {
52 # XXX need the defined test because the IM lazy builds from
53 # the model and DBIC can have nullable fields and DBIC doesn't
54 # have a way to tell us that doesn't force value inflation (extra
55 # SELECTs for belongs_to) so basically we're screwed.
56 return ($self->_model_has_value && defined($self->_build_value)
57 ? $self->_value_string_from_value
58 : $self->_empty_string_value);
61 sub _value_string_from_value {
65 sub _empty_string_value { '' }
67 sub value_is_required {
69 $self->model->attribute_is_required($self->attribute);
72 __PACKAGE__->meta->make_immutable;
80 Reaction::UI::ViewPort::Field
100 See L<Reaction::Class> for authors.
104 See L<Reaction::Class> for the license.