| 1 | package Ftree::DataParsers::ExcelFormat; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use version; our $VERSION = qv('2.3.41'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Spreadsheet::ParseExcel; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | use Ftree::DataParsers::ExtendedSimonWardFormat | ||||||||||||||||||||||||||||
| 8 | 2 | ▶ | ; # for getting pictures. Temporal solution | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Ftree::FamilyTreeData; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | # use CGI::Carp qw(fatalsToBrowser); | ||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Encode qw(decode); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | sub createFamilyTreeDataFromFile { | ||||||||||||||||||||||||||
|
Subroutine
createFamilyTreeDataFromFile: called CC=10 SCAR=23.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 2 | my ($config_) = @_; | |||||||||||||||||||||||||||
| 15 | my $file_name = $config_->{file_name} | ||||||||||||||||||||||||||||
| 16 | 2 | ▶ | or die "No file_name is given in config"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | my $family_tree_data = Ftree::FamilyTreeData->new(); | |||||||||||||||||||||||||||
| 19 | 2 | ▶ | my $excel = Spreadsheet::ParseExcel::Workbook->Parse($file_name) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | or die "Unable to parse file " . $file_name; | ||||||||||||||||||||||||||||
| 21 | 2 | foreach my $sheet ( @{ $excel->{Worksheet} } ) { | |||||||||||||||||||||||||||
| 22 | 1 | ▶ | $sheet->{MaxRow} ||= $sheet->{MinRow}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$sheet->{"MaxRow"} ||= $sheet->{"MinRow"}
MC/DC0%0/2
$sheet->{"MaxRow"} ||= $sheet->{"MinRow"}
$sheet->{"MaxRow"}
$sheet->{"MinRow"}
Truth table33%1/3
A ||= B
A= $sheet->{"MaxRow"}B= $sheet->{"MinRow"}
| |||||||||||||||||||||||||||||
| 23 | 1 | foreach my $row ( $sheet->{MinRow} + 1 .. $sheet->{MaxRow} ) { | |||||||||||||||||||||||||||
| 24 | my $tempperson = { | ||||||||||||||||||||||||||||
| 25 | id => convertCell( $sheet->{Cells}[$row][0] ), | ||||||||||||||||||||||||||||
| 26 | first_name => convertCell( $sheet->{Cells}[$row][3] ), | ||||||||||||||||||||||||||||
| 27 | mid_name => convertCell( $sheet->{Cells}[$row][4] ), | ||||||||||||||||||||||||||||
| 28 | last_name => convertCell( $sheet->{Cells}[$row][5] ), | ||||||||||||||||||||||||||||
| 29 | title => convertCell( $sheet->{Cells}[$row][1] ), | ||||||||||||||||||||||||||||
| 30 | prefix => convertCell( $sheet->{Cells}[$row][2] ), | ||||||||||||||||||||||||||||
| 31 | suffix => convertCell( $sheet->{Cells}[$row][6] ), | ||||||||||||||||||||||||||||
| 32 | nickname => convertCell( $sheet->{Cells}[$row][7] ), | ||||||||||||||||||||||||||||
| 33 | father_id => convertCell( $sheet->{Cells}[$row][8] ), | ||||||||||||||||||||||||||||
| 34 | mother_id => convertCell( $sheet->{Cells}[$row][9] ), | ||||||||||||||||||||||||||||
| 35 | email => convertCell( $sheet->{Cells}[$row][10] ), | ||||||||||||||||||||||||||||
| 36 | homepage => convertCell( $sheet->{Cells}[$row][11] ), | ||||||||||||||||||||||||||||
| 37 | date_of_birth => convertCell( $sheet->{Cells}[$row][12] ), | ||||||||||||||||||||||||||||
| 38 | date_of_death => convertCell( $sheet->{Cells}[$row][13] ), | ||||||||||||||||||||||||||||
| 39 | gender => convertCell( $sheet->{Cells}[$row][14] ), | ||||||||||||||||||||||||||||
| 40 | is_living => convertCell( $sheet->{Cells}[$row][15] ), | ||||||||||||||||||||||||||||
| 41 | place_of_birth => convertCell( $sheet->{Cells}[$row][16] ), | ||||||||||||||||||||||||||||
| 42 | place_of_death => convertCell( $sheet->{Cells}[$row][17] ), | ||||||||||||||||||||||||||||
| 43 | cemetery => convertCell( $sheet->{Cells}[$row][18] ), | ||||||||||||||||||||||||||||
| 44 | schools => ( defined $sheet->{Cells}[$row][19] ) | ||||||||||||||||||||||||||||
| 45 | ? [ split( /,/, convertCell( $sheet->{Cells}[$row][19] ) ) ] | ||||||||||||||||||||||||||||
| 46 | : undef, | ||||||||||||||||||||||||||||
| 47 | jobs => ( defined $sheet->{Cells}[$row][20] ) | ||||||||||||||||||||||||||||
| 48 | ? [ split( /,/, convertCell( $sheet->{Cells}[$row][20] ) ) ] | ||||||||||||||||||||||||||||
| 49 | : undef, | ||||||||||||||||||||||||||||
| 50 | work_places => ( defined $sheet->{Cells}[$row][21] ) | ||||||||||||||||||||||||||||
| 51 | ? [ split( /,/, convertCell( $sheet->{Cells}[$row][21] ) ) ] | ||||||||||||||||||||||||||||
| 52 | : undef, | ||||||||||||||||||||||||||||
| 53 | places_of_living => convertCell( $sheet->{Cells}[$row][22] ), | ||||||||||||||||||||||||||||
| 54 | 15 | ▶ | general => convertCell( $sheet->{Cells}[$row][23] ) | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 55 | }; | ||||||||||||||||||||||||||||
| 56 | 15 | $family_tree_data->add_person($tempperson); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 2 | ▶ | if ( defined $config_->{photo_dir} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 2 | Ftree::DataParsers::ExtendedSimonWardFormat::setPictureDirectory( $config_->{photo_dir} ); | |||||||||||||||||||||||||||
| 61 | 2 | Ftree::DataParsers::ExtendedSimonWardFormat::fill_up_pictures($family_tree_data); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 2 | return $family_tree_data; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 328 | ▶ | sub convertCell { | ||||||||||||||||||||||||||
|
Subroutine
convertCell: called CC=9 SCAR=24.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | 328 | my ($cell) = @_; | |||||||||||||||||||||||||||
| 69 | 328 | ▶ | return undef unless defined $cell; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 134 | my $rowtxt = ''; | |||||||||||||||||||||||||||
| 71 | 134 | ▶ | if ( !$cell ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | $rowtxt = "\t"; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # next; | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 134 | my $val = $cell->{Val}; | |||||||||||||||||||||||||||
| 77 | 134 | ▶ | if ( !defined($val) or $val eq '' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $val or $val eq ""
MC/DC0%0/2
not defined $val or $val eq ""
not defined $val
$val eq ""
Truth table33%1/3
not(A) or B
A= not defined $valB= $val eq ""
| |||||||||||||||||||||||||||||
| 78 | 0 | $rowtxt = "\t"; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | # next; | ||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 134 | ▶ | if (defined $val){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 134 | ▶ | if ( defined $cell->{Code} && $cell->{Code} eq 'ucs2' ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $cell->{"Code"} and $cell->{"Code"} eq "ucs2"
MC/DC50%1/2
defined $cell->{"Code"} and $cell->{"Code"} eq "ucs2"
defined $cell->{"Code"}
$cell->{"Code"} eq "ucs2"
Truth table66%2/3
A and B
A= defined $cell->{"Code"}B= $cell->{"Code"} eq "ucs2"
| |||||||||||||||||||||||||||||
| 84 | 1 | $val = decode( "UTF-16BE", $val ); | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 134 | $val =~ s/^\s+//; | |||||||||||||||||||||||||||
| 87 | 134 | $val =~ s/\s+$//; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | 134 | ▶ | if ( $val eq '' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | $rowtxt = "\t"; | |||||||||||||||||||||||||||
| 91 | 0 | next; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 134 | $rowtxt = "$val"; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 134 | return $rowtxt; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | # return $cell->{Val} if( $cell->{Type} eq "Numeric" ); | ||||||||||||||||||||||||||||
| 98 | # return $cell->{Val} unless( defined $cell->{Code} ); | ||||||||||||||||||||||||||||
| 99 | # use Encode qw(decode encode); | ||||||||||||||||||||||||||||
| 100 | # $characters = decode('UTF-8', $octets, Encode::FB_CROAK); | ||||||||||||||||||||||||||||
| 101 | # return decode('UTF-8',$cell->{Val},Encode::FB_CROAK);#decode('UTF-16LE', $cell->{Val}); | ||||||||||||||||||||||||||||
| 102 | # Encode::from_to( $cell->{Val}, "utf8", "utf16le" ); | ||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 2 | 1; | |||||||||||||||||||||||||||