| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package ClarID::Tools::Command::validate; |
|
2
|
5
|
|
|
5
|
|
35
|
use strict; |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
221
|
|
|
3
|
5
|
|
|
5
|
|
28
|
use warnings; |
|
|
5
|
|
|
|
|
8
|
|
|
|
5
|
|
|
|
|
389
|
|
|
4
|
5
|
|
|
5
|
|
33
|
use utf8; |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
37
|
|
|
5
|
5
|
|
|
5
|
|
3019
|
use open qw(:std :utf8); # <-- turn on UTF-8 for STDIN/STDOUT/STDERR |
|
|
5
|
|
|
|
|
7179
|
|
|
|
5
|
|
|
|
|
44
|
|
|
6
|
5
|
|
|
5
|
|
845
|
use feature 'say'; |
|
|
5
|
|
|
|
|
9
|
|
|
|
5
|
|
|
|
|
738
|
|
|
7
|
5
|
|
|
5
|
|
33
|
use File::Spec::Functions qw(catfile); |
|
|
5
|
|
|
|
|
8
|
|
|
|
5
|
|
|
|
|
406
|
|
|
8
|
5
|
|
|
5
|
|
2742
|
use Moo; |
|
|
5
|
|
|
|
|
41308
|
|
|
|
5
|
|
|
|
|
27
|
|
|
9
|
|
|
|
|
|
|
use MooX::Options |
|
10
|
5
|
|
|
|
|
38
|
auto_help => 1, |
|
11
|
|
|
|
|
|
|
usage => 'pod', |
|
12
|
5
|
|
|
5
|
|
25715
|
version => $ClarID::Tools::VERSION; |
|
|
5
|
|
|
|
|
23070
|
|
|
13
|
5
|
|
|
5
|
|
629360
|
use YAML::XS qw(LoadFile); |
|
|
5
|
|
|
|
|
18519
|
|
|
|
5
|
|
|
|
|
452
|
|
|
14
|
5
|
|
|
5
|
|
78
|
use JSON::XS qw(decode_json); |
|
|
5
|
|
|
|
|
25
|
|
|
|
5
|
|
|
|
|
421
|
|
|
15
|
5
|
|
|
5
|
|
37
|
use Path::Tiny qw(path); |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
339
|
|
|
16
|
5
|
|
|
5
|
|
3051
|
use ClarID::Tools::Validator; |
|
|
5
|
|
|
|
|
19
|
|
|
|
5
|
|
|
|
|
464
|
|
|
17
|
|
|
|
|
|
|
# Tell App::Cmd this is a command |
|
18
|
5
|
|
|
5
|
|
40
|
use App::Cmd::Setup -command; |
|
|
5
|
|
|
|
|
12
|
|
|
|
5
|
|
|
|
|
92
|
|
|
19
|
5
|
|
|
5
|
|
4776
|
use namespace::autoclean; |
|
|
5
|
|
|
|
|
61901
|
|
|
|
5
|
|
|
|
|
25
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# CLI options |
|
22
|
|
|
|
|
|
|
# NB: Invalid parameter values (e.g., --format=foo) trigger App::Cmd usage/help |
|
23
|
|
|
|
|
|
|
# This hides the detailed Types::Standard error |
|
24
|
|
|
|
|
|
|
# Fix by overriding usage_error/options_usage |
|
25
|
|
|
|
|
|
|
option codebook => ( |
|
26
|
|
|
|
|
|
|
is => 'ro', |
|
27
|
|
|
|
|
|
|
format => 's', |
|
28
|
|
|
|
|
|
|
required => 1, |
|
29
|
|
|
|
|
|
|
doc => 'path to your codebook.yaml', |
|
30
|
|
|
|
|
|
|
); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
option schema => ( |
|
33
|
|
|
|
|
|
|
is => 'ro', |
|
34
|
|
|
|
|
|
|
format => 's', |
|
35
|
|
|
|
|
|
|
required => 1, |
|
36
|
|
|
|
|
|
|
default => sub { catfile( $ClarID::Tools::share_dir, 'clarid-codebook-schema.json' ) }, |
|
37
|
|
|
|
|
|
|
doc => 'path to JSON Schema file', |
|
38
|
|
|
|
|
|
|
); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
option debug => ( |
|
41
|
|
|
|
|
|
|
is => 'ro', |
|
42
|
|
|
|
|
|
|
is_flag => 1, |
|
43
|
|
|
|
|
|
|
default => sub { 0 }, |
|
44
|
|
|
|
|
|
|
doc => 'self-validate the schema before use', |
|
45
|
|
|
|
|
|
|
); |
|
46
|
0
|
|
|
0
|
1
|
0
|
sub abstract { "validate a codebook against its JSON schema" } |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub execute { |
|
49
|
5
|
|
|
5
|
1
|
131
|
my ($self, $opts, @args) = @_; |
|
50
|
|
|
|
|
|
|
|
|
51
|
5
|
|
|
|
|
70
|
my $cb_data = LoadFile( $self->codebook ); |
|
52
|
5
|
|
|
|
|
8851
|
my $schema_txt = path( $self->schema )->slurp_utf8; |
|
53
|
4
|
|
|
|
|
6495
|
my $schema = decode_json( $schema_txt ); |
|
54
|
|
|
|
|
|
|
|
|
55
|
4
|
|
|
|
|
38
|
ClarID::Tools::Validator::validate_codebook( |
|
56
|
|
|
|
|
|
|
$cb_data, |
|
57
|
|
|
|
|
|
|
$schema, |
|
58
|
|
|
|
|
|
|
$self->debug, |
|
59
|
|
|
|
|
|
|
); |
|
60
|
|
|
|
|
|
|
|
|
61
|
2
|
|
|
|
|
316
|
say "✅ Codebook is valid"; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |