aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/UI/ViewPort/Field.pm
blob: d8d504a2233747da534037e8d33fb79385745c6b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package Reaction::UI::ViewPort::Field;

use Reaction::Class;
use aliased 'Reaction::InterfaceModel::Object';
use aliased 'Reaction::Meta::InterfaceModel::Object::ParameterAttribute';

class Field is 'Reaction::UI::ViewPort', which {

  has value        => (is => 'rw', lazy_build => 1);
  has name         => (is => 'rw', isa => 'Str', lazy_build => 1);
  has label        => (is => 'rw', isa => 'Str', lazy_build => 1);
  has value_string => (is => 'rw', isa => 'Str', lazy_build => 1);

  has model     => (is => 'ro', isa => Object,             required => 1);
  has attribute => (is => 'ro', isa => ParameterAttribute, required => 1);

  implements adopt_value => as {};

  implements _build_name => as { shift->attribute->name };
  implements _build_value_string => as { shift->value };

  implements _build_label => as {
    join(' ', map { ucfirst } split('_', shift->name));
  };

  #unlazify and move it to build. to deal with array use typeconstraints and coercions
  implements _build_value => as {
    my ($self) = @_;
    my $reader = $self->attribute->get_read_method;
    my $predicate = $self->attribute->predicate;
    #this is bound to blow the fuck if !model->$predicate what to do?
    return $self->model->$reader if (!$predicate || $self->model->$predicate);
    return;
  };

};

1;