blib/lib/Gedcom/Record.pm

filter: Statementstmt 85.2% 278 / 326 Branchbran 71.7% 132 / 184 Conditioncond 69.3% 70 / 101 MC/DCmcdc 48.3% 29 / 60 Subroutinesub 85.2% 29 / 34 Podpod 76.1% 16 / 21 totaltotal 76.3% 554 / 726 CC 151 SCAR 27.1
CC
151
Cov
79%
parse
30.6
summary
30.0
validate_syntax
25.1
CRAP 15.0
« blib/lib/Gedcom/LifeLines.pm ↑ Summary parse_grammar »
1 # Copyright 1998-2019, Paul Johnson (paul@pjcj.net)
2  
3 # This software is free. It is licensed under the same terms as Perl itself.
4  
5 # The latest version of this software should be available from my homepage:
6 # http://www.pjcj.net
7  
8 # documentation at __END__
9  
10 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 15 require 5.005;
13  
14 package Gedcom::Record;
15  
16 15 ▶use vars qw($VERSION @ISA $AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 15 $VERSION = "1.21";
18 15 @ISA = qw( Gedcom::Item );
19  
20 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 15 ▶BEGIN { eval "use Date::Manip" } # We'll use this if it is available
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 15 ▶use Gedcom::Item 1.21;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 15 ▶use Gedcom::Comparison 1.21;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 BEGIN
27 {
28 15 ▶ use subs keys %Gedcom::Funcs;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 15 ▶ *tag_record = \&Gedcom::Item::get_item;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 15 *delete_record = \&Gedcom::Item::delete_item;
31 15 *get_record = \&record;
32 }
33  
34 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
35  
36 sub AUTOLOAD {
37 26 ▶ my ($self) = @_; # don't change @_ because of the goto
Subroutine AUTOLOAD: called CC=2 SCAR=7.0
38 26 my $func = $AUTOLOAD;
39 # print "autoloading $func\n";
40 26 $func =~ s/^.*:://;
41 26 ▶ carp "Undefined subroutine $func called" unless $Gedcom::Funcs{lc $func};
Branch: 1 branch
BranchTrueFalseTotal
unless $Gedcom::Funcs{lc $func} 0 26 26
42 15 ▶ no strict "refs";
Subroutine BEGIN: called CC=1 SCAR=0.0
43 *$func = sub {
44 3113 ▶ my $self = shift;
Subroutine __ANON__: called CC=8 SCAR=21.2
45 3113 my ($count) = @_;
46 3113 my $v;
47 # print "[[ $func ]]\n";
48 3113 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 3106 7 3113
49 return map {
50 3106 $_ &&
51 3091 ▶ do { $v = $_->full_value; defined $v && length $v ? $v : $_ }
Branch: 2 branches
BranchTrueFalseTotal
$_ and do { $v = $_->full_value; defined $v && length $v ? $v : $_ } 3091 0 3091
defined $v && length $v ? : 3013 78 3091
Condition66%2/3
defined $v and length $v
!ll&&!rl&&r
0783013
MC/DC50%1/2
defined $v and length $v
defined $v length $v
Truth table66%2/3
A and B
A= defined $vB= length $v
ABresult
0X0
100
111
52 } $self->record([$func, $count]);
53 } else {
54 7 my $r = $self->record([$func, $count]);
55 return $r &&
56 7 ▶ do { $v = $r->full_value; defined $v && length $v ? $v : $r }
Branch: 1 branch
BranchTrueFalseTotal
defined $v && length $v ? : 6 1 7
Condition50%3/6
$r && do { $v = $r->full_value; defined $v && length $v ? $v : $r }
!ll&&!rl&&r
007
defined $v and length $v
!ll&&!rl&&r
016
MC/DC0%0/2
$r && do { $v = $r->full_value; defined $v && length $v ? $v : $r }
$r do { $v = $r->full_value; defined $v && length $v ? $v : $r }
MC/DC50%1/2
defined $v and length $v
defined $v length $v
Truth table33%1/3
A && B
A= $rB= do { $v = $r->full_value; defined $v && length $v ? $v : $r }
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= defined $vB= length $v
ABresult
0X0
100
111
57 }
58 26 };
59 26 goto &$func
60 }
61  
62 sub record {
63 3219 ▶ my $self = shift;
Subroutine record: called CC=11 SCAR=28.7
Pod documented
64 3219 my @records = ($self);
65 3219 ▶ for my $func (map { ref() ? $_ : split } @_) {
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 3114 200 3314
66 3322 my $count = 0;
67 3322 ▶ ($func, $count) = @$func if ref $func eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $func eq "ARRAY" 3114 208 3322
68 3322 ▶ if (ref $func) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $func) 0 3322 3322
69 0 warn "Invalid record of type ", ref $func, " requested";
70 0 return undef;
71 }
72 3322 my $record = $Gedcom::Funcs{lc $func};
73 3322 ▶ unless ($record) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($record) 0 3322 3322
74 0 ▶ warn $func
Branch: 2 branches
BranchTrueFalseTotal
unless $func =~ /^_/ 0 0 0
$func ? : 0 0 0
75 ? "Non standard record of type $func requested"
76 : "Record type not specified"
77 unless $func =~ /^_/;
78 0 $record = $func;
79 }
80  
81 3322 @records = map { $_->tag_record($record, $count) } @records;
82  
83 # fams and famc need to be resolved
84 3322 ▶ @records = map { $self->resolve($_->{value}) } @records
Branch: 1 branch
BranchTrueFalseTotal
if $record eq "FAMS" or $record eq "FAMC" 0 3322 3322
Condition33%1/3
$record eq "FAMS" or $record eq "FAMC"
l!l&&r!l&&!r
003322
MC/DC0%0/2
$record eq "FAMS" or $record eq "FAMC"
$record eq "FAMS" $record eq "FAMC"
Truth table33%1/3
A or B
A= $record eq "FAMS"B= $record eq "FAMC"
ABresult
1X1
011
000
85 if $record eq "FAMS" || $record eq "FAMC";
86 }
87 3219 ▶ wantarray ? @records : $records[0]
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3202 17 3219
88 }
89  
90 sub get_value {
91 103 ▶ my $self = shift;
Subroutine get_value: called CC=5 SCAR=16.4
Pod documented
92 103 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 96 7 103
93 96 ▶ return map { my $v = $_->full_value; defined $v and length $v ? $v : () }
Branch: 2 branches
BranchTrueFalseTotal
defined $v and length $v ? $v : () 82 0 82
length $v ? : 82 0 82
94 $self->record(@_);
95 } else {
96 7 my $record = $self->record(@_);
97 7 ▶ return $record && $record->full_value;
Condition66%2/3
$record && $record->full_value
!ll&&!rl&&r
061
MC/DC50%1/2
$record && $record->full_value
$record $record->full_value
Truth table66%2/3
A && B
A= $recordB= $record->full_value
ABresult
0X0
100
111
98 }
99 }
100  
101 sub tag_value {
102 62696 ▶ my $self = shift;
Subroutine tag_value: called CC=5 SCAR=16.8
Pod undocumented
103 62696 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 52461 10235 62696
104 52461 ▶ return map { my $v = $_->full_value; defined $v and length $v ? $v : () }
Branch: 2 branches
BranchTrueFalseTotal
defined $v and length $v ? $v : () 53326 0 53326
length $v ? : 53326 0 53326
105 $self->tag_record(@_);
106 } else {
107 10235 my $record = $self->tag_record(@_);
108 10235 ▶ return $record && $record->full_value;
Condition33%1/3
$record && $record->full_value
!ll&&!rl&&r
0010235
MC/DC0%0/2
$record && $record->full_value
$record $record->full_value
Truth table33%1/3
A && B
A= $recordB= $record->full_value
ABresult
0X0
100
111
109 }
110 }
111  
112 sub add_record {
113 80 ▶ my $self = shift;
Subroutine add_record: called CC=14 SCAR=26.8
Pod undocumented
114 80 my (%args) = @_;
115  
116 80 ▶ die "No tag specified" unless defined $args{tag};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"tag"} 0 80 80
117  
118 my $record = Gedcom::Record->new(
119 gedcom => $self->{gedcom},
120 callback => $self->{callback},
121 tag => $args{tag},
122 80 );
123  
124 80 ▶ if (!defined $self->{grammar}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $self->{'grammar'}) { } 0 80 80
elsif (my(@g) = $self->{'grammar'}->item($args{'tag'})) { } 80 0 80
125 0 warn "$self->{tag} has no grammar\n";
126 } elsif (my @g = $self->{grammar}->item($args{tag})) {
127 # use DDS; print Dump \@g;
128 80 my $grammar = $g[0];
129 80 for my $g (@g) {
130 # print "testing $args{tag} ", $args{val} // "undef", " against ",
131 # $g->{value} // "undef", "\n";
132 82 ▶ if ($args{tag} eq "NOTE") {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'tag'} eq 'NOTE') { } 6 76 82
133 6 ▶ if (( defined $args{xref} && $g->{value} =~ /xref/i) ||
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"xref"} and $g->{"value"} =~ /xref/i or not defined $args{"xref"} || $g->{"value"} =~ /xref/i) 5 1 6
Condition77%7/9
defined $args{"xref"} and $g->{"value"} =~ /xref/i or not defined $args{"xref"} || $g->{"value"} =~ /xref/i
l!l&&r!l&&!r
141
defined $args{"xref"} and $g->{"value"} =~ /xref/i
!ll&&!rl&&r
501
defined $args{'xref'} || $g->{'value'} =~ /xref/i
l!l&&r!l&&!r
014
MC/DC50%2/4
defined $args{"xref"} and $g->{"value"} =~ /xref/i or not defined $args{"xref"} || $g->{"value"} =~ /xref/i
defined $args{"xref"} $g->{"value"} =~ /xref/i defined $args{'xref'} $g->{'value'} =~ /xref/i
Truth table42%3/7
A and B or not(C || D)
A= defined $args{"xref"}B= $g->{"value"} =~ /xref/iC= defined $args{'xref'}D= $g->{'value'} =~ /xref/i
ABCDresult
11XX1
0X001
10001
0X1X0
0X010
101X0
10010
134 (!defined $args{xref} && $g->{value} !~ /xref/i)) {
135 # print "note match\n";
136 5 $grammar = $g;
137 5 last;
138 }
139 } else {
140 76 ▶ if (( defined $args{val} && $g->{value}) ||
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"val"} and $g->{"value"} or not defined $args{"val"} || $g->{"value"}) 67 9 76
Condition100%9/9
defined $args{"val"} and $g->{"value"} or not defined $args{"val"} || $g->{"value"}
l!l&&r!l&&!r
51169
defined $args{"val"} and $g->{"value"}
!ll&&!rl&&r
23251
defined $args{'val'} || $g->{'value'}
l!l&&r!l&&!r
2716
MC/DC75%3/4
defined $args{"val"} and $g->{"value"} or not defined $args{"val"} || $g->{"value"}
defined $args{"val"} $g->{"value"} defined $args{'val'} $g->{'value'}
Truth table57%4/7
A and B or not(C || D)
A= defined $args{"val"}B= $g->{"value"}C= defined $args{'val'}D= $g->{'value'}
ABCDresult
11XX1
0X001
10001
0X1X0
0X010
101X0
10010
141 (!defined $args{val} && !$g->{value})) {
142 # print "match\n";
143 67 $grammar = $g;
144 67 last;
145 }
146 }
147 }
148 80 $self->parse($record, $grammar);
149 } else {
150 0 warn "$args{tag} is not a sub-item of $self->{tag}\n";
151 }
152  
153 80 push @{$self->{items}}, $record;
154  
155 80 $record
156 }
157  
158 sub add {
159 62 ▶ my $self = shift;
Subroutine add: called CC=8 SCAR=20.8
Pod documented
160 62 my ($xref, $val);
161 62 ▶ if (@_ > 1 && ref $_[-1] ne "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1 and ref $_[-1] ne "ARRAY") 59 3 62
Condition66%2/3
@_ > 1 and ref $_[-1] ne "ARRAY"
!ll&&!rl&&r
3059
MC/DC50%1/2
@_ > 1 and ref $_[-1] ne "ARRAY"
@_ > 1 ref $_[-1] ne "ARRAY"
Truth table66%2/3
A and B
A= @_ > 1B= ref $_[-1] ne "ARRAY"
ABresult
0X0
100
111
162 59 $val = pop;
163 59 ▶ if (UNIVERSAL::isa($val, "Gedcom::Record")) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($val, "Gedcom::Record")) 6 53 59
164 6 $xref = $val;
165 6 $val = undef;
166 }
167 }
168  
169 62 ▶ my @funcs = map { ref() ? $_ : split } @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 2 62 64
170 62 ▶ $funcs[-1] = [$funcs[-1], 0] unless ref $funcs[-1];
Branch: 1 branch
BranchTrueFalseTotal
unless ref $funcs[-1] 61 1 62
171 62 push @{$funcs[-1]}, { xref => $xref, val => $val };
172 62 my $record = $self->get_and_create(@funcs);
173  
174 62 ▶ if (defined $xref) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $xref) 6 56 62
175 6 $record->{value} = $xref->{xref};
176 6 $self->{gedcom}{xrefs}{$xref->{xref}} = $xref;
177 }
178  
179 62 ▶ if (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 53 9 62
180 53 $record->{value} = $val;
181 }
182  
183 $record
184 62 }
185  
186 sub set {
187 1 ▶ my $self = shift;
Subroutine set: called CC=3 SCAR=11.7
Pod documented
188 1 my $val = pop;
189  
190 1 ▶ my @funcs = map { ref() ? $_ : split } @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 1 1
191 1 my $r = $self->get_and_create(@funcs);
192  
193 1 ▶ if (UNIVERSAL::isa($val, "Gedcom::Record")) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($val, 'Gedcom::Record')) { } 0 1 1
194 0 $r->{value} = $val->{xref};
195 0 $self->{gedcom}{xrefs}{$val->{xref}} = $val;
196 } else {
197 1 $r->{value} = $val;
198 }
199  
200 1 $r
201 }
202  
203 sub get_and_create {
204 63 ▶ my $self = shift;
Subroutine get_and_create: called CC=11 SCAR=26.2
Pod undocumented
205 63 my @funcs = @_;
206 # use DDS; print "get_and_create: " , Dump \@funcs;
207  
208 63 my $rec = $self;
209 63 for my $f (0 .. $#funcs) {
210 72 my ($func, $count, $args) = ($funcs[$f], 1);
211 72 ▶ $args = {} unless defined $args;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args 72 0 72
212 72 ▶ ($func, $count, $args) = @$func if ref $func eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
if ref $func eq "ARRAY" 63 9 72
213 72 $count--;
214  
215 72 ▶ if (ref $func) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $func) 0 72 72
216 0 warn "Invalid record of type ", ref $func, " requested";
217 0 return undef;
218 }
219  
220 72 my $record = $Gedcom::Funcs{lc $func};
221 72 ▶ unless ($record) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($record) 0 72 72
222 0 ▶ warn $func
Branch: 2 branches
BranchTrueFalseTotal
unless $func =~ /^_/ 0 0 0
$func ? : 0 0 0
223 ? "Non standard record of type $func requested"
224 : "Record type not specified"
225 unless $func =~ /^_/;
226 0 $record = $func;
227 }
228  
229 # print "$func [$count] - $record\n";
230  
231 72 my @records = $rec->tag_record($record);
232  
233 72 ▶ if ($count < 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($count < 0) { } 61 11 72
elsif ($#records < $count) { } 7 4 11
234 61 $rec = $rec->add_record(tag => $record, %$args);
235 } elsif ($#records < $count) {
236 7 my $new;
237 $new = $rec->add_record(tag => $record, %$args)
238 7 for (0 .. @records - $count);
239 7 $rec = $new;
240 } else {
241 4 $rec = $records[$count];
242 }
243 }
244  
245 $rec
246 63 }
247  
248 sub parse {
249 # print "parsing\n";
250 10314 ▶ my $self = shift;
Subroutine parse: called CC=19 SCAR=34.2
Pod documented
251 10314 my ($record, $grammar, $test) = @_;
252 10314 ▶ $test ||= 0;
Condition50%1/2
$test ||= 0
l!l
010314
MC/DC0%0/1
$test ||= 0
$test
Truth table50%1/2
A
A= $test
Aresult
11
00
253  
254 # print "checking "; $record->print();
255 # print "against "; $grammar->print();
256 # print "test is $test\n";
257  
258 10314 my $t = $record->{tag};
259 10314 my $g = $grammar->{tag};
260 10314 ▶ die "Can't match $t with $g" if $t && $t ne $g; # internal error
Branch: 1 branch
BranchTrueFalseTotal
if $t and $t ne $g 0 10314 10314
Condition33%1/3
$t and $t ne $g
!ll&&!rl&&r
0103140
MC/DC0%0/2
$t and $t ne $g
$t $t ne $g
Truth table33%1/3
A and B
A= $tB= $t ne $g
ABresult
0X0
100
111
261  
262 10314 $record->{grammar} = $grammar;
263 10314 my $class = $record->{gedcom}{types}{$t};
264 10314 ▶ bless $record, "Gedcom::$class" if $class;
Branch: 1 branch
BranchTrueFalseTotal
if $class 2657 7657 10314
265  
266 10314 my $match = 1;
267  
268 10314 for my $r (@{$record->{items}}) {
269 8928 my $tag = $r->{tag};
270 8928 my @i;
271 # print "- valid sub-items of $t: @{[keys %{$grammar->valid_items}]}\n";
272 8928 for my $i ($grammar->item($tag)) {
273 # Try to get rid of matches we don't want because they only match
274 # in name.
275  
276 # Check that the level is appropriate.
277 # print " - ", $i->level, "|", $r->level, "\n";
278 8944 ▶ next unless $i->level =~ /^[+0]/ || $i->level == $r->level;
Branch: 1 branch
BranchTrueFalseTotal
unless $i->level =~ /^[+0]/ or $i->level == $r->level 0 8944 8944
Condition33%1/3
$i->level =~ /^[+0]/ or $i->level == $r->level
l!l&&r!l&&!r
894400
MC/DC0%0/2
$i->level =~ /^[+0]/ or $i->level == $r->level
$i->level =~ /^[+0]/ $i->level == $r->level
Truth table33%1/3
A or B
A= $i->level =~ /^[+0]/B= $i->level == $r->level
ABresult
1X1
011
000
279  
280 # Check we have a pointer iff we need one.
281 # print " + ", $i->value, "|", $r->value, "|", $r->pointer, "\n";
282 8944 ▶ next if $i->value && ($i->value =~ /^<XREF:/ ^ ($r->pointer || 0));
Branch: 1 branch
BranchTrueFalseTotal
if $i->value and $i->value =~ /^<XREF:/ ^ ($r->pointer || 0) 24 8920 8944
Condition100%5/5
$i->value and $i->value =~ /^<XREF:/ ^ ($r->pointer || 0)
!ll&&!rl&&r
1392752824
$r->pointer || 0
l!l
20725480
MC/DC100%2/2
$i->value and $i->value =~ /^<XREF:/ ^ ($r->pointer || 0)
$i->value $i->value =~ /^<XREF:/ ^ ($r->pointer || 0)
MC/DC100%1/1
$r->pointer || 0
$r->pointer
Truth table100%3/3
A and B
A= $i->valueB= $i->value =~ /^<XREF:/ ^ ($r->pointer || 0)
ABresult
0X0
100
111
Truth table100%2/2
A
A= $r->pointer
Aresult
11
00
283  
284 # print "pushing\n";
285 8920 push @i, $i;
286 }
287  
288 # print "valid sub-items of $t: @{[keys %{$grammar->valid_items}]}\n";
289 # print "<$tag> => <@i>\n";
290  
291 8928 ▶ unless (@i) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@i) 8 8920 8928
292 # unless $tag eq "CONT" || $tag eq "CONC"
293 # || substr($tag, 0, 1) eq "_";
294 # TODO - should CONT and CONC be allowed anywhere?
295 8 ▶ unless (substr($tag, 0, 1) eq "_") {
Branch: 1 branch
BranchTrueFalseTotal
unless (substr($tag, 0, 1) eq "_") 0 8 8
296 warn "$self->{file}:$r->{line}: $tag is not a sub-item of $t\n",
297 "Valid sub-items are ",
298 0 ▶ join(", ", sort keys %{$grammar->{_valid_items}}), "\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $test 0 0 0
299 unless $test;
300 0 $match = 0;
301 0 next;
302 }
303 }
304  
305 # print "$self->{file}:$r->{line}: Ambiguous tag $tag as sub-item of $t, ",
306 # "found ", scalar @i, " matches\n" if @i > 1;
307 8928 my $m = 0;
308 8928 for my $i (@i) {
309 8920 ▶ last if $m = $self->parse($r, $i, @i > 1);
Branch: 1 branch
BranchTrueFalseTotal
if $m = $self->parse($r, $i, @i > 1) 8920 0 8920
310 }
311  
312 8928 ▶ if (@i > 1 && !$m) {
Branch: 1 branch
BranchTrueFalseTotal
if (@i > 1 and not $m) 0 8928 8928
Condition33%1/3
@i > 1 and not $m
!ll&&!rl&&r
892800
MC/DC0%0/2
@i > 1 and not $m
@i > 1 not $m
Truth table33%1/3
A and not(B)
A= @i > 1B= not $m
ABresult
0X0
100
111
313 # TODO - I'm not even sure if this can happen.
314 0 warn "$self->{file}:$r->{line}:" ,
315 "Ambiguous tag $tag as sub-item of $t, ",
316 "found ", scalar @i, " matches, all of which have errors. ",
317 "Reporting errors from last match.\n";
318 0 $self->parse($r, $i[-1]);
319 0 $match = 0;
320 # TODO - count the errors in each match and use the best.
321 }
322 }
323 # print "parsed $match\n";
324  
325 $match
326 10314 }
327  
328 sub collect_xrefs {
329 25650 ▶ my $self = shift;
Subroutine collect_xrefs: called CC=3 SCAR=11.0
Pod documented
330 25650 my ($callback) = @_;
331 25650 ▶ $self->{gedcom}{xrefs}{$self->{xref}} = $self if defined $self->{xref};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"xref"} 3177 22473 25650
332 25650 $_->collect_xrefs($callback) for @{$self->{items}};
333 25650 $self
334 }
335  
336 sub resolve_xref {
337 5287 ▶ shift->{gedcom}->resolve_xref(@_);
Subroutine resolve_xref: called CC=1 SCAR=0.0
Pod documented
338 }
339  
340 sub resolve {
341 15679 ▶ my $self = shift;
Subroutine resolve: called CC=4 SCAR=13.9
Pod documented
342 my @x = map {
343 15679 ref($_)
344 ? $_
345 14150 ▶ : do { my $x = $self->{gedcom}->resolve_xref($_); defined $x ? $x : () }
Branch: 2 branches
BranchTrueFalseTotal
ref $_ ? : 12696 1454 14150
defined $x ? : 1438 16 1454
346 } @_;
347 15679 ▶ wantarray ? @x : $x[0]
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 15671 8 15679
348 }
349  
350 sub resolve_xrefs {
351 22803 ▶ my $self = shift;
Subroutine resolve_xrefs: called CC=3 SCAR=11.0
Pod documented
352 22803 my ($callback) = @_;
353 22803 ▶ if (my $xref = $self->{gedcom}->resolve_xref($self->{value})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $xref = $self->{"gedcom"}->resolve_xref($self->{"value"})) 2572 20231 22803
354 2572 $self->{value} = $xref;
355 }
356 22803 $_->resolve_xrefs($callback) for @{$self->_items};
357 22803 $self
358 }
359  
360 sub unresolve_xrefs {
361 15156 ▶ my $self = shift;;
Subroutine unresolve_xrefs: called CC=5 SCAR=16.1
Pod documented
362 15156 my ($callback) = @_;
363 $self->{value} = $self->{value}{xref}
364 if defined $self->{value}
365 and UNIVERSAL::isa $self->{value}, "Gedcom::Record"
366 15156 ▶ and exists $self->{value}{xref};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"value"} and UNIVERSAL::isa($self->{"value"}, "Gedcom::Record") and exists $self->{"value"}{"xref"} 2056 13100 15156
Condition83%5/6
defined $self->{"value"} and UNIVERSAL::isa($self->{"value"}, "Gedcom::Record") and exists $self->{"value"}{"xref"}
!ll&&!rl&&r
1310002056
defined $self->{"value"} and UNIVERSAL::isa($self->{"value"}, "Gedcom::Record")
!ll&&!rl&&r
12130882056
MC/DC66%2/3
defined $self->{"value"} and UNIVERSAL::isa($self->{"value"}, "Gedcom::Record") and exists $self->{"value"}{"xref"}
defined $self->{"value"} UNIVERSAL::isa($self->{"value"}, "Gedcom::Record") exists $self->{"value"}{"xref"}
Truth table75%3/4
A and B and C
A= defined $self->{"value"}B= UNIVERSAL::isa($self->{"value"}, "Gedcom::Record")C= exists $self->{"value"}{"xref"}
ABCresult
0XX0
10X0
1100
1111
367 15156 $_->unresolve_xrefs($callback) for @{$self->_items};
368 15156 $self
369 }
370  
371 15 my $D = 0; # turn on debug output
372 15 my $I = -1; # indent for debug output
373  
374 sub validate_syntax {
375 69989 ▶ my $self = shift;
Subroutine validate_syntax: called CC=24 SCAR=32.2
Pod undocumented
376 69989 ▶ return 1 unless exists $self->{grammar};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"grammar"} 16500 53489 69989
377 53489 my $ok = 1;
378 $self->{gedcom}{validate_callback}->($self)
379 53489 ▶ if defined $self->{gedcom}{validate_callback};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"gedcom"}{"validate_callback"} 0 53489 53489
380 53489 my $grammar = $self->{grammar};
381 53489 $I++;
382 print " " x $I . "validate_syntax(" .
383 53489 ▶ (defined $grammar->{tag} ? $grammar->{tag} : "") . ")\n" if $D;
Branch: 2 branches
BranchTrueFalseTotal
if $D 0 53489 53489
defined $grammar->{'tag'} ? : 0 0 0
384 53489 my $file = $self->{gedcom}{record}{file};
385 my $here = "$file:$self->{line}: $self->{tag}" .
386 53489 ▶ (defined $self->{xref} ? " $self->{xref}" : "");
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'xref'} ? : 8648 44841 53489
387 # print "$self->{line}: "; $self->print;
388 $ok = 0, warn "$here: $self->{tag} Can't contain a value ($self->{value})\n"
389 if defined $self->{value} && length $self->{value} &&
390 53489 ▶ !defined $grammar->{value};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"value"} and length $self->{"value"} and not defined $grammar->{"value"} 680 52809 53489
Condition100%6/6
defined $self->{"value"} and length $self->{"value"} and not defined $grammar->{"value"}
!ll&&!rl&&r
1508037729680
defined $self->{"value"} and length $self->{"value"}
!ll&&!rl&&r
15171356338409
MC/DC100%3/3
defined $self->{"value"} and length $self->{"value"} and not defined $grammar->{"value"}
defined $self->{"value"} length $self->{"value"} not defined $grammar->{"value"}
Truth table100%4/4
A and B and not(C)
A= defined $self->{"value"}B= length $self->{"value"}C= not defined $grammar->{"value"}
ABCresult
0XX0
10X0
1100
1111
391 53489 my %counts;
392 53489 for my $record (@{$self->_items}) {
393 69928 ▶ print " " x $I . "level $record->{level} on $self->{level}\n" if $D;
Branch: 1 branch
BranchTrueFalseTotal
if $D 0 69928 69928
394 $ok = 0,
395 warn "$here: Can't add level $record->{level} to $self->{level}\n"
396 69928 ▶ if $record->{level} > $self->{level} + 1;
Branch: 1 branch
BranchTrueFalseTotal
if $record->{"level"} > $self->{"level"} + 1 0 69928 69928
397 69928 $counts{$record->{tag}}++;
398 69928 ▶ $ok = 0 unless $record->validate_syntax;
Branch: 1 branch
BranchTrueFalseTotal
unless $record->validate_syntax 1364 68564 69928
399 }
400 53489 my $valid_items = $grammar->valid_items;
401 53489 for my $tag (sort keys %$valid_items) {
402 563458 for my $g (@{$valid_items->{$tag}}) {
403 637008 my $min = $g->{min};
404 637008 my $max = $g->{max};
405 637008 ▶ my $matches = delete $counts{$tag} || 0;
Condition100%2/2
delete $counts{$tag} || 0
l!l
57309579699
MC/DC100%1/1
delete $counts{$tag} || 0
delete $counts{$tag}
Truth table100%2/2
A
A= delete $counts{$tag}
Aresult
11
00
406 637008 ▶ my $msg = "$here has $matches $tag" . ($matches == 1 ? "" : "s");
Branch: 1 branch
BranchTrueFalseTotal
$matches == 1 ? : 55339 581669 637008
407 637008 ▶ print " " x $I . "$msg - min is $min max is $max\n" if $D;
Branch: 1 branch
BranchTrueFalseTotal
if $D 0 637008 637008
408 637008 ▶ $ok = 0, warn "$msg - minimum is $min\n" if $matches < $min;
Branch: 1 branch
BranchTrueFalseTotal
if $matches < $min 0 637008 637008
409 637008 ▶ $ok = 0, warn "$msg - maximum is $max\n" if $matches > $max && $max;
Branch: 1 branch
BranchTrueFalseTotal
if $matches > $max and $max 2 637006 637008
Condition100%3/3
$matches > $max and $max
!ll&&!rl&&r
607485295212
MC/DC100%2/2
$matches > $max and $max
$matches > $max $max
Truth table100%3/3
A and B
A= $matches > $maxB= $max
ABresult
0X0
100
111
410 }
411 }
412 53489 for my $tag (keys %counts) {
413 60 for my $c ($self->tag_record($tag)) {
414 60 ▶ $ok = 0,
Branch: 1 branch
BranchTrueFalseTotal
unless substr($tag, 0, 1) eq "_" 0 60 60
415 warn "$file:$c->{line}: $tag is not a sub-item of $self->{tag}\n"
416 unless substr($tag, 0, 1) eq "_";
417 # unless $tag eq "CONT" || $tag eq "CONC" || substr($tag, 0, 1) eq "_";
418 # TODO - should CONT and CONC be allowed anywhere?
419 }
420 }
421 53489 $I--;
422 53489 $ok;
423 }
424  
425 15 my $Check = {
426 INDI => {
427 FAMS => [ "HUSB", "WIFE" ],
428 FAMC => [ "CHIL" ]
429 },
430 FAM => {
431 HUSB => [ "FAMS" ],
432 WIFE => [ "FAMS" ],
433 CHIL => [ "FAMC" ],
434 },
435 };
436  
437 sub validate_semantics {
438 8770 ▶ my $self = shift;
Subroutine validate_semantics: called CC=13 SCAR=26.5
Pod documented
439 8770 ▶ return 1 unless $self->{tag} eq "INDI" || $self->{tag} eq "FAM";
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"tag"} eq "INDI" or $self->{"tag"} eq "FAM" 365 8405 8770
Condition100%3/3
$self->{"tag"} eq "INDI" or $self->{"tag"} eq "FAM"
l!l&&r!l&&!r
55852820365
MC/DC100%2/2
$self->{"tag"} eq "INDI" or $self->{"tag"} eq "FAM"
$self->{"tag"} eq "INDI" $self->{"tag"} eq "FAM"
Truth table100%3/3
A or B
A= $self->{"tag"} eq "INDI"B= $self->{"tag"} eq "FAM"
ABresult
1X1
011
000
440 # print "validating: "; $self->print; print $self->summary, "\n";
441 8405 my $ok = 1;
442 8405 my $xrefs = $self->{gedcom}{xrefs};
443 8405 my $chk = $Check->{$self->{tag}};
444 8405 for my $f (keys %$chk) {
445 19630 my $found = 1;
446 RECORD:
447 19630 for my $record ($self->tag_value($f)) {
448 15244 $found = 0;
449 15244 ▶ $record = $xrefs->{$record} unless ref $record;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $record 8640 6604 15244
450 15244 ▶ if ($record) {
Branch: 1 branch
BranchTrueFalseTotal
if ($record) 15240 4 15244
451 15240 for my $back (@{$chk->{$f}}) {
452 # print "back $back\n";
453 17160 for my $i ($record->tag_value($back)) {
454 # print "record is $i\n";
455 20400 ▶ $i = $xrefs->{$i} unless ref $i;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $i 11560 8840 20400
456 20400 ▶ if ($i && $i->{xref} eq $self->{xref}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i and $i->{"xref"} eq $self->{"xref"}) 15240 5160 20400
Condition66%2/3
$i and $i->{"xref"} eq $self->{"xref"}
!ll&&!rl&&r
0516015240
MC/DC50%1/2
$i and $i->{"xref"} eq $self->{"xref"}
$i $i->{"xref"} eq $self->{"xref"}
Truth table66%2/3
A and B
A= $iB= $i->{"xref"} eq $self->{"xref"}
ABresult
0X0
100
111
457 15240 $found = 1;
458 # print "found...\n";
459 15240 next RECORD;
460 }
461 }
462 }
463 0 ▶ unless ($found) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($found) 0 0 0
464 # TODO - use the line of the offending record
465 0 $ok = 0;
466 0 my $file = $self->{gedcom}{record}{file};
467 warn "$file:$self->{line}: $f $record->{xref} " .
468 "does not reference $self->{tag} $self->{xref}. " .
469 "Add the line:\n" .
470 "$file:" . ($record->{line} + 1) . ": 1 " .
471 0 join("or ", @{$chk->{$f}}) . " $self->{xref}\n";
472 }
473 }
474 }
475 }
476 8405 $ok;
477 }
478  
479 sub normalise_dates {
480 7578 ▶ my $self = shift;
Subroutine normalise_dates: called CC=16 SCAR=29.8
Pod documented
481 7578 ▶ unless ($INC{"Date/Manip.pm"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($INC{"Date/Manip.pm"}) 0 7578 7578
482 0 warn "Date::Manip.pm is required to use normalise_dates()";
483 0 return;
484 }
485 7578 ▶ if( eval { Date::Manip->VERSION( 6 ) } &&
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { "Date::Manip"->VERSION(6) } } and not eval { do { "Date::Manip"->VERSION("6.13") } }) 0 7578 7578
Condition33%1/3
eval { do { "Date::Manip"->VERSION(6) } } and not eval { do { "Date::Manip"->VERSION("6.13") } }
!ll&&!rl&&r
075780
MC/DC0%0/2
eval { do { "Date::Manip"->VERSION(6) } } and not eval { do { "Date::Manip"->VERSION("6.13") } }
eval { do { "Date::Manip"->VERSION(6) } } not eval { do { "Date::Manip"->VERSION("6.13") } }
Truth table33%1/3
A and not(B)
A= eval { do { "Date::Manip"->VERSION(6) } }B= not eval { do { "Date::Manip"->VERSION("6.13") } }
ABresult
0X0
100
111
486 7578 !eval { Date::Manip->VERSION( 6.13 ) } ) {
487 0 warn "Unable to normalize dates with this version of Date::Manip. " .
488 "Please upgrade to version 6.13.";
489 return
490 0 }
491 7578 ▶ my $format = shift || "%A, %E %B %Y";
Condition100%2/2
shift() || '%A, %E %B %Y'
l!l
75726
MC/DC100%1/1
shift() || '%A, %E %B %Y'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
492 7578 ▶ if (defined $self->{tag} && $self->{tag} =~ /^date$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"tag"} and $self->{"tag"} =~ /^date$/i) 906 6672 7578
Condition66%2/3
defined $self->{"tag"} and $self->{"tag"} =~ /^date$/i
!ll&&!rl&&r
06672906
MC/DC50%1/2
defined $self->{"tag"} and $self->{"tag"} =~ /^date$/i
defined $self->{"tag"} $self->{"tag"} =~ /^date$/i
Truth table66%2/3
A and B
A= defined $self->{"tag"}B= $self->{"tag"} =~ /^date$/i
ABresult
0X0
100
111
493 906 ▶ if (defined $self->{value} && $self->{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"value"} and $self->{"value"}) 906 0 906
Condition33%1/3
defined $self->{"value"} and $self->{"value"}
!ll&&!rl&&r
00906
MC/DC0%0/2
defined $self->{"value"} and $self->{"value"}
defined $self->{"value"} $self->{"value"}
Truth table33%1/3
A and B
A= defined $self->{"value"}B= $self->{"value"}
ABresult
0X0
100
111
494 # print "date was $self->{value}\n";
495 906 my @dates = split / or /, $self->{value};
496 906 for my $dt (@dates) {
497 # Don't change the date if it looks like 'AFT 1989'.
498 # AFT means AFTER and ParseDate returns the current date and the tests
499 # are failing.
500 # Current date can symbolize such an "after" date, but can also
501 # symbolize a very specific point in time and that could also confuse
502 # the user.
503 906 ▶ next if $dt =~ /^AFT/;
Branch: 1 branch
BranchTrueFalseTotal
if $dt =~ /^AFT/ 6 900 906
504  
505 # Don't change the date if it is just < 7 digits.
506 900 ▶ if ($dt !~ /^\s*(\d+)\s*$/ || length $1 > 6) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $dt =~ /^\s*(\d+)\s*$/ or length $1 > 6) 642 258 900
Condition66%2/3
not $dt =~ /^\s*(\d+)\s*$/ or length $1 > 6
l!l&&r!l&&!r
6420258
MC/DC50%1/2
not $dt =~ /^\s*(\d+)\s*$/ or length $1 > 6
not $dt =~ /^\s*(\d+)\s*$/ length $1 > 6
Truth table66%2/3
not(A) or B
A= not $dt =~ /^\s*(\d+)\s*$/B= length $1 > 6
ABresult
1X1
011
000
507 642 my $date = ParseDate($dt);
508 642 my $d = UnixDate($date, $format);
509 642 ▶ $dt = $d if $d;
Branch: 1 branch
BranchTrueFalseTotal
if $d 630 12 642
510 }
511 }
512 906 $self->{value} = join " or ", @dates;
513 # print "date is $self->{value}\n";
514 }
515 }
516 7578 $_->normalise_dates($format) for @{$self->_items};
517 7578 ▶ $self->delete_items if $self->level > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->level > 1 1758 5820 7578
518 }
519  
520 sub renumber {
521 13600 ▶ my $self = shift;
Subroutine renumber: called CC=10 SCAR=23.0
Pod documented
522 13600 my ($args, $recurse) = @_;
523 # TODO - add the xref if there is supposed to be one
524 13600 ▶ return if exists $self->{recursed} or not defined $self->{xref};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"recursed"} or not defined $self->{"xref"} 9104 4496 13600
Condition100%3/3
exists $self->{"recursed"} or not defined $self->{"xref"}
l!l&&r!l&&!r
9078264496
MC/DC100%2/2
exists $self->{"recursed"} or not defined $self->{"xref"}
exists $self->{"recursed"} not defined $self->{"xref"}
Truth table100%3/3
A or not(B)
A= exists $self->{"recursed"}B= not defined $self->{"xref"}
ABresult
1X1
011
000
525 # we can't actually change the xrefs until the end
526 4496 ▶ my $x = $self->{tag} eq "SUBM" ? "SUBM" : substr $self->{tag}, 0, 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'tag'} eq 'SUBM' ? : 13 4483 4496
527 $self->{new_xref} = $x . ++$args->{$self->{tag}}
528 4496 ▶ unless exists $self->{new_xref};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"new_xref"} 1736 2760 4496
529 4496 ▶ return unless $recurse and not exists $self->{recursed};
Branch: 1 branch
BranchTrueFalseTotal
unless $recurse and not exists $self->{"recursed"} 2760 1736 4496
Condition66%2/3
$recurse and not exists $self->{"recursed"}
!ll&&!rl&&r
276001736
MC/DC50%1/2
$recurse and not exists $self->{"recursed"}
$recurse not exists $self->{"recursed"}
Truth table66%2/3
A and not(B)
A= $recurseB= not exists $self->{"recursed"}
ABresult
0X0
100
111
530 1736 $self->{recursed} = 1;
531 1736 ▶ if ($self->{tag} eq "INDI") {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"tag"} eq "INDI") 1121 615 1736
532 1121 my @r = map { $self->$_() }
533 qw( fams famc spouse children parents siblings );
534 1121 $_->renumber($args, 0) for @r;
535 1121 $_->renumber($args, 1) for @r;
536 }
537 }
538  
539 sub child_value {
540 # NOTE - This function is deprecated - use tag_value instead
541 0 ▶ my $self = shift;
Subroutine child_value: not called CC=1 SCAR=6.9
Pod documented
542 0 $self->tag_value(@_)
543 }
544  
545 sub child_values {
546 # NOTE - This function is deprecated - use tag_value instead
547 0 ▶ my $self = shift;
Subroutine child_values: not called CC=1 SCAR=6.9
Pod documented
548 0 $self->tag_value(@_)
549 }
550  
551 sub compare {
552 0 ▶ my $self = shift;
Subroutine compare: not called CC=1 SCAR=6.9
Pod undocumented
553 0 my ($r) = @_;
554 0 Gedcom::Comparison->new($self, $r)
555 }
556  
557 sub summary {
558 0 ▶ my $self = shift;
Subroutine summary: not called CC=5 SCAR=34.0
Pod documented
559 0 my $s = "";
560 0 $s .= sprintf "%-5s", $self->{xref};
561 0 my $r = $self->tag_record("NAME");
562 0 ▶ $s .= sprintf " %-40s", $r ? $r->{value} : "";
Branch: 1 branch
BranchTrueFalseTotal
$r ? : 0 0 0
563 0 $r = $self->tag_record("SEX");
564 0 ▶ $s .= sprintf " %1s", $r ? $r->{value} : "";
Branch: 1 branch
BranchTrueFalseTotal
$r ? : 0 0 0
565 0 my $d = "";
566 0 ▶ if ($r = $self->tag_record("BIRT") and my $date = $r->tag_record("DATE")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r = $self->tag_record("BIRT") and my $date = $r->tag_record("DATE")) 0 0 0
Condition0%0/3
$r = $self->tag_record("BIRT") and my $date = $r->tag_record("DATE")
!ll&&!rl&&r
000
MC/DC0%0/2
$r = $self->tag_record("BIRT") and my $date = $r->tag_record("DATE")
$r = $self->tag_record("BIRT") my $date = $r->tag_record("DATE")
Truth table0%0/3
A and B
A= $r = $self->tag_record("BIRT")B= my $date = $r->tag_record("DATE")
ABresult
0X0
100
111
567 0 $d = $date->{value};
568 }
569 0 $s .= sprintf " %16s", $d;
570 0 $s;
571 }
572  
573 15 1;
574  
575 __END__
« blib/lib/Gedcom/LifeLines.pm ↑ Summary parse_grammar »