blib/lib/SignalWire/Agents/SWML/Schema.pm

filter: Statementstmt 100% 60 / 60 Branchbran 50.0% 3 / 6 Conditioncond 53.3% 8 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 6 totaltotal 77.9% 85 / 109 CC 12 SCAR 17.9
CC
12
Cov
88%
_load_schema
12.2
instance
2.0
BEGIN
1.0
CRAP 6.0
« blib/lib/SignalWire/Agents/SWML/Service.pm ↑ Summary blib/lib/SignalWire/Agents/Skills/Builtin/SwmlTransfer.pm »
1 package SignalWire::Agents::SWML::Schema;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use JSON ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use File::Basename ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # Singleton instance
9 2 my $instance;
10  
11 has 'verbs' => (
12 is => 'ro',
13 2 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
14 2 );
15  
16 has 'schema_data' => (
17 is => 'ro',
18 2 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
19 2 );
20  
21 2 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
22 2 my ($self) = @_;
23 2 $self->_load_schema();
24 }
25  
26 2 ▶sub _load_schema {
Subroutine _load_schema: called CC=11 SCAR=25.0
27 2 my ($self) = @_;
28 2 my $dir = File::Basename::dirname(__FILE__);
29 2 my $schema_file = "$dir/schema.json";
30  
31 2 ▶ open my $fh, '<', $schema_file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $schema_file or die "Cannot open schema.json at ${schema_file}: $!" 2 0 2
32 or die "Cannot open schema.json at $schema_file: $!";
33 2 local $/;
34 2 my $json_text = <$fh>;
35 2 close $fh;
36  
37 2 my $data = JSON::decode_json($json_text);
38 2 $self->{schema_data} = $data;
39  
40 2 ▶ my $defs = $data->{'$defs'} || {};
Condition50%1/2
$data->{'$defs'} || {}
l!l
20
MC/DC0%0/1
$data->{'$defs'} || {}
$data->{'$defs'}
Truth table50%1/2
A
A= $data->{'$defs'}
Aresult
11
00
41 2 ▶ my $swml_method = $defs->{SWMLMethod} || {};
Condition50%1/2
$defs->{'SWMLMethod'} || {}
l!l
20
MC/DC0%0/1
$defs->{'SWMLMethod'} || {}
$defs->{'SWMLMethod'}
Truth table50%1/2
A
A= $defs->{'SWMLMethod'}
Aresult
11
00
42 2 ▶ my $any_of = $swml_method->{anyOf} || [];
Condition50%1/2
$swml_method->{'anyOf'} || []
l!l
20
MC/DC0%0/1
$swml_method->{'anyOf'} || []
$swml_method->{'anyOf'}
Truth table50%1/2
A
A= $swml_method->{'anyOf'}
Aresult
11
00
43  
44 2 my %verbs;
45 2 for my $entry (@$any_of) {
46 76 ▶ my $ref = $entry->{'$ref'} || next;
Condition50%1/2
$entry->{'$ref'} || (next)
l!l
760
MC/DC0%0/1
$entry->{'$ref'} || (next)
$entry->{'$ref'}
Truth table50%1/2
A
A= $entry->{'$ref'}
Aresult
11
00
47 76 (my $def_name) = $ref =~ m{/([^/]+)$};
48 76 ▶ next unless $def_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $def_name 0 76 76
49  
50 76 ▶ my $def = $defs->{$def_name} || next;
Condition50%1/2
$defs->{$def_name} || (next)
l!l
760
MC/DC0%0/1
$defs->{$def_name} || (next)
$defs->{$def_name}
Truth table50%1/2
A
A= $defs->{$def_name}
Aresult
11
00
51 76 ▶ my $props = $def->{properties} || next;
Condition50%1/2
$def->{'properties'} || (next)
l!l
760
MC/DC0%0/1
$def->{'properties'} || (next)
$def->{'properties'}
Truth table50%1/2
A
A= $def->{'properties'}
Aresult
11
00
52  
53 76 my @keys = keys %$props;
54 76 ▶ next unless @keys;
Branch: 1 branch
BranchTrueFalseTotal
unless @keys 0 76 76
55  
56 76 my $verb_name = $keys[0];
57 $verbs{$verb_name} = {
58 schema_name => $def_name,
59 verb_name => $verb_name,
60 76 properties => $props->{$verb_name},
61 };
62 }
63  
64 2 $self->{verbs} = \%verbs;
65 }
66  
67 9 ▶sub instance {
Subroutine instance: called CC=2 SCAR=7.0
Pod undocumented
68 9 my ($class) = @_;
69 9 ▶ $instance //= $class->new();
Condition66%2/3
$instance //= $class->new
l!l&&r!l&&!r
720
MC/DC0%0/2
$instance //= $class->new
$instance $class->new
Truth table66%2/3
A //= B
A= $instanceB= $class->new
ABresult
1X1
011
000
70 9 return $instance;
71 }
72  
73 2 ▶sub get_verb_names {
Subroutine get_verb_names: called CC=1 SCAR=0.0
Pod undocumented
74 2 my ($self) = @_;
75 2 return sort keys %{ $self->verbs };
76 }
77  
78 30 ▶sub has_verb {
Subroutine has_verb: called CC=1 SCAR=0.0
Pod undocumented
79 30 my ($self, $name) = @_;
80 30 return exists $self->verbs->{$name};
81 }
82  
83 3 ▶sub get_verb {
Subroutine get_verb: called CC=1 SCAR=0.0
Pod undocumented
84 3 my ($self, $name) = @_;
85 3 return $self->verbs->{$name};
86 }
87  
88 3 ▶sub verb_count {
Subroutine verb_count: called CC=1 SCAR=0.0
Pod undocumented
89 3 my ($self) = @_;
90 3 return scalar keys %{ $self->verbs };
91 }
92  
93 2 1;
« blib/lib/SignalWire/Agents/SWML/Service.pm ↑ Summary blib/lib/SignalWire/Agents/Skills/Builtin/SwmlTransfer.pm »