| 1 | package JSON::Schema::Generate; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use 5.006; use strict; use warnings; our $VERSION = '0.15'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use Tie::IxHash; use Types::Standard qw/Str HashRef Bool/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use Compiled::Params::OO qw/cpo/; use JSON; use Blessed::Merge; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 9 | our ($validate, $JSON); | |||||||||||||||||||||||||||||||||||||||||||||
| 7 | 9 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=4.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | $validate = cpo( | ||||||||||||||||||||||||||||||||||||||||||||||
| 9 | new => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 10 | id => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | type => Str, | ||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | 'http://example.com/root.json' | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | title => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | type => Str, | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | 'The Root Schema' | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | description => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | type => Str, | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | 'The root schema is the schema that comprises the entire JSON document.' | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | schema => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | type => Str, | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | 'http://json-schema.org/draft-07/schema#' | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | spec => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | type => HashRef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | default => sub { { } } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | merge_examples => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | type => Bool, | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | default => sub { !!0 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | none_required => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | type => Bool, | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | default => sub { !!0 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | no_id => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | type => Bool, | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | default => sub { !!0 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | no_title => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | type => Bool, | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | default => sub { !!0 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | no_description => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | type => Bool, | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | default => sub { !!0 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | no_example => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | type => Bool, | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | default => sub { !!0 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | minimal_schema => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | type => Bool, | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | default => sub { !!0 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 9 | ); | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 9 | $JSON = JSON->new->canonical->pretty; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $args = $validate->new->(@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $self->{schema} = _tie_hash(); | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | $self->{schema}{'$schema'} = $args->schema; | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $self->{schema}{'$id'} = $args->id; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $self->{schema}{title} = $args->title; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $self->{schema}{description} = $args->description; | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $self->{$_} = $args->$_ for qw/spec merge_examples none_required no_id no_title no_description no_example minimal_schema/; | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if ($args->merge_examples) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $self->{merge} = Blessed::Merge->new( | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | blessed => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | unique_array => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | unique_hash => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | same => 0 | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ($self->{minimal_schema}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # make sure all the other no_* features are turned on | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | $self->{$_} = 1 for qw/no_id no_title no_description no_example/; | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub learn { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
learn: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | $_[0]->{data} = ref $_[1] ? $_[1] : $JSON->decode($_[1]); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $_[0]->{data_runs}++; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $_[0]->_build_props($_[0]->{schema}, $_[0]->{data}, '#'); | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | return $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub generate { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | my ($self, $struct) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | $self->_handle_required($self->{schema}) unless $self->{none_required}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | return $struct ? $self->{schema} : $JSON->encode($self->{schema}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub _handle_required { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_required: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my ($self, $schema) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my $total_runs = $self->{data_runs}; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | if ($schema->{required}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my @required; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | for my $key (keys %{$schema->{required}}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if ($schema->{required}->{$key} == $total_runs) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | push @required, $key; | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $schema->{required} = \@required; | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ($schema->{properties}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $self->_handle_required($schema->{properties}{$_}) for keys %{$schema->{properties}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | $self->_handle_required($schema->{items}) if $schema->{items}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | sub _build_props { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_props: not called CC=30 SCAR=68.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my ($self, $props, $data, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $ref = ref $data; | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | if ($ref eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $self->_add_type($props, 'object'); | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $self->_unique_examples($props, $data); | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | return if ref $props->{type}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | if (!$props->{properties}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | $props->{required} = _tie_hash() unless $self->{none_required}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $props->{properties} = _tie_hash(); | |||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | for my $key (sort keys %{$data}) { | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | $props->{required}->{$key}++ unless $self->{none_required}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | my $id = $path . ( $path eq '#' ? '' : '-' ) . 'properties-' . $key; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | unless ($props->{properties}{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $props->{properties}{$key} = _tie_hash(); | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | %{$props->{properties}{$key}} = ( | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | ($self->{no_id} ? () : ('$id' => $id)), | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | ($self->{no_title} ? () : (title => 'The title')), | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | ($self->{no_description} ? () : (description => 'An explanation about the purpose of this instance')), | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | ($self->{spec}->{$key} ? %{$self->{spec}->{$key}} : ()) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $self->_build_props($props->{properties}{$key}, $data->{$key}, $id); | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } elsif ($ref eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | $self->_add_type($props, 'array'); | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | my $id = $path . '-items'; | |||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | unless ($props->{items}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $props->{items} = _tie_hash(); | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | $props->{items}{'$id'} = $id unless $self->{no_id}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | $props->{items}{title} = 'The Items Schema' unless $self->{no_title}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | $props->{items}{description} = 'An explanation about the purpose of this instance.' unless $self->{no_description}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | map { | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $self->_build_props($props->{items}, $_, $id); | |||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | } @{$data} | |||||||||||||||||||||||||||||||||||||||||||||
| 165 | } elsif (! defined $data) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | $self->_add_type($props, 'null'); | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | $self->_unique_examples($props, undef) unless $self->{no_example}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | ▶ | } elsif ($ref eq 'SCALAR' || $ref =~ m/Boolean$/) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$ref eq "SCALAR" or $ref =~ /Boolean$/
MC/DC0%0/2
$ref eq "SCALAR" or $ref =~ /Boolean$/
$ref eq "SCALAR"
$ref =~ /Boolean$/
Truth table0%0/3
A or B
A= $ref eq "SCALAR"B= $ref =~ /Boolean$/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | $self->_add_type($props, 'boolean'); | |||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | $self->_unique_examples($props, \1, \0) unless $self->{no_example}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } elsif ($data =~ m/^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | $self->_add_type($props, 'integer'); | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | $self->_unique_examples($props, $data) unless $self->{no_example}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } elsif ($data =~ m/^\d+\.\d+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $self->_add_type($props, 'number'); | |||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | $self->_unique_examples($props, $data) unless $self->{no_example}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } elsif ($data =~ m/\d{4}\-\d{2}\-\d{2}T\d{2}\:\d{2}\:\d{2}\+\d{2}\:\d{2}/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $self->_add_type($props, 'date-time'); | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | ▶ | $self->_unique_examples($props, $data) unless $self->{no_example}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $self->_add_type($props, 'string'); | |||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | $self->_unique_examples($props, $data) unless $self->{no_example}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | return $props; | |||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | sub _tie_hash { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tie_hash: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | my %properties; | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | tie %properties, 'Tie::IxHash'; | |||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | return \%properties; | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | sub _add_type { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_type: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | my ($self, $props, $type) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if (!$props->{type}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $props->{type} = $type; | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | } elsif ($props->{type} ne $type) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | $props->{type} = [ $props->{type} ] unless ref $props->{type}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | push @{$props->{type}}, $type unless grep { $type eq $_ } @{$props->{type}}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | sub _unique_examples { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unique_examples: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my ($self, $props, @examples) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | return if ($self->{no_example}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | for my $example (@examples) { | |||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | if ((ref($example) || 'SCALAR') ne 'SCALAR' && $props->{examples} && $self->{merge_examples}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/8
(ref $example || "SCALAR") ne "SCALAR" and $props->{"examples"} and $self->{"merge_examples"}
(ref $example || "SCALAR") ne "SCALAR" and $props->{"examples"}
ref $example || 'SCALAR'
MC/DC0%0/3
(ref $example || "SCALAR") ne "SCALAR" and $props->{"examples"} and $self->{"merge_examples"}
ref $example
$props->{"examples"}
$self->{"merge_examples"}
Truth table0%0/4
A and B and C
A= ref $exampleB= $props->{"examples"}C= $self->{"merge_examples"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $props->{examples}->[0] = $self->{merge}->merge($props->{examples}->[0], $example); | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | unless (grep { ($_//"") eq ($example//"") } @{$props->{examples}}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/4
$_ // ""
$example // ""
MC/DC0%0/1
$_ // ""
$_
MC/DC0%0/1
$example // ""
$example
Truth table0%0/2
A
A= $_
Truth table0%0/2
A
A= $example
| |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | push @{$props->{examples}}, $example; | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||