blib/lib/Gedcom/Grammar.pm

filter: Statementstmt 95.3% 62 / 65 Branchbran 78.5% 22 / 28 Conditioncond 66.6% 4 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 90.9% 10 / 11 Podpod 83.3% 5 / 6 totaltotal 86.6% 104 / 120 CC 19 SCAR 17.3
CC
19
Cov
89%
_valid_items
11.0
max
3.0
structure
3.0
CRAP 5.6
« blib/lib/Gedcom.pm ↑ Summary blib/lib/Gedcom/CGI.pm »
1 # Copyright 1998-2013, 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::Grammar;
15  
16 15 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 15 ▶use Gedcom::Item 1.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 15 ▶use vars qw($VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 15 $VERSION = "1.20";
22 15 @ISA = qw( Gedcom::Item );
23  
24 sub structure {
25 708 ▶ my $self = shift;
Subroutine structure: called CC=3 SCAR=11.0
Pod undocumented
26 708 my ($struct) = @_;
27 708 ▶ unless (exists $self->{top}{structures}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"top"}{"structures"}) 11 697 708
28 $self->{top}{structures} = {
29 319 ▶ map { $_->{structure} ? ($_->{structure} => $_) : () }
Branch: 1 branch
BranchTrueFalseTotal
$_->{'structure'} ? : 319 0 319
30 11 @{$self->{top}{items}}
31 };
32 }
33 # print Dumper $self->{top}{structures};
34 708 $self->{top}{structures}{$struct}
35 }
36  
37 sub item {
38 10468 ▶ my $self = shift;
Subroutine item: called CC=3 SCAR=11.0
Pod documented
39 10468 my ($tag) = @_;
40 10468 ▶ return unless defined $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tag 0 10468 10468
41 10468 my $valid_items = $self->valid_items;
42 # use Data::Dumper; print "[$tag] -- ", Dumper($self), Dumper $valid_items;
43 10468 ▶ return unless exists $valid_items->{$tag};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $valid_items->{$tag} 8 10460 10468
44 10460 map { $_->{grammar} } @{$valid_items->{$tag}}
45 }
46  
47 sub min {
48 2408 ▶ my $self = shift;
Subroutine min: called CC=2 SCAR=7.2
Pod documented
49 2408 ▶ exists $self->{min} ? $self->{min} : 1
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'min'} ? : 2408 0 2408
50 }
51  
52 sub max {
53 2408 ▶ my $self = shift;
Subroutine max: called CC=3 SCAR=11.1
Pod documented
54 2408 ▶ exists $self->{max} ? $self->{max} eq "M" ? 0 : $self->{max} : 1
Branch: 2 branches
BranchTrueFalseTotal
exists $self->{'max'} ? : 2408 0 2408
$self->{'max'} eq 'M' ? : 529 1879 2408
55 }
56  
57 sub items {
58 0 ▶ my $self = shift;
Subroutine items: not called CC=1 SCAR=6.9
Pod documented
59 0 keys %{$self->valid_items}
60 }
61  
62 sub _valid_items {
63 769 ▶ my $self = shift;
Subroutine _valid_items: called CC=11 SCAR=24.0
64 769 my %valid_items;
65 769 for my $item (@{$self->{items}}) {
66 2408 my $min = $item->min;
67 2408 my $max = $item->max;
68 2408 ▶ if ($item->{tag}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item->{'tag'}) { } 1712 696 2408
69 1712 push @{$valid_items{$item->{tag}}}, {
70 grammar => $item,
71 min => $min,
72 max => $max
73 };
74 } else {
75 die "What's a " . Data::Dumper->new([$item], ["grammar"])
76 696 ▶ unless my ($value) = $item->{value} =~ /<<(.*)>>/;
Branch: 1 branch
BranchTrueFalseTotal
unless my($value) = $item->{"value"} =~ /<<(.*)>>/ 0 696 696
77 696 ▶ die "Can't find $value in gedcom structures"
Branch: 1 branch
BranchTrueFalseTotal
unless my $structure = $self->structure($value) 0 696 696
78 unless my $structure = $self->structure($value);
79 696 $item->{structure} = $structure;
80 696 ▶ while (my($tag, $g) = each %{$structure->valid_items}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$structure->valid_items;}) 2994 696 3690
81 2994 push @{$valid_items{$tag}}, map {
82 grammar => $_->{grammar},
83 # min and max can be calculated by multiplication because
84 # the grammar always permits multiple selection records, and
85 # selection records never have compulsory records. This may
86 # change in future grammars, but I would not expect it to -
87 # such a grammar would seem to have little practical use.
88 min => $_->{min} * $min,
89 2994 max => $_->{max} * $max
90 }, @$g;
91 }
92 696 ▶ if (exists $item->{items} && @{$item->{items}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $item->{"items"} and @{$item->{"items"};}) 11 685 696
Condition66%2/3
exists $item->{"items"} and @{$item->{"items"};}
!ll&&!rl&&r
068511
MC/DC50%1/2
exists $item->{"items"} and @{$item->{"items"};}
exists $item->{"items"} @{$item->{"items"};}
Truth table66%2/3
A and B
A= exists $item->{"items"}B= @{$item->{"items"};}
ABresult
0X0
100
111
93 11 my $extra_items = $item->_valid_items;
94 11 ▶ while (my ($sub_item, $sub_grammars) = each %valid_items) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %valid_items) 121 11 132
95 121 for my $sub_grammar (@$sub_grammars) {
96 121 $sub_grammar->{grammar}->valid_items;
97 121 ▶ while (my ($i, $g) = each %$extra_items) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$extra_items) 242 121 363
98 # print "adding $i to $sub_item\n";
99 242 $sub_grammar->{grammar}{_valid_items}{$i} = $g;
100 }
101 }
102 # print "giving @{[keys %{$sub_grammar->{grammar}->valid_items}]}\n";
103 }
104 }
105 }
106 }
107 # print "valid items are @{[keys %valid_items]}\n";
108 769 \%valid_items
109 }
110  
111 sub valid_items {
112 67768 ▶ my $self = shift;
Subroutine valid_items: called CC=2 SCAR=7.1
Pod documented
113 67768 ▶ $self->{_valid_items} ||= $self->_valid_items
Condition66%2/3
$self->{"_valid_items"} ||= $self->_valid_items
l!l&&r!l&&!r
670107580
MC/DC0%0/2
$self->{"_valid_items"} ||= $self->_valid_items
$self->{"_valid_items"} $self->_valid_items
Truth table66%2/3
A ||= B
A= $self->{"_valid_items"}B= $self->_valid_items
ABresult
1X1
011
000
114 }
115  
116 15 1;
117  
118 __END__
« blib/lib/Gedcom.pm ↑ Summary blib/lib/Gedcom/CGI.pm »