perlrdf/Command/Validate.pm

filter: Statementstmt 50.0% 35 / 70 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.5% 12 / 17 Podpod 25.0% 1 / 4 totaltotal 47.5% 48 / 101 CC 7 SCAR 15.6
CC
7
Cov
44%
execute
12.0
output_tap_footer
12.0
output_tap_result
6.0
CRAP 4.8
« perlrdf/FileSpec/InputFile.pm ↑ Summary perlrdf/FileSpec.pm »
1 package App::perlrdf::Command::Validate;
2  
3 1 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 $App::perlrdf::Command::Validate::AUTHORITY = 'cpan:TOBYINK';
10 1 $App::perlrdf::Command::Validate::VERSION = '0.006';
11 }
12  
13 1 ▶use App::perlrdf -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶use constant abstract => q (Check syntax of RDF files.);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use constant command_names => qw( validate val );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use constant description => <<'DESCRIPTION';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 Given inputs, parses them and reports any errors.
20  
21 The output conforms to the Test Anything Protocol.
22 DESCRIPTION
23 1 ▶use constant opt_spec => (
Subroutine BEGIN: called CC=1 SCAR=0.0
24 [ 'input|i=s@', 'Input filename or URL' ],
25 [ 'input-spec|I=s@', 'Input file specification' ],
26 [ 'input-format|p=s', 'Input format (mnemonic: parse)' ],
27 [ 'input-base|b=s', 'Input base URI' ],
28 1 );
29 1 ▶use constant usage_desc => '%c validate %o INPUT [INPUT ...]';
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 sub execute
32 0 ▶{
Subroutine execute: not called CC=3 SCAR=24.8
Pod documented
33 0 require App::perlrdf::FileSpec::InputRDF;
34 0 require RDF::Trine;
35 0 require App::perlrdf::DummyModel;
36
37 0 my ($self, $opt, $arg) = @_;
38
39 0 my @inputs = $self->get_filespecs(
40 'App::perlrdf::FileSpec::InputRDF',
41 input => $opt,
42 );
43
44 push @inputs, map {
45 0 App::perlrdf::FileSpec::InputRDF->new_from_filespec(
46 $_,
47 $opt->{input_format},
48 $opt->{input_base},
49 )
50 0 } @$arg;
51  
52 push @inputs,
53 App::perlrdf::FileSpec::InputRDF->new_from_filespec(
54 '-',
55 $opt->{input_format},
56 $opt->{input_base},
57 )
58 0 ▶ unless @inputs;
Branch: 1 branch
BranchTrueFalseTotal
unless @inputs 0 0 0
59  
60 0 $self->output_tap_header(\@inputs);
61 0 for my $in (@inputs)
62 {
63 0 my $model = App::perlrdf::DummyModel::->new;
64 0 my $valid = eval {
65 0 local $@ = undef;
66 0 $in->parse_into_model($model);
67 0 1;
68 };
69 0 $self->output_tap_result($in, $valid, $$model);
70 }
71 0 $self->output_tap_footer(\@inputs);
72 }
73  
74 sub output_tap_header
75 0 ▶{
Subroutine output_tap_header: not called CC=1 SCAR=6.9
Pod undocumented
76 0 my ($self, $inputs) = @_;
77 0 printf("1..%d\n", scalar @$inputs);
78 }
79  
80 sub output_tap_result
81 0 ▶{
Subroutine output_tap_result: not called CC=2 SCAR=17.9
Pod undocumented
82 0 my ($self, $in, $valid, $size) = @_;
83
84 my $parser_name = sub
85 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
86 0 my $f = shift;
87 0 my $p = ref($f->parser);
88 0 ▶ return $1 if $p =~ /^.+::([^:]+?)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $p =~ /^.+::([^:]+?)$/ 0 0 0
89 0 return $p;
90 0 };
91
92 0 ▶ if ($valid)
Branch: 1 branch
BranchTrueFalseTotal
if ($valid) { } 0 0 0
93 {
94 0 ++$self->{tap_pass};
95 printf(
96 "ok %d - %s is valid %s, %d triples\n",
97 ++$self->{tap_total},
98 0 $in->uri,
99 $in->$parser_name,
100 $size,
101 );
102 }
103 else
104 {
105 printf(
106 "not ok %d - %s is broken %s, %d triples before failure\n",
107 ++$self->{tap_total},
108 0 $in->uri,
109 $in->$parser_name,
110 $size,
111 );
112 }
113 }
114  
115 sub output_tap_footer
116 0 ▶{
Subroutine output_tap_footer: not called CC=3 SCAR=24.8
Pod undocumented
117 0 my $self = shift;
118
119 0 my $n = $self->{tap_total} - $self->{tap_pass};
120 0 ▶ $n = 254 if $n > 254;
Branch: 1 branch
BranchTrueFalseTotal
if $n > 254 0 0 0
121
122 0 ▶ if ($n)
Branch: 1 branch
BranchTrueFalseTotal
if ($n) 0 0 0
123 {
124 0 print "# Summary: $self->{tap_pass} ok; $n not ok.\n";
125 }
126
127 0 exit($n);
128 }
129  
130 1 1;
131  
« perlrdf/FileSpec/InputFile.pm ↑ Summary perlrdf/FileSpec.pm »