Query/Functions/Geo.pm

filter: Statementstmt 86.1% 31 / 36 Branchbran 62.5% 5 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 81.0% 47 / 58 CC 6 SCAR 11.3
CC
6
Cov
81%
__ANON__
6.1
BEGIN
2.0
install
1.0
CRAP 3.1
« Query/Algebra/Filter.pm ↑ Summary Query/Plan/Offset.pm »
1 =head1 NAME
2  
3 RDF::Query::Functions::Geo - Geographic extension functions
4  
5 =head1 VERSION
6  
7 This document describes RDF::Query::Functions::Geo version 2.919.
8  
9 =head1 DESCRIPTION
10  
11 Defines the following function:
12  
13 =over
14  
15 =item * java:com.ldodds.sparql.Distance
16  
17 =back
18  
19 =cut
20  
21 package RDF::Query::Functions::Geo;
22  
23 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 35 ▶use Scalar::Util qw(blessed reftype refaddr looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 35 ▶use Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 35 our ($VERSION, $l);
28 35 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
29 35 $l = Log::Log4perl->get_logger("rdf.query.functions.geo");
30 35 $VERSION = '2.919';
31 }
32  
33 35 our $GEO_DISTANCE_LOADED;
34 35 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.0
35 35 $GEO_DISTANCE_LOADED = do {
36 35 eval {
37 35 require Geo::Distance;
38 };
39 35 ▶ ($@) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 35 35
40 };
41 }
42  
43 =begin private
44  
45 =item C<< install >>
46  
47 Documented in L<RDF::Query::Functions>.
48  
49 =end private
50  
51 =cut
52  
53 35 ▶sub install {
Subroutine install: called CC=1 SCAR=0.4
Pod documented
54 RDF::Query::Functions->install_function(
55 "java:com.ldodds.sparql.Distance",
56 17 ▶ sub {
Subroutine __ANON__: called CC=5 SCAR=18.0
57 # http://xmlarmyknife.com/blog/archives/000281.html
58 17 my $query = shift;
59 17 my ($lat1, $lon1, $lat2, $lon2);
60
61 17 ▶ unless ($GEO_DISTANCE_LOADED) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($RDF::Query::Functions::Geo::GEO_DISTANCE_LOADED) 0 17 17
62 0 throw RDF::Query::Error::FilterEvaluationError ( -text => "Cannot compute distance because Geo::Distance is not available" );
63 }
64
65 my $geo = ref($query)
66 17 ▶ ? ($query->{_query_cache}{'java:com.ldodds.sparql.Distance'}{_geo_dist_obj} ||= new Geo::Distance)
Branch: 1 branch
BranchTrueFalseTotal
ref $query ? : 16 1 17
Condition66%2/3
$query->{"_query_cache"}{"java:com.ldodds.sparql.Distance"}{"_geo_dist_obj"} ||= "Geo::Distance"->new
l!l&&r!l&&!r
1420
MC/DC0%0/2
$query->{"_query_cache"}{"java:com.ldodds.sparql.Distance"}{"_geo_dist_obj"} ||= "Geo::Distance"->new
$query->{"_query_cache"}{"java:com.ldodds.sparql.Distance"}{"_geo_dist_obj"} "Geo::Distance"->new
Truth table66%2/3
A ||= B
A= $query->{"_query_cache"}{"java:com.ldodds.sparql.Distance"}{"_geo_dist_obj"}B= "Geo::Distance"->new
ABresult
1X1
011
000
67 : new Geo::Distance;
68 17 ▶ if (2 == @_) {
Branch: 1 branch
BranchTrueFalseTotal
if (2 == @_) { } 0 17 17
69 0 my ($point1, $point2) = map { $_->literal_value } splice(@_,0,2);
70 0 ($lat1, $lon1) = split(/ /, $point1);
71 0 ($lat2, $lon2) = split(/ /, $point2);
72 } else {
73 17 ($lat1, $lon1, $lat2, $lon2) = map { $_->literal_value } splice(@_,0,4);
74 }
75
76 17 my $dist = $geo->distance(
77 'kilometer',
78 $lon1,
79 $lat1,
80 $lon2,
81 $lat2,
82 );
83 # warn "ldodds:Distance => $dist\n";
84 17 return RDF::Query::Node::Literal->new("$dist", undef, 'http://www.w3.org/2001/XMLSchema#float');
85 }
86 35 );
87 }
88  
89 35 1;
90  
91 __END__
« Query/Algebra/Filter.pm ↑ Summary Query/Plan/Offset.pm »