Revision 8944e415
Von Sven Schöling vor etwa 13 Jahren hinzugefügt
SL/DB/Helper/Attr.pm | ||
---|---|---|
_as_percent($package, $name, places => 2) if $type =~ /numeric | real | float/xi;
|
||
_as_number ($package, $name, places => 0) if $type =~ /int/xi;
|
||
_as_date ($package, $name) if $type =~ /date | timestamp/xi;
|
||
_as_bool_yn($package, $name) if $type =~ /bool/xi;
|
||
}
|
||
|
||
sub _as_number {
|
||
... | ... | |
return 1;
|
||
}
|
||
|
||
sub _as_bool_yn {
|
||
my ($package, $attribute, %params) = @_;
|
||
|
||
no strict 'refs';
|
||
*{ $package . '::' . $attribute . '_as_bool_yn' } = sub {
|
||
my ($self) = @_;
|
||
|
||
if (@_ > 1) {
|
||
die 'not an accessor';
|
||
}
|
||
|
||
return !defined $self->$attribute ? ''
|
||
: $self->$attribute ? $::locale->text('Yes')
|
||
: $::locale->text('No');
|
||
}
|
||
}
|
||
|
||
1;
|
||
|
||
|
t/helper/attr.t | ||
---|---|---|
use Test::More tests => 29;
|
||
use Test::More tests => 32;
|
||
|
||
use lib 't';
|
||
|
||
... | ... | |
$i->netamount(10.34);
|
||
is($i->taxamount_as_number, '1,66');
|
||
|
||
$o->closed(1);
|
||
is $o->closed_as_bool_yn, 'Ja', 'bool 1';
|
||
$o->closed(0);
|
||
is $o->closed_as_bool_yn, 'Nein', 'bool 2';
|
||
|
||
# undef test: this only works for columns without default, rose will set
|
||
# defaults according to the database
|
||
$i->taxincluded(undef);
|
||
is $i->taxincluded_as_bool_yn, '', 'bool 3';
|
||
|
Auch abrufbar als: Unified diff
_bool_yn accessor