Fix/aref_query.pm

filter: Statementstmt 97.1% 34 / 35 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 93.8% 46 / 49 CC 4 SCAR 6.0
CC
4
Cov
95%
__ANON__
3.1
emit
2.0
BEGIN
1.0
CRAP 1.8
« Fix/rdf_ldf_statements.pm ↑ Summary RDF.pm »
1 package Catmandu::Fix::aref_query;
2  
3 3 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Catmandu::Fix;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = '0.32';
8  
9 3 with 'Catmandu::Fix::Base';
10  
11 has query => (
12 is => 'ro',
13 5 ▶ coerce => sub { RDF::aREF::Query->new( query => $_[0] ) } # TODO: ns
Subroutine __ANON__: called CC=1 SCAR=0.0
14 3 );
15  
16 3 has path => (
17 is => 'ro',
18 );
19  
20 3 has subject => (
21 is => 'ro',
22 );
23
24 5 ▶around 'BUILDARGS', sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
25 5 my $orig = shift;
26 5 my $self = shift;
27
28 5 ▶ if (@_ == 3) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 3) { } 2 3 5
elsif (@_ == 2) { } 3 0 3
29 2 $orig->($self, subject => $_[0], query => $_[1], path => $_[2] );
30 } elsif (@_ == 2) {
31 3 $orig->($self, query => $_[0], path => $_[1] );
32 } else {
33 0 $orig->($self, @_);
34 }
35 3 };
36  
37 6 ▶sub emit {
Subroutine emit: called CC=2 SCAR=6.9
Pod undocumented
38 6 my ($self, $fixer) = @_;
39  
40 6 ▶ my $subject = defined $self->subject ? $fixer->emit_string($self->subject) : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->subject ? : 2 4 6
41 6 my $path = $fixer->split_path($self->path);
42 6 my $query = $fixer->capture($self->query);
43  
44 # TODO: replace/append/single-value mode
45  
46 6 my $var = $fixer->var;
47 6 my $origin = $fixer->generate_var;
48 6 my $values = $fixer->generate_var;
49  
50 my $perl = join "\n",
51 "my ${origin} = ${subject} // ${var}->{_uri} // ${var}->{_url};",
52 "my ${values} = [ ${query}->apply( ${var}, ${origin} ) ];",
53 6 ▶ $fixer->emit_create_path( $var, $path, sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
54 6 my $var = shift;
55 6 join "\n", map { " $_" } '',
56 "if (is_array_ref(${var})) {",
57 " push \@{${var}}, \@{${values}};",
58 "} else {",
59 " if (defined ${var}) {",
60 " unshift \@{${values}}, ${var};",
61 " }",
62 " ${var} = \@{${values}} > 1 ? ${values} : ${values}->[0];",
63 "}"
64 ;
65 6 });
66  
67 # print $perl."\n";
68  
69 6 return $perl;
70 }
71  
72 3 1;
73 __END__
« Fix/rdf_ldf_statements.pm ↑ Summary RDF.pm »