Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision cbbcefbb

Von Sven Schöling vor etwa 14 Jahren hinzugefügt

  • ID cbbcefbbb1b2b58752bd9dd9d374c6092323ef27
  • Vorgänger 82515b2d
  • Nachfolger 3af1d16a

Attr Helper umgeschrieben auf dnamisch registrierte coderefs.

Unterschiede anzeigen:

SL/DB/Helpers/AttrNumber.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_number' } = sub {
17
    my ($self, $string) = @_;
17 18

  
18
sub ${attribute}_as_number {
19
  my \$self = shift;
19
    $self->$attribute($::form->parse_amount(\%::myconfig, $string)) if @_ > 1;
20 20

  
21
  if (scalar \@_) {
22
    \$self->${attribute}(\$::form->parse_amount(\\\%::myconfig, \$_[0]));
23
  }
24

  
25
  return \$::form->format_amount(\\\%::myconfig, \$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, $self->$attribute, $params{places});
22
  };
33 23

  
34 24
  return 1;
35 25
}

Auch abrufbar als: Unified diff