| 1 | package JSON::Schema::Generator; | ||||||||||||||||||||||
| 2 | 2 | ▶ | use 5.008001; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | |||||||||||||||||||||||
| 6 | 2 | our $VERSION = "0.01"; | |||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | 2 | ▶ | use JSON::Schema::Generator::Handler::Array; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | 2 | ▶ | use JSON::Schema::Generator::Handler::Atom; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 10 | 2 | ▶ | use JSON::Schema::Generator::Handler::Maybe::Lifted; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | 2 | ▶ | use JSON::Schema::Generator::Handler::Object; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 12 | 2 | ▶ | use JSON::Schema::Generator::Handler::Union; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 13 | 2 | ▶ | use JSON::TypeInference; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 14 | |||||||||||||||||||||||
| 15 | 1 | ▶ | sub new { | ||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 16 | 1 | my ($class) = @_; | |||||||||||||||||||||
| 17 | 1 | return bless { learned_data => [] }, $class; | |||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | 3 | ▶ | sub learn { | ||||||||||||||||||||
|
Subroutine
learn: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 21 | 3 | my ($self, $data) = @_; | |||||||||||||||||||||
| 22 | 3 | push @{$self->{learned_data}}, $data; | |||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||
| 24 | |||||||||||||||||||||||
| 25 | 1 | ▶ | sub generate { | ||||||||||||||||||||
|
Subroutine
generate: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 26 | 1 | my ($self) = @_; | |||||||||||||||||||||
| 27 | 1 | my $inferred_type = JSON::TypeInference->infer($self->{learned_data}); | |||||||||||||||||||||
| 28 | return { | ||||||||||||||||||||||
| 29 | '$schema' => 'http://json-schema.org/draft-04/schema#', | ||||||||||||||||||||||
| 30 | title => 'TODO', | ||||||||||||||||||||||
| 31 | description => 'TODO', | ||||||||||||||||||||||
| 32 | 1 | %{_dispatch($inferred_type, $self->{learned_data})}, | |||||||||||||||||||||
| 33 | }; | ||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||
| 35 | |||||||||||||||||||||||
| 36 | 8 | ▶ | sub _dispatch { | ||||||||||||||||||||
|
Subroutine
_dispatch: called CC=5 SCAR=16.1
| |||||||||||||||||||||||
| 37 | 8 | my ($type, $examples) = @_; | |||||||||||||||||||||
| 38 | 8 | my $dispatch = \&_dispatch; | |||||||||||||||||||||
| 39 | 8 | ▶ | if ($type->name eq 'array') { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 40 | 1 | return JSON::Schema::Generator::Handler::Array->process($type, $examples, $dispatch); | |||||||||||||||||||||
| 41 | } elsif ($type->name eq 'object') { | ||||||||||||||||||||||
| 42 | 1 | return JSON::Schema::Generator::Handler::Object->process($type, $examples, $dispatch); | |||||||||||||||||||||
| 43 | } elsif ($type->name eq 'union') { | ||||||||||||||||||||||
| 44 | 1 | return JSON::Schema::Generator::Handler::Union->process($type, $examples, $dispatch); | |||||||||||||||||||||
| 45 | } elsif ($type->name eq 'maybe') { | ||||||||||||||||||||||
| 46 | 1 | return JSON::Schema::Generator::Handler::Maybe::Lifted->process($type, $examples, $dispatch); | |||||||||||||||||||||
| 47 | } else { | ||||||||||||||||||||||
| 48 | 4 | return JSON::Schema::Generator::Handler::Atom->process($type, $examples, $dispatch); | |||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||
| 51 | |||||||||||||||||||||||
| 52 | 2 | 1; | |||||||||||||||||||||
| 53 | __END__ | ||||||||||||||||||||||