lib/ClarID/Tools/Command/validate.pm

filter: Statementstmt 98.1% 54 / 55 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 94.4% 17 / 18 Podpod 100% 2 / 2 totaltotal 97.3% 73 / 75 CC 1 SCAR 0.5
CC
1
Cov
98%
abstract
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« lib/ClarID/Tools/Util.pm ↑ Summary lib/ClarID/Tools.pm »
1 package ClarID::Tools::Command::validate;
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use open qw(:std :utf8); # <-- turn on UTF-8 for STDIN/STDOUT/STDERR
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use feature 'say';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use File::Spec::Functions qw(catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 use MooX::Options
10 6 ▶ auto_help => 1,
Subroutine BEGIN: called CC=1 SCAR=0.0
11 usage => 'pod',
12 6 version => $ClarID::Tools::VERSION;
13 6 ▶use JSON::XS qw(decode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use Path::Tiny qw(path);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use ClarID::Tools::Validator;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use ClarID::Tools::Util qw(load_yaml_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 # Tell App::Cmd this is a command
18 6 ▶use App::Cmd::Setup -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 6 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 1 ▶ default => sub { catfile( $ClarID::Tools::share_dir, 'clarid-codebook-schema.json' ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
37 6 doc => 'path to JSON Schema file',
38 );
39  
40 option debug => (
41 is => 'ro',
42 is_flag => 1,
43 6 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
44 6 doc => 'self-validate the schema before use',
45 );
46 0 ▶sub abstract { "validate a codebook against its JSON schema" }
Subroutine abstract: not called CC=1 SCAR=6.9
Pod documented
47  
48 6 ▶sub execute {
Subroutine execute: called CC=1 SCAR=0.0
Pod documented
49 6 my ($self, $opts, @args) = @_;
50  
51 6 my $cb_data = load_yaml_file( $self->codebook );
52 5 my $schema_txt = path( $self->schema )->slurp_utf8;
53 4 my $schema = decode_json( $schema_txt );
54  
55 4 ClarID::Tools::Validator::validate_codebook(
56 $cb_data,
57 $schema,
58 $self->debug,
59 );
60  
61 2 say "✅ Codebook is valid";
62 }
63  
64 6 1;
« lib/ClarID/Tools/Util.pm ↑ Summary lib/ClarID/Tools.pm »