- $params{places} = 2 if !defined($params{places});
-
- my $code = <<CODE;
-package ${package};
-
-sub ${attribute}_as_date {
- my \$self = shift;
-
- if (scalar \@_) {
- if (\$_[0]) {
- my (\$yy, \$mm, \$dd) = \$::locale->parse_date(\\\%::myconfig, \@_);
- \$self->${attribute}(DateTime->new(year => \$yy, month => \$mm, day => \$dd));
- } else {
- \$self->${attribute}(undef);
+ no strict 'refs';
+ *{ $package . '::' . $attribute . '_as_date' } = sub {
+ my ($self, $string) = @_;
+
+ if (@_ > 1) {
+ if ($string) {
+ my ($yy, $mm, $dd) = $::locale->parse_date(\%::myconfig, $string);
+ $self->$attribute(DateTime->new(year => $yy, month => $mm, day => $dd));
+ } else {
+ $self->$attribute(undef);
+ }