| 1 | package Ftree::DataParsers::ExtendedSimonWardFormat; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | require Ftree::DataParsers::ArrayImporters::CSVArrayImporter; | |||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use version; our $VERSION = qv('2.3.41'); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Ftree::Name; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Ftree::Picture; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Ftree::FamilyTreeData; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Params::Validate qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Ftree::StringUtils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use v5.10.1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use experimental 'smartmatch'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Ftree::DataParsers::FieldValidatorParser; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | # use CGI::Carp qw(fatalsToBrowser warningsToBrowser); | ||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | my $picture_directory; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub getID { | ||||||||||||||||||||||||||
|
Subroutine
getID: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 23 | 0 | my ($name_with_space) = @_; | |||||||||||||||||||||||||||
| 24 | 0 | $name_with_space =~ s/ /_/g; | |||||||||||||||||||||||||||
| 25 | 0 | return $name_with_space; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub getNameFields { | ||||||||||||||||||||||||||
|
Subroutine
getNameFields: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 0 | my ($full_name) = @_; | |||||||||||||||||||||||||||
| 30 | 0 | $full_name =~ s/[0-9]//g; | |||||||||||||||||||||||||||
| 31 | 0 | my @full_name_a = split( / /, $full_name ); | |||||||||||||||||||||||||||
| 32 | 0 | my $mid_name; | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ( @full_name_a > 2 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 0 | $mid_name = | |||||||||||||||||||||||||||
| 35 | join( ' ', @full_name_a[ 1 .. $#full_name_a - 1 ] ); | ||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | return { | ||||||||||||||||||||||||||||
| 38 | 0 | first_name => $full_name_a[0], | |||||||||||||||||||||||||||
| 39 | mid_name => $mid_name, | ||||||||||||||||||||||||||||
| 40 | last_name => $full_name_a[-1] | ||||||||||||||||||||||||||||
| 41 | }; | ||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 2 | ▶ | sub fill_up_pictures { | ||||||||||||||||||||||||||
|
Subroutine
fill_up_pictures: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | 2 | my ($family_tree_data) = @_; | |||||||||||||||||||||||||||
| 46 | 2 | ▶ | while ( my ( $id, $person ) = each %{ $family_tree_data->{people} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 15 | my $picture_file_name = | |||||||||||||||||||||||||||
| 48 | getPictureFileName( getFileName($id), $picture_directory ); | ||||||||||||||||||||||||||||
| 49 | 15 | ▶ | $person->set_default_picture( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | Ftree::Picture->new( | ||||||||||||||||||||||||||||
| 51 | { | ||||||||||||||||||||||||||||
| 52 | file_name => $picture_file_name, | ||||||||||||||||||||||||||||
| 53 | comment => "" | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | ) | ||||||||||||||||||||||||||||
| 56 | ) if ( defined $picture_file_name ); | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 15 | ▶ | sub getPictureFileName { | ||||||||||||||||||||||||||
|
Subroutine
getPictureFileName: called CC=5 SCAR=17.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 15 | my ($id) = @_; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 15 | ▶ | if ( -e "$picture_directory/$id.jpg" ) { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 64 | 0 | return "$id.jpg"; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | elsif ( -e "$picture_directory/$id.gif" ) { | ||||||||||||||||||||||||||||
| 67 | 2 | return "$id.gif"; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | elsif ( -e "$picture_directory/$id.tif" ) { | ||||||||||||||||||||||||||||
| 70 | 0 | return "$id.tif"; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | elsif ( -e "$picture_directory/$id.png" ) { | ||||||||||||||||||||||||||||
| 73 | 9 | return "$id.png"; | |||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | }; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | else { | ||||||||||||||||||||||||||||
| 79 | 4 | return; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 2 | ▶ | sub setPictureDirectory { | ||||||||||||||||||||||||||
|
Subroutine
setPictureDirectory: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 84 | 2 | my ($picture_directory_) = @_; | |||||||||||||||||||||||||||
| 85 | 2 | $picture_directory = $picture_directory_; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | # return: 0, in case of file open error | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub createFamilyTreeDataFromFile { | ||||||||||||||||||||||||||
|
Subroutine
createFamilyTreeDataFromFile: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 90 | 0 | my ($config_) = @_; | |||||||||||||||||||||||||||
| 91 | my $file_name = $config_->{file_name} | ||||||||||||||||||||||||||||
| 92 | 0 | ▶ | or die "No file_name is given in config"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | my $family_tree_data = Ftree::FamilyTreeData->new(); | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | # default encoding is utf8 | ||||||||||||||||||||||||||||
| 97 | 0 | ▶ | my $encoding = defined $config_->{encoding} ? $config_->{encoding} : "utf8"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | my $arrayImporter = | |||||||||||||||||||||||||||
| 99 | Ftree::DataParsers::ArrayImporters::CSVArrayImporter->new( $file_name, | ||||||||||||||||||||||||||||
| 100 | $encoding ); | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | while ( $arrayImporter->hasNext() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | my @fields = $arrayImporter->next(); | |||||||||||||||||||||||||||
| 103 | 0 | @fields = map { Ftree::StringUtils::trim($_) } @fields; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | my $name_ref = getNameFields( $fields[0] ); | |||||||||||||||||||||||||||
| 106 | 0 | ▶ | my ( $date_of_birth, $date_of_death ) = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | defined $fields[5] ? split( /-/, $fields[5], 2 ) : ( undef, undef ); | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | my $temp_person = $family_tree_data->add_person( | ||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||
| 111 | id => getID( $fields[0] ), | ||||||||||||||||||||||||||||
| 112 | first_name => $name_ref->{first_name}, | ||||||||||||||||||||||||||||
| 113 | mid_name => $name_ref->{mid_name}, | ||||||||||||||||||||||||||||
| 114 | last_name => $name_ref->{last_name}, | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | title => $fields[7], | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 116 | prefix => $fields[8], | ||||||||||||||||||||||||||||
| 117 | suffix => $fields[9], | ||||||||||||||||||||||||||||
| 118 | nickname => $fields[10], | ||||||||||||||||||||||||||||
| 119 | father_id => getID( $fields[1] ), | ||||||||||||||||||||||||||||
| 120 | mother_id => getID( $fields[2] ), | ||||||||||||||||||||||||||||
| 121 | email => $fields[3], | ||||||||||||||||||||||||||||
| 122 | homepage => $fields[4], | ||||||||||||||||||||||||||||
| 123 | date_of_birth => $date_of_birth, | ||||||||||||||||||||||||||||
| 124 | date_of_death => $date_of_death, | ||||||||||||||||||||||||||||
| 125 | gender => $fields[6], | ||||||||||||||||||||||||||||
| 126 | is_living => $fields[11], | ||||||||||||||||||||||||||||
| 127 | place_of_birth => $fields[12], | ||||||||||||||||||||||||||||
| 128 | place_of_death => $fields[13], | ||||||||||||||||||||||||||||
| 129 | cemetery => $fields[14], | ||||||||||||||||||||||||||||
| 130 | schools => ( defined $fields[15] ) | ||||||||||||||||||||||||||||
| 131 | ? [ split( /,/, $fields[15] ) ] | ||||||||||||||||||||||||||||
| 132 | : undef, | ||||||||||||||||||||||||||||
| 133 | jobs => ( defined $fields[16] ) ? [ split( /,/, $fields[16] ) ] | ||||||||||||||||||||||||||||
| 134 | : undef, | ||||||||||||||||||||||||||||
| 135 | work_places => ( defined $fields[17] ) | ||||||||||||||||||||||||||||
| 136 | ? [ split( /,/, $fields[17] ) ] | ||||||||||||||||||||||||||||
| 137 | : undef, | ||||||||||||||||||||||||||||
| 138 | places_of_living => $fields[18], | ||||||||||||||||||||||||||||
| 139 | general => $fields[19] | ||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if ( defined $temp_person->get_father() | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $temp_person->get_father and not defined $temp_person->get_father->get_name
MC/DC0%0/2
defined $temp_person->get_father and not defined $temp_person->get_father->get_name
defined $temp_person->get_father
not defined $temp_person->get_father->get_name
Truth table0%0/3
A and not(B)
A= defined $temp_person->get_fatherB= not defined $temp_person->get_father->get_name
| |||||||||||||||||||||||||||||
| 143 | && !defined $temp_person->get_father()->get_name() ) | ||||||||||||||||||||||||||||
| 144 | { | ||||||||||||||||||||||||||||
| 145 | 0 | $temp_person->get_father() | |||||||||||||||||||||||||||
| 146 | ->set_name( Ftree::Name->new( getNameFields( $fields[1] ) ) ); | ||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | 0 | ▶ | if ( defined $temp_person->get_mother() | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $temp_person->get_mother and not defined $temp_person->get_mother->get_name
MC/DC0%0/2
defined $temp_person->get_mother and not defined $temp_person->get_mother->get_name
defined $temp_person->get_mother
not defined $temp_person->get_mother->get_name
Truth table0%0/3
A and not(B)
A= defined $temp_person->get_motherB= not defined $temp_person->get_mother->get_name
| |||||||||||||||||||||||||||||
| 149 | && !defined $temp_person->get_mother()->get_name() ) | ||||||||||||||||||||||||||||
| 150 | { | ||||||||||||||||||||||||||||
| 151 | 0 | $temp_person->get_mother() | |||||||||||||||||||||||||||
| 152 | ->set_name( Ftree::Name->new( getNameFields( $fields[2] ) ) ); | ||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | 0 | $arrayImporter->close(); | |||||||||||||||||||||||||||
| 156 | 0 | ▶ | if ( defined $config_->{photo_dir} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 0 | setPictureDirectory( $config_->{photo_dir} ); | |||||||||||||||||||||||||||
| 158 | 0 | fill_up_pictures($family_tree_data); | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | return $family_tree_data; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | ####################################################### | ||||||||||||||||||||||||||||
| 165 | # converts a name to a filename | ||||||||||||||||||||||||||||
| 166 | # (converts spaces, converts case) | ||||||||||||||||||||||||||||
| 167 | # CHANGE: we dont remove middle name: $newname =~ s/ .* / /; | ||||||||||||||||||||||||||||
| 168 | # | ||||||||||||||||||||||||||||
| 169 | 15 | ▶ | sub getFileName { | ||||||||||||||||||||||||||
|
Subroutine
getFileName: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 170 | 15 | my ($id) = @_; | |||||||||||||||||||||||||||
| 171 | 15 | $id =~ s/ /_/g; | |||||||||||||||||||||||||||
| 172 | 15 | $id =~ tr/A-Z/a-z/; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | # $id =~ tr/[á,é,ó,ö,ő,ú,ü,ű,í,Á,É,Ó,Ö,Ő,Ú,Ü,Ű,Í]/ | ||||||||||||||||||||||||||||
| 175 | # [a,e,o,o,o,u,u,u,i,a,e,o,o,o,u,u,u,i]/; #IT DOES NOT WORK?!? | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | # This works: | ||||||||||||||||||||||||||||
| 178 | 15 | $id =~ s/á/a/g; | |||||||||||||||||||||||||||
| 179 | 15 | $id =~ s/ä/a/g; | |||||||||||||||||||||||||||
| 180 | 15 | $id =~ s/é/e/g; | |||||||||||||||||||||||||||
| 181 | 15 | $id =~ s/ó/o/g; | |||||||||||||||||||||||||||
| 182 | 15 | $id =~ s/ö/o/g; | |||||||||||||||||||||||||||
| 183 | 15 | $id =~ s/ő/o/g; | |||||||||||||||||||||||||||
| 184 | 15 | $id =~ s/ú/u/g; | |||||||||||||||||||||||||||
| 185 | 15 | $id =~ s/ü/u/g; | |||||||||||||||||||||||||||
| 186 | 15 | $id =~ s/ű/u/g; | |||||||||||||||||||||||||||
| 187 | 15 | $id =~ s/í/i/g; | |||||||||||||||||||||||||||
| 188 | 15 | $id =~ s/Á/a/g; | |||||||||||||||||||||||||||
| 189 | 15 | $id =~ s/É/e/g; | |||||||||||||||||||||||||||
| 190 | 15 | $id =~ s/Ó/o/g; | |||||||||||||||||||||||||||
| 191 | 15 | $id =~ s/Ö/o/g; | |||||||||||||||||||||||||||
| 192 | 15 | $id =~ s/Ő/o/g; | |||||||||||||||||||||||||||
| 193 | 15 | $id =~ s/Ú/u/g; | |||||||||||||||||||||||||||
| 194 | 15 | $id =~ s/Ü/u/g; | |||||||||||||||||||||||||||
| 195 | 15 | $id =~ s/Ű/u/g; | |||||||||||||||||||||||||||
| 196 | 15 | $id =~ s/Í/i/g; | |||||||||||||||||||||||||||
| 197 | 15 | $id =~ s/ß/b/g; | |||||||||||||||||||||||||||
| 198 | 15 | return $id; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 2 | 1; | |||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||