branching for lazy_build changes
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / DisplayField / Boolean.pm
1 package Reaction::UI::ViewPort::DisplayField::Boolean;
2
3 use Reaction::Class;
4 use aliased 'Reaction::UI::ViewPort::DisplayField';
5
6 class Boolean, is DisplayField, which {
7     has '+value' => (isa => 'Bool');
8     #has '+layout' => (default => 'displayfield/value_string');
9
10     has value_string => (isa => 'Str', is => 'rw', lazy_build => 1);
11
12     has value_string_format =>
13         (isa => 'HashRef', is => 'rw', required => 1,
14          default => sub { {true => 'Yes', false => 'No'} }
15   );
16
17   implements build_value_string => as {
18     my $self = shift;
19     my $val = $self->value;
20     if(!defined $val || $val eq "" || "$val" eq '0'){
21         return $self->value_string_format->{false};
22     } elsif("$val" eq '1'){
23         return $self->value_string_format->{true};
24     } else{  #this will hopefully never happen
25         confess "Not supporting some type of Bool value";
26     }
27   };
28
29 };
30
31 1;