Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 8944e415

Von Sven Schöling vor fast 13 Jahren hinzugefügt

  • ID 8944e41547df93c8b25943938bb42ddec101fc16
  • Vorgänger 4f42c5f0
  • Nachfolger abd4a0b0

_bool_yn accessor

Unterschiede anzeigen:

SL/DB/Helper/Attr.pm
33 33
  _as_percent($package, $name, places =>  2) if $type =~ /numeric | real | float/xi;
34 34
  _as_number ($package, $name, places =>  0) if $type =~ /int/xi;
35 35
  _as_date   ($package, $name)               if $type =~ /date | timestamp/xi;
36
  _as_bool_yn($package, $name)               if $type =~ /bool/xi;
36 37
}
37 38

  
38 39
sub _as_number {
......
104 105
  return 1;
105 106
}
106 107

  
108
sub _as_bool_yn {
109
  my ($package, $attribute, %params) = @_;
110

  
111
  no strict 'refs';
112
  *{ $package . '::' . $attribute . '_as_bool_yn' } = sub {
113
    my ($self) = @_;
114

  
115
    if (@_ > 1) {
116
      die 'not an accessor';
117
    }
118

  
119
    return !defined $self->$attribute ? ''
120
         :          $self->$attribute ? $::locale->text('Yes')
121
         :                              $::locale->text('No');
122
  }
123
}
124

  
107 125
1;
108 126

  
109 127

  
t/helper/attr.t
1
use Test::More tests => 29;
1
use Test::More tests => 32;
2 2

  
3 3
use lib 't';
4 4

  
......
50 50
$i->netamount(10.34);
51 51
is($i->taxamount_as_number, '1,66');
52 52

  
53
$o->closed(1);
54
is $o->closed_as_bool_yn, 'Ja', 'bool 1';
55
$o->closed(0);
56
is $o->closed_as_bool_yn, 'Nein', 'bool 2';
57

  
58
# undef test: this only works for columns without default, rose will set
59
# defaults according to the database
60
$i->taxincluded(undef);
61
is $i->taxincluded_as_bool_yn, '', 'bool 3';
62

  

Auch abrufbar als: Unified diff