| 1 | package JQ::Lite; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 182 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 182 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 182 | ▶ | use JSON::PP (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 182 | ▶ | use JQ::Lite::Evaluator; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 182 | ▶ | use JQ::Lite::Parser; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 182 | ▶ | use JQ::Lite::Runtime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 182 | our $VERSION = '2.59'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 163 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 15 | 163 | my ($class, %opts) = @_; | |||||||||||||||||||||||||||
| 16 | 163 | my $base_vars = {}; | |||||||||||||||||||||||||||
| 17 | 163 | ▶ | if (exists $opts{vars} && ref $opts{vars} eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $opts{"vars"} and ref $opts{"vars"} eq "HASH"
MC/DC50%1/2
exists $opts{"vars"} and ref $opts{"vars"} eq "HASH"
exists $opts{"vars"}
ref $opts{"vars"} eq "HASH"
Truth table66%2/3
A and B
A= exists $opts{"vars"}B= ref $opts{"vars"} eq "HASH"
| |||||||||||||||||||||||||||||
| 18 | 45 | $base_vars = { %{ $opts{vars} } }; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | my $self = { | ||||||||||||||||||||||||||||
| 22 | raw => $opts{raw} || 0, | ||||||||||||||||||||||||||||
| 23 | _base_vars => $base_vars, | ||||||||||||||||||||||||||||
| 24 | 163 | ▶ | _vars => { %{$base_vars} }, | ||||||||||||||||||||||||||
|
Condition50%1/2
$opts{'raw'} || 0
MC/DC0%0/1
$opts{'raw'} || 0
$opts{'raw'}
Truth table50%1/2
A
A= $opts{'raw'}
| |||||||||||||||||||||||||||||
| 25 | }; | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 163 | return bless $self, $class; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 6052 | ▶ | sub run_query { | ||||||||||||||||||||||||||
|
Subroutine
run_query: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 6052 | my ($self, $json_text, $query) = @_; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 6052 | ▶ | my $depth = $self->{_query_depth} || 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'_query_depth'} || 0
MC/DC100%1/1
$self->{'_query_depth'} || 0
$self->{'_query_depth'}
Truth table100%2/2
A
A= $self->{'_query_depth'}
| |||||||||||||||||||||||||||||
| 34 | 6052 | local $self->{_query_depth} = $depth + 1; | |||||||||||||||||||||||||||
| 35 | 6052 | ▶ | if ($depth == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 5846 | ▶ | local $self->{_vars} = { %{ $self->{_base_vars} || {} } }; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'_base_vars'} || {}
MC/DC0%0/1
$self->{'_base_vars'} || {}
$self->{'_base_vars'}
Truth table50%1/2
A
A= $self->{'_base_vars'}
| |||||||||||||||||||||||||||||
| 37 | 5846 | return _run_query_internal($self, $json_text, $query); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 206 | return _run_query_internal($self, $json_text, $query); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 6052 | ▶ | sub _run_query_internal { | ||||||||||||||||||||||||||
|
Subroutine
_run_query_internal: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 44 | 6052 | my ($self, $json_text, $query) = @_; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 6052 | my $runtime = JQ::Lite::Runtime->new(owner => $self); | |||||||||||||||||||||||||||
| 47 | 6052 | my $data = $runtime->decode_input($json_text); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 6051 | ▶ | return ($data) if !defined $query || $query =~ /^\s*\.\s*$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $query or $query =~ /^\s*\.\s*$/
MC/DC50%1/2
not defined $query or $query =~ /^\s*\.\s*$/
not defined $query
$query =~ /^\s*\.\s*$/
Truth table66%2/3
not(A) or B
A= not defined $queryB= $query =~ /^\s*\.\s*$/
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1039 | my $ast = JQ::Lite::Parser::parse_ast($query); | |||||||||||||||||||||||||||
| 52 | 1038 | my $evaluator = JQ::Lite::Evaluator->new(runtime => $runtime); | |||||||||||||||||||||||||||
| 53 | 1038 | return $evaluator->evaluate($ast, $data); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 182 | 1; | |||||||||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||||||||||