Commit | Line | Data |
7adfd53f |
1 | package Reaction::UI::ViewPort::DisplayField; |
2 | |
3 | use Reaction::Class; |
4 | |
5 | class 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 | |
d7b00a50 |
47 | implements 'value_string' => as { shift->value }; |
48 | |
7adfd53f |
49 | }; |
50 | |
51 | 1; |
52 | |
53 | =head1 NAME |
54 | |
55 | Reaction::UI::ViewPort::DisplayField |
56 | |
57 | =head1 DESCRIPTION |
58 | |
59 | Base class for displaying non user-editable fields. |
60 | |
61 | =head1 ATTRIBUTES |
62 | |
63 | =head2 name |
64 | |
65 | =head2 object |
66 | |
67 | L<Reaction::InterfaceModel::Object> |
68 | |
69 | =head2 attribute |
70 | |
71 | L<Reaction::Meta::InterfaceModel::Object::ParameterAttribute> |
72 | |
73 | =head2 value |
74 | |
75 | =head2 label |
76 | |
77 | User friendly label, by default is based on the name. |
78 | |
79 | =head1 SEE ALSO |
80 | |
81 | L<Reaction::UI::ViewPort> |
82 | |
83 | =head1 AUTHORS |
84 | |
85 | See L<Reaction::Class> for authors. |
86 | |
87 | =head1 LICENSE |
88 | |
89 | See L<Reaction::Class> for the license. |
90 | |
91 | =cut |