r62507@cain (orig r402): groditi | 2007-11-14 18:33:11 +0000
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / DisplayField.pm
CommitLineData
7adfd53f 1package Reaction::UI::ViewPort::DisplayField;
2
3use Reaction::Class;
4
5class DisplayField is 'Reaction::UI::ViewPort', which {
6
7 has name => (
8 isa => 'Str', is => 'rw', required => 1
9 );
10
11 has object => (
12 isa => 'Reaction::InterfaceModel::Object',
13 is => 'ro', required => 0, predicate => 'has_object',
14 );
15
16 has attribute => (
17 isa => 'Reaction::Meta::InterfaceModel::Object::ParameterAttribute',
18 is => 'ro', predicate => 'has_attribute',
19 );
20
21 has value => (
22 is => 'rw', lazy_build => 1, trigger_adopt('value'),
7adfd53f 23 );
24
25 has label => (isa => 'Str', is => 'rw', lazy_build => 1);
26
27 implements BUILD => as {
28 my ($self) = @_;
29 if (!$self->has_attribute != !$self->has_object) {
30 confess "Should have both object and attribute or neither"; }
31 };
32
89939ff9 33 implements _build_label => as {
7adfd53f 34 my ($self) = @_;
35 return join(' ', map { ucfirst } split('_', $self->name));
36 };
37
89939ff9 38 implements _build_value => as {
7adfd53f 39 my ($self) = @_;
40 if ($self->has_attribute) {
41 my $reader = $self->attribute->get_read_method;
42 return $self->object->$reader;
43 }
44 return '';
45 };
46
47};
48
491;
50
51=head1 NAME
52
53Reaction::UI::ViewPort::DisplayField
54
55=head1 DESCRIPTION
56
57Base class for displaying non user-editable fields.
58
59=head1 ATTRIBUTES
60
61=head2 name
62
63=head2 object
64
65L<Reaction::InterfaceModel::Object>
66
67=head2 attribute
68
69L<Reaction::Meta::InterfaceModel::Object::ParameterAttribute>
70
71=head2 value
72
73=head2 label
74
75User friendly label, by default is based on the name.
76
77=head1 SEE ALSO
78
79L<Reaction::UI::ViewPort>
80
81=head1 AUTHORS
82
83See L<Reaction::Class> for authors.
84
85=head1 LICENSE
86
87See L<Reaction::Class> for the license.
88
89=cut