| 1 | package App::perlrdf::Command::Canonicalize; | ||||||||||||||||||||||||||||
| 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::Canonicalize::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||
| 10 | 1 | $App::perlrdf::Command::Canonicalize::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 (Generate canonical N-Triples from an input file.); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use constant command_names => qw( canonicalize canonicalise ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use constant description => <<'DESCRIPTION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | Converts an input file into canonical N-Triples. The idea of canonical | ||||||||||||||||||||||||||||
| 20 | N-Triples is that blank node identifiers are normalised to a predictable | ||||||||||||||||||||||||||||
| 21 | pattern; and statements are serialized in a predictable order. It is | ||||||||||||||||||||||||||||
| 22 | useful as a canonical serialization for graph signing or generating a | ||||||||||||||||||||||||||||
| 23 | SHA1/MD5 digest of a graph. | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | Not all RDF graphs can be fully canonicalized. The on-fail option allows | ||||||||||||||||||||||||||||
| 26 | you to decide what is done with the extra triples left over from | ||||||||||||||||||||||||||||
| 27 | canonicalization. May be set to "truncate" (the default), "append", | ||||||||||||||||||||||||||||
| 28 | "space" or "die". See RDF::Trine::Serializer::NTriples::Canonical | ||||||||||||||||||||||||||||
| 29 | for more details. | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | See <http://www.hpl.hp.com/techreports/2003/HPL-2003-142.pdf>. | ||||||||||||||||||||||||||||
| 32 | DESCRIPTION | ||||||||||||||||||||||||||||
| 33 | 1 | ▶ | use constant opt_spec => ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | [ 'input|i=s', 'Input filename or URL' ], | ||||||||||||||||||||||||||||
| 35 | [ 'input-spec|I=s', 'Input file specification' ], | ||||||||||||||||||||||||||||
| 36 | [ 'input-format|p=s', 'Input format (mnemonic: parse)' ], | ||||||||||||||||||||||||||||
| 37 | [ 'input-base|b=s', 'Input base URI' ], | ||||||||||||||||||||||||||||
| 38 | []=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=> | ||||||||||||||||||||||||||||
| 39 | [ 'output|o=s', 'Output filename or URL' ], | ||||||||||||||||||||||||||||
| 40 | []=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=> | ||||||||||||||||||||||||||||
| 41 | [ 'on-fail|x=s', 'Behaviour when graphs cannot be canonicalized' ], | ||||||||||||||||||||||||||||
| 42 | 1 | ); | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 1 | ▶ | use constant usage_desc => '%c canonicalize %o INPUT [OUTPUT]'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | sub execute | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 0 | require App::perlrdf::FileSpec::InputRDF; | |||||||||||||||||||||||||||
| 49 | 0 | require App::perlrdf::FileSpec::OutputRDF; | |||||||||||||||||||||||||||
| 50 | 0 | require RDF::Trine::Serializer::NTriples::Canonical; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | my ($self, $opt, $arg) = @_; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | $opt->{output_format} = 'RDF::Trine::Serializer::NTriples::Canonical'; | |||||||||||||||||||||||||||
| 55 | 0 | ▶ | $opt->{on_fail} //= 'truncate'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opt->{"on_fail"} //= "truncate"
MC/DC0%0/1
$opt->{"on_fail"} //= "truncate"
$opt->{"on_fail"}
Truth table0%0/2
A
A= $opt->{"on_fail"}
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | my @inputs = $self->get_filespecs( | |||||||||||||||||||||||||||
| 58 | 'App::perlrdf::FileSpec::InputRDF', | ||||||||||||||||||||||||||||
| 59 | input => $opt, | ||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | @inputs = App::perlrdf::FileSpec::InputRDF->new_from_filespec( | ||||||||||||||||||||||||||||
| 63 | (shift(@$arg) // '-'), | ||||||||||||||||||||||||||||
| 64 | $opt->{input_format}, | ||||||||||||||||||||||||||||
| 65 | $opt->{input_base}, | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | ) unless @inputs; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
shift @$arg // "-"
MC/DC0%0/1
shift @$arg // "-"
shift @$arg
Truth table0%0/2
A
A= shift @$arg
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | my @outputs = $self->get_filespecs( | |||||||||||||||||||||||||||
| 69 | 'App::perlrdf::FileSpec::OutputRDF', | ||||||||||||||||||||||||||||
| 70 | output => $opt, | ||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | @outputs = App::perlrdf::FileSpec::OutputRDF->new_from_filespec( | ||||||||||||||||||||||||||||
| 74 | (shift(@$arg) // '-'), | ||||||||||||||||||||||||||||
| 75 | $opt->{output_format}, | ||||||||||||||||||||||||||||
| 76 | undef, | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | ) unless @outputs; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
shift @$arg // "-"
MC/DC0%0/1
shift @$arg // "-"
shift @$arg
Truth table0%0/2
A
A= shift @$arg
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | $self->usage_error("Need exactly one input source and one output destination") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@inputs == 1 and @outputs == 1
MC/DC0%0/2
@inputs == 1 and @outputs == 1
@inputs == 1
@outputs == 1
Truth table0%0/3
A and B
A= @inputs == 1B= @outputs == 1
| |||||||||||||||||||||||||||||
| 80 | unless @inputs==1 and @outputs==1; | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | my $in = RDF::Trine::Model->new; | |||||||||||||||||||||||||||
| 83 | 0 | $inputs[0]->parse_into_model($in); | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | my $ser = RDF::Trine::Serializer::NTriples::Canonical::->new( | ||||||||||||||||||||||||||||
| 86 | onfail => $opt->{on_fail}, | ||||||||||||||||||||||||||||
| 87 | 0 | ); | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | $ser->serialize_model_to_file($outputs[0]->handle, $in); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 1 | 1; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||