Query/Select.pm

filter: Statementstmt 97.8% 46 / 47 Branchbran 91.6% 11 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 97.0% 66 / 68 CC 10 SCAR 15.9
CC
10
Cov
97%
select_value
8.0
_property
3.1
BEGIN
1.0
CRAP 4.9
↑ Summary Query/Count.pm »
1 package WQS::SPARQL::Query::Select;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Class::Utils qw(set_params);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 sub new {
10 3 ▶ my ($class, @params) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
11  
12 # Create object.
13 3 my $self = bless {}, $class;
14  
15 # Process parameters.
16 3 set_params($self, @params);
17  
18 3 return $self;
19 }
20  
21 sub select_value {
22 6 ▶ my ($self, $property_pairs_hr, $filter_ar) = @_;
Subroutine select_value: called CC=8 SCAR=20.8
Pod documented
23  
24 6 my %sort;
25 6 foreach my $property (keys %{$property_pairs_hr}) {
26 8 ▶ if ($property !~ m/^P(\d+)(\/P\d+\*?)?$/ms) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($property =~ m[^P(\d+)(/P\d+\*?)?$]ms) 1 7 8
27 1 err "Bad property '$property'.";
28 }
29 7 $sort{$property} = $1;
30 }
31  
32 5 my $sparql = "SELECT ?item WHERE {\n";
33 5 foreach my $property (sort { $sort{$a} <=> $sort{$b} } keys %{$property_pairs_hr}) {
34 7 my $property_wdt = $self->_property($property);
35  
36 7 my $value = $property_pairs_hr->{$property};
37 7 ▶ if ($value =~ m/^Q\d+$/ms) {
Branch: 3 branches
BranchTrueFalseTotal
if ($value =~ /^Q\d+$/ms) { } 3 4 7
elsif ($value =~ /^\?/ms) { } 1 3 4
elsif ($value =~ /^(.*?)(\@\w\w)$/ms) { } 1 2 3
38 3 $value = "wd:$value";
39 } elsif ($value =~ m/^\?/ms) {
40 # same
41 } elsif ($value =~ m/^(.*?)(@\w\w)$/ms) {
42 1 $value = "'$1'$2";
43 } else {
44 2 $value = "'$value'";
45 }
46  
47 7 $sparql .= " ?item $property_wdt $value.\n"
48 }
49 5 foreach my $filter_item_ar (@{$filter_ar}) {
50 1 $sparql .= ' FILTER('.$filter_item_ar->[0].' '.$filter_item_ar->[1].' '.$filter_item_ar->[2].')'."\n";
51 }
52 5 $sparql .= "}\n";
53  
54 5 return $sparql;
55 }
56  
57 sub _property {
58 7 ▶ my ($self, $property_key) = @_;
Subroutine _property: called CC=3 SCAR=11.2
59  
60 7 my $property_wdt;
61 7 ▶ if ($property_key =~ m/^P\d+$/ms) {
Branch: 2 branches
BranchTrueFalseTotal
if ($property_key =~ /^P\d+$/ms) { } 6 1 7
elsif ($property_key =~ m[^(P\d+)/(P\d+\*?)$]ms) { } 1 0 1
62 6 $property_wdt = 'wdt:'.$property_key;
63 } elsif ($property_key =~ m/^(P\d+)\/(P\d+\*?)$/ms) {
64 1 $property_wdt = 'wdt:'.$1.'/wdt:'.$2;
65 } else {
66 0 err "Property doesn't supported.",
67 'property_key', $property_key,
68 ;
69 }
70  
71 7 return $property_wdt;
72 }
73  
74 4 1;
75  
76 __END__
↑ Summary Query/Count.pm »