[Moscow.pm] refactoring

Victor Efimov victor на vsespb.ru
Чт Окт 15 00:53:45 PDT 2015


примерно так:

 push @person_row, (defined $person->get_father()) ?
$person->get_father()->get_id() : undef;

на

push @person_row, map { defined ? $_->get_id : undef }
($person->get_father(), $person->get_mother()))

и

      $date .= defined $date_of_birth->day ? $date_of_birth->day."/" : "";
      $date .= defined $date_of_birth->month ? $date_of_birth->month."/" : "";
      $date .= defined $date_of_birth->year ? $date_of_birth->year : "";

на

for ($date_of_birth) {
   join ("/", map { $_ ? $_ : () } ($_->day, $_->month, $_->year_))
}


(не тестировал)


15 октября 2015 г., 5:43 пользователь Nikolay Mishin <mi на ya.ru> написал:
> Hi Moscow.PM!
>
> Существует ли какой-либо сбособ сделать более читаемым такой код?:
>
>     push @person_row, (defined $person->get_father()) ? $person->get_father()->get_id() : undef;
>     push @person_row, (defined $person->get_mother()) ? $person->get_mother()->get_id() : undef;
>     push @person_row, ($person->get_email(), $person->get_homepage());
>
>     my $date = "";
>     if(defined $person->get_date_of_birth()) {
>       my $date_of_birth = $person->get_date_of_birth();
>       $date .= defined $date_of_birth->day ? $date_of_birth->day."/" : "";
>       $date .= defined $date_of_birth->month ? $date_of_birth->month."/" : "";
>       $date .= defined $date_of_birth->year ? $date_of_birth->year : "";
>     }
>
> источник https://github.com/mishin/Ftree-cpan/blob/master/lib/Ftree/Exporters/ExcelExporter.pm#L53
>
> --
> С уважением
> Николай Мишин
>
> --
> Moscow.pm mailing list
> moscow-pm на pm.org | http://moscow.pm.org


Подробная информация о списке рассылки Moscow-pm