aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/UI/ViewPort/DisplayField/Boolean.pm
blob: 9389436cf684747f6294d420075054f09404b983 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package Reaction::UI::ViewPort::DisplayField::Boolean;

use Reaction::Class;
use aliased 'Reaction::UI::ViewPort::DisplayField';

class Boolean, is DisplayField, which {
    has '+value' => (isa => 'Bool');
    has '+layout' => (default => 'displayfield/value_string');

    has value_string => (isa => 'Str', is => 'rw', lazy_build => 1);

    has value_string_format =>
        (isa => 'HashRef', is => 'rw', required => 1,
         default => sub { {true => 'Yes', false => 'No'} }
  );

  implements build_value_string => as {
    my $self = shift;
    my $val = $self->value;
    if(!defined $val || $val eq "" || "$val" eq '0'){
        return $self->value_string_format->{false};
    } elsif("$val" eq '1'){
        return $self->value_string_format->{true};
    } else{  #this will hopefully never happen
        confess "Not supporting some type of Bool value";
    }
  };

};

1;