perlrdf/Command/Translate.pm

filter: Statementstmt 73.3% 33 / 45 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 12 / 12 Podpod 100% 1 / 1 totaltotal 65.7% 46 / 70 CC 8 SCAR 33.2
CC
8
Cov
60%
execute
64.0
BEGIN
1.0
BEGIN
1.0
CRAP 27.5
« perlrdf/Command/Canonicalize.pm ↑ Summary perlrdf/FileSpec/OutputRDF.pm »
1 package App::perlrdf::Command::Translate;
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::Translate::AUTHORITY = 'cpan:TOBYINK';
10 1 $App::perlrdf::Command::Translate::VERSION = '0.006';
11 }
12  
13 1 ▶use App::perlrdf -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 sub skolem ($)
16 {
17 require Data::UUID;
18 require RDF::Trine;
19
20 my $model = shift;
21 my %map;
22 my $uuid = Data::UUID->new;
23 my @statements =
24 grep { $_->has_blanks }
25 $model->get_statements(undef, undef, undef, undef)->get_all;
26 $model->remove_statement($_) for @statements;
27 $model->add_statement($_)
28 for map {
29 my $st = $_;
30 my @nodes =
31 map {
32 if ($_->is_blank)
33 {
34 $map{ $_->blank_identifier }
35 ||= RDF::Trine::Node::Resource->new(
36 sprintf 'urn:uuid:%s', lc $uuid->create_str
37 )
38 }
39 else
40 {
41 $_
42 }
43 }
44 $st->nodes;
45 @nodes==4
46 ? RDF::Trine::Statement::Quad->new(@nodes)
47 : RDF::Trine::Statement->new(@nodes)
48 }
49 @statements;
50 }
51  
52 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54 1 ▶use constant abstract => q (Parse/serialise some RDF.);
Subroutine BEGIN: called CC=1 SCAR=0.0
55 1 ▶use constant command_names => qw( translate tr parse serialise serialize );
Subroutine BEGIN: called CC=1 SCAR=0.0
56 1 ▶use constant description => <<'DESCRIPTION';
Subroutine BEGIN: called CC=1 SCAR=0.0
57 Parses the input as RDF in various serialisations, and re-serialises it
58 in your choice of serialisation.
59  
60 Input may be a URL, filename or STDIN. If multiple inputs are sepcified,
61 these are merged into a single graph.
62  
63 Output may be a URL (for HTTP POST), filename of STDOUT. If multiple
64 outputs are specified, the entire graph is written to each of them.
65 DESCRIPTION
66 1 ▶use constant opt_spec => (
Subroutine BEGIN: called CC=1 SCAR=0.0
67 [ 'input|i=s@', 'Input filename or URL' ],
68 [ 'input-spec|I=s@', 'Input file specification' ],
69 [ 'input-format|p=s', 'Input format (mnemonic: parse)' ],
70 [ 'input-base|b=s', 'Input base URI' ],
71 []=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>
72 [ 'output|o=s@', 'Output filename or URL' ],
73 [ 'output-spec|O=s@', 'Output file specification' ],
74 [ 'output-format|s=s', 'Output format (mnemonic: serialise)' ],
75 []=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>=>
76 [ 'skolem|k', 'Transform blank nodes into URIs' ],
77 1 );
78  
79 sub execute
80 1 ▶{
Subroutine execute: called CC=8 SCAR=41.6
Pod documented
81 1 require App::perlrdf::FileSpec::InputRDF;
82 0 require App::perlrdf::FileSpec::OutputRDF;
83 0 require RDF::Trine;
84
85 0 my ($self, $opt, $arg) = @_;
86
87 0 my @inputs = $self->get_filespecs(
88 'App::perlrdf::FileSpec::InputRDF',
89 input => $opt,
90 );
91
92 @inputs = App::perlrdf::FileSpec::InputRDF->new_from_filespec(
93 (shift(@$arg) // '-'),
94 $opt->{input_format},
95 $opt->{input_base},
96 0 ▶ ) unless @inputs;
Branch: 1 branch
BranchTrueFalseTotal
unless @inputs 0 0 0
Condition0%0/2
shift @$arg // "-"
l!l
00
MC/DC0%0/1
shift @$arg // "-"
shift @$arg
Truth table0%0/2
A
A= shift @$arg
Aresult
11
00
97  
98 0 my @outputs = $self->get_filespecs(
99 'App::perlrdf::FileSpec::OutputRDF',
100 output => $opt,
101 );
102
103 @outputs = App::perlrdf::FileSpec::OutputRDF->new_from_filespec(
104 (shift(@$arg) // '-'),
105 $opt->{output_format},
106 undef,
107 0 ▶ ) unless @outputs;
Branch: 1 branch
BranchTrueFalseTotal
unless @outputs 0 0 0
Condition0%0/2
shift @$arg // "-"
l!l
00
MC/DC0%0/1
shift @$arg // "-"
shift @$arg
Truth table0%0/2
A
A= shift @$arg
Aresult
11
00
108
109 0 my $model = RDF::Trine::Model->new;
110 0 $_->parse_into_model($model) for @inputs;
111 0 ▶ skolem $model if $opt->{skolem};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"skolem"} 0 0 0
112 0 $_->serialize_model($model) for @outputs;
113 0 0;
114 }
115  
116 1 1;
117  
« perlrdf/Command/Canonicalize.pm ↑ Summary perlrdf/FileSpec/OutputRDF.pm »