some boiler plate docs
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Field.pm
1 package Reaction::UI::ViewPort::Field;
2
3 use Reaction::Class;
4 use aliased 'Reaction::InterfaceModel::Object';
5 use aliased 'Reaction::Meta::InterfaceModel::Object::ParameterAttribute';
6
7 class Field is 'Reaction::UI::ViewPort', which {
8
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);
13
14   has model     => (is => 'ro', isa => Object,             required => 1);
15   has attribute => (is => 'ro', isa => ParameterAttribute, required => 1);
16
17   implements adopt_value => as {};
18
19   implements _build_name => as { shift->attribute->name };
20   implements _build_value_string => as { shift->value };
21
22   implements _build_label => as {
23     join(' ', map { ucfirst } split('_', shift->name));
24   };
25
26   #unlazify and move it to build. to deal with array use typeconstraints and coercions
27   implements _build_value => as {
28     my ($self) = @_;
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?
32     return $self->model->$reader ; #if (!$predicate || $self->model->$predicate);
33
34     print STDERR "weird!\n";
35     return;
36   };
37
38 };
39
40 1;
41 __END__;
42
43 =head1 NAME
44
45 Reaction::UI::ViewPort::Field
46
47 =head1 DESCRIPTION
48
49 =head1 ATTRIBUTES
50
51 =head2 model
52
53 =head2 attribute
54
55 =head2 value
56
57 =head2 name
58
59 =head2 label
60
61 =head2 value_string
62
63 =head1 AUTHORS
64
65 See L<Reaction::Class> for authors.
66
67 =head1 LICENSE
68
69 See L<Reaction::Class> for the license.
70
71 =cut