_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;
-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';
+