| 1 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | package App::AppSpec::Schema::Validator; | ||||||||||
| 4 | |||||||||||
| 5 | 2 | our $VERSION = 'v0.6.1'; # TRIAL VERSION | |||||||||
| 6 | |||||||||||
| 7 | 2 | ▶ | use App::Spec; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use App::Spec::Schema qw/ $SCHEMA /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use YAML::PP; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | sub validate_spec_file { | ||||||||
|
Subroutine
validate_spec_file: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 13 | 1 | my ($self, $file) = @_; | |||||||||
| 14 | 1 | my $yp = YAML::PP->new( boolean => 'JSON::PP', schema => [qw/ JSON /] ); | |||||||||
| 15 | 1 | my $spec = $yp->load_file($file); | |||||||||
| 16 | 1 | return $self->validate_spec($spec); | |||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | 1 | ▶ | sub validate_spec { | ||||||||
|
Subroutine
validate_spec: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 20 | 1 | my ($self, $spec) = @_; | |||||||||
| 21 | 1 | ▶ | eval { require JSON::Validator } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | or die "JSON::Validator is needed for validating a spec file"; | ||||||||||
| 23 | 1 | my $json_validator = JSON::Validator->new; | |||||||||
| 24 | 1 | $json_validator->schema($SCHEMA); | |||||||||
| 25 | 1 | my @errors = $json_validator->validate($spec); | |||||||||
| 26 | 1 | return @errors; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 0 | ▶ | sub format_errors { | ||||||||
|
Subroutine
format_errors: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 30 | 0 | my ($self, $errors) = @_; | |||||||||
| 31 | 0 | my $output = ''; | |||||||||
| 32 | 0 | for my $error (@$errors) { | |||||||||
| 33 | 0 | $output .= "Path: " . $error->path . "\n"; | |||||||||
| 34 | 0 | $output .= " Message: " . $error->message . "\n"; | |||||||||
| 35 | } | ||||||||||
| 36 | 0 | return $output; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 2 | 1; | |||||||||