Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision c75d178e

Von Moritz Bunkus vor fast 12 Jahren hinzugefügt

  • ID c75d178e3cb42a605b4498cc498532f007a7f0d7
  • Vorgänger 30c8e51b
  • Nachfolger 1d0a5eee

Record-Presenter: robustere Typenprüfung

Unterschiede anzeigen:

SL/Presenter/Record.pm
71 71

  
72 72
      my $method       =  $spec->{column} || $spec->{data};
73 73
      my $meta         =  $column_meta{ $spec->{data} };
74
      my $type         =  lc ref $meta;
75
      $type            =~ s/.*:://;
74
      my $type         =  ref $meta;
76 75
      my $relationship =  $relationships{ $spec->{data} };
77 76
      my $rel_type     =  !$relationship ? '' : lc $relationship->class;
78
      $rel_type        =~ s/.*:://;
77
      $rel_type        =~ s/^sl::db:://;
79 78

  
80 79
      if (ref($spec->{data}) eq 'CODE') {
81 80
        $cell{value} = $spec->{data}->($obj);
82 81

  
83 82
      } else {
84
        $cell{value} = $rel_type eq 'customer'        ? $self->customer($obj->$method, display => 'table-cell')
85
                     : $rel_type eq 'vendor'          ? $self->vendor(  $obj->$method, display => 'table-cell')
86
                     : $rel_type eq 'project'         ? $self->project( $obj->$method, display => 'table-cell')
87
                     : $type eq 'date'                ? $call->($obj, $method . '_as_date')
88
                     : $type =~ m/float|numeric|real/ ? $::form->format_amount(\%::myconfig, $call->($obj, $method), 2)
89
                     : $type eq 'boolean'             ? $call->($obj, $method . '_as_bool_yn')
90
                     : $type =~ m/int|serial/         ? $spec->{data} * 1
91
                     :                                  $call->($obj, $method);
83
        $cell{value} = $rel_type && $self->can($rel_type)                                       ? $self->$rel_type($obj->$method, display => 'table-cell')
84
                     : $type eq 'Rose::DB::Object::Metadata::Column::Date'                      ? $call->($obj, $method . '_as_date')
85
                     : $type =~ m/^Rose::DB::Object::Metadata::Column::(?:Float|Numeric|Real)$/ ? $::form->format_amount(\%::myconfig, $call->($obj, $method), 2)
86
                     : $type eq 'Rose::DB::Object::Metadata::Column::Boolean'                   ? $call->($obj, $method . '_as_bool_yn')
87
                     : $type =~ m/^Rose::DB::Object::Metadata::Column::(?:Integer|Serial)$/     ? $spec->{data} * 1
88
                     :                                                                            $call->($obj, $method);
92 89
      }
93 90

  
94 91
      $cell{alignment} = 'right' if $type =~ m/int|serial|float|real|numeric/;

Auch abrufbar als: Unified diff