| 1 | package JSON::Schema::AsType::Visit; | ||||||||||||||||||||||||||||
| 2 | 27 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||||||||||||||||||||
| 3 | 27 | $JSON::Schema::AsType::Visit::VERSION = '1.0.0'; | |||||||||||||||||||||||||||
| 4 | # ABSTRACT: Visit each node of a schema. | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 27 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 8454 | ▶ | sub visit { | ||||||||||||||||||||||||||
|
Subroutine
visit: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 10 | 8454 | my ( $ref, $fcn ) = @_; | |||||||||||||||||||||||||||
| 11 | 8454 | my $ctx = { _depth => 0 }; | |||||||||||||||||||||||||||
| 12 | 8454 | _visit( $ref, $fcn, $ctx ); | |||||||||||||||||||||||||||
| 13 | 8454 | return $ctx; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 24921 | ▶ | sub _visit { | ||||||||||||||||||||||||||
|
Subroutine
_visit: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||
| 17 | 24921 | my ( $ref, $fcn, $ctx ) = @_; | |||||||||||||||||||||||||||
| 18 | 24921 | my $type = ref($ref); | |||||||||||||||||||||||||||
| 19 | 24921 | ▶ | return if $type eq 'JSON::PP::Boolean'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 24257 | ▶ | croak("'$ref' is not an ARRAY or HASH") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$type eq "ARRAY" or $type eq "HASH"
MC/DC0%0/2
$type eq "ARRAY" or $type eq "HASH"
$type eq "ARRAY"
$type eq "HASH"
Truth table66%2/3
A or B
A= $type eq "ARRAY"B= $type eq "HASH"
| |||||||||||||||||||||||||||||
| 21 | unless $type eq 'ARRAY' || $type eq 'HASH'; | ||||||||||||||||||||||||||||
| 22 | 24257 | ▶ | my @elems = $type eq 'ARRAY' ? ( 0 .. $#$ref ) : ( sort keys %$ref ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 24257 | for my $idx (@elems) { | |||||||||||||||||||||||||||
| 24 | 41591 | my ( $v, $vr ); | |||||||||||||||||||||||||||
| 25 | 41591 | ▶ | $v = $type eq 'ARRAY' ? $ref->[$idx] : $ref->{$idx}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 41591 | ▶ | $vr = $type eq 'ARRAY' ? \( $ref->[$idx] ) : \( $ref->{$idx} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 41591 | local $_ = $v; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 41591 | $fcn->( $idx, $vr, $ctx ); | |||||||||||||||||||||||||||
| 30 | 41591 | ▶ | if ( ref($v) eq 'ARRAY' || ref($v) eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $v eq "ARRAY" or ref $v eq "HASH"
MC/DC100%2/2
ref $v eq "ARRAY" or ref $v eq "HASH"
ref $v eq "ARRAY"
ref $v eq "HASH"
Truth table100%3/3
A or B
A= ref $v eq "ARRAY"B= ref $v eq "HASH"
| |||||||||||||||||||||||||||||
| 31 | 16467 | $ctx->{_depth}++; | |||||||||||||||||||||||||||
| 32 | 16467 | push $ctx->{_path}->@*, $idx; | |||||||||||||||||||||||||||
| 33 | 16467 | _visit( $v, $fcn, $ctx ); | |||||||||||||||||||||||||||
| 34 | 16467 | $ctx->{_depth}--; | |||||||||||||||||||||||||||
| 35 | 16467 | pop $ctx->{_path}->@*; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 27 | 1; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | __END__ | ||||||||||||||||||||||||||||