Commit | Line | Data |
7adfd53f |
1 | package Reaction::UI::ViewPort::Field; |
2 | |
3 | use Reaction::Class; |
ddccc6a2 |
4 | use aliased 'Reaction::InterfaceModel::Object'; |
5 | use aliased 'Reaction::Meta::InterfaceModel::Object::ParameterAttribute'; |
7adfd53f |
6 | |
7 | class Field is 'Reaction::UI::ViewPort', which { |
8 | |
ddccc6a2 |
9 | has value => (is => 'rw', lazy_build => 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); |
7adfd53f |
13 | |
ddccc6a2 |
14 | has model => (is => 'ro', isa => Object, required => 1); |
15 | has attribute => (is => 'ro', isa => ParameterAttribute, required => 1); |
7adfd53f |
16 | |
ddccc6a2 |
17 | implements adopt_value => as {}; |
7adfd53f |
18 | |
ddccc6a2 |
19 | implements _build_name => as { shift->attribute->name }; |
20 | implements _build_value_string => as { shift->value }; |
7adfd53f |
21 | |
89939ff9 |
22 | implements _build_label => as { |
ddccc6a2 |
23 | join(' ', map { ucfirst } split('_', shift->name)); |
7adfd53f |
24 | }; |
25 | |
ddccc6a2 |
26 | #unlazify and move it to build. to deal with array use typeconstraints and coercions |
89939ff9 |
27 | implements _build_value => as { |
7adfd53f |
28 | my ($self) = @_; |
ddccc6a2 |
29 | my $reader = $self->attribute->get_read_method; |
30 | my $predicate = $self->attribute->predicate; |
31 | #this is bound to blow the fuck if !model->$predicate what to do? |
c03f75a7 |
32 | return $self->model->$reader ; #if (!$predicate || $self->model->$predicate); |
33 | |
34 | print STDERR "weird!\n"; |
ddccc6a2 |
35 | return; |
7adfd53f |
36 | }; |
37 | |
7adfd53f |
38 | }; |
39 | |
40 | 1; |