Revision cbbcefbb
Von Sven Schöling vor etwa 14 Jahren hinzugefügt
SL/DB/Helpers/AttrPercent.pm | ||
---|---|---|
12 | 12 |
|
13 | 13 |
$params{places} = 2 if !defined($params{places}); |
14 | 14 |
|
15 |
my $code = <<CODE; |
|
16 |
package ${package}; |
|
15 |
no strict 'refs'; |
|
16 |
*{ $package . '::' . $attribute . '_as_percent' } = sub { |
|
17 |
my ($self, $string) = @_; |
|
17 | 18 |
|
18 |
sub ${attribute}_as_percent { |
|
19 |
my \$self = shift; |
|
19 |
$self->$attribute($::form->parse_amount(\%::myconfig, $string) / 100) if @_ > 1; |
|
20 | 20 |
|
21 |
if (scalar \@_) { |
|
22 |
\$self->${attribute}(\$::form->parse_amount(\\\%::myconfig, \$_[0]) / 100); |
|
23 |
} |
|
24 |
|
|
25 |
return \$::form->format_amount(\\\%::myconfig, 100 * \$self->${attribute}, $params{places}); |
|
26 |
} |
|
27 |
|
|
28 |
1; |
|
29 |
CODE |
|
30 |
|
|
31 |
eval $code; |
|
32 |
croak "Defining '${attribute}_as_number' failed: $EVAL_ERROR" if $EVAL_ERROR; |
|
21 |
return $::form->format_amount(\%::myconfig, 100 * $self->$attribute, $params{places}); |
|
22 |
}; |
|
33 | 23 |
|
34 | 24 |
return 1; |
35 | 25 |
} |
Auch abrufbar als: Unified diff
Attr Helper umgeschrieben auf dnamisch registrierte coderefs.