| 1 | 5 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | package Geo::LibProj::cs2cs; | ||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: IPC interface to PROJ cs2cs | ||||||||||||||||||||||||||||||||||
| 7 | 5 | $Geo::LibProj::cs2cs::VERSION = '1.03'; | |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Carp qw(carp croak); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use File::Basename qw(basename); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use Scalar::Util 1.10 qw(looks_like_number); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use IPC::Run3 qw(run3); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | 5 | our $CMD = 'cs2cs'; | |||||||||||||||||||||||||||||||||
| 18 | 5 | our @PATH = (); | |||||||||||||||||||||||||||||||||
| 19 | 5 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||
| 20 | # optional modules | ||||||||||||||||||||||||||||||||||
| 21 | 5 | ▶ | eval "require Alien::proj" or eval "require Alien::Proj4"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||
| 23 | 5 | eval { unshift @PATH, File::Spec->catdir(Alien::proj->dist_dir, 'bin') }; | |||||||||||||||||||||||||||||||||
| 24 | 5 | eval { push @PATH, undef, File::Spec->catdir(Alien::Proj4->dist_dir, 'bin') }; | |||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | # default stringification formats for cs2cs stdin and stdout | ||||||||||||||||||||||||||||||||||
| 28 | 5 | our $FORMAT_IN = '%.15g'; | |||||||||||||||||||||||||||||||||
| 29 | 5 | our $FORMAT_OUT = '%.12g'; | |||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | 5 | our %PARAMS = ( | |||||||||||||||||||||||||||||||||
| 32 | -f => $FORMAT_OUT, | ||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||
| 36 | 12 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 37 | 12 | my $class = shift; | |||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | 12 | my ($source_crs, $target_crs, $user_params); | |||||||||||||||||||||||||||||||||
| 40 | 12 | ▶ | if ( ref($_[0]) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 41 | 1 | ($user_params, $source_crs, $target_crs) = @_; | |||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||
| 43 | else { | ||||||||||||||||||||||||||||||||||
| 44 | 11 | ($source_crs, $target_crs, $user_params) = @_; | |||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||
| 47 | 12 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||
| 49 | 12 | ▶ | my $params = { %PARAMS, defined $user_params ? %$user_params : () }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 50 | 12 | $self->_special_params($params); | |||||||||||||||||||||||||||||||||
| 51 | 9 | $self->{format_in} = $FORMAT_IN; | |||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||
| 53 | # assemble cs2cs call line | ||||||||||||||||||||||||||||||||||
| 54 | 9 | for my $key (keys %$params) { | |||||||||||||||||||||||||||||||||
| 55 | 12 | ▶ | delete $params->{$key} unless defined $params->{$key}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||
| 57 | 9 | ▶ | my @source_crs = split m/ /, $source_crs // 'undef'; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$source_crs // "undef"
MC/DC100%1/1
$source_crs // "undef"
$source_crs
Truth table100%2/2
A
A= $source_crs
| |||||||||||||||||||||||||||||||||||
| 58 | 9 | ▶ | my @target_crs = split m/ /, $target_crs // 'undef'; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$target_crs // "undef"
MC/DC100%1/1
$target_crs // "undef"
$target_crs
Truth table100%2/2
A
A= $target_crs
| |||||||||||||||||||||||||||||||||||
| 59 | 9 | $self->{cmd} = $self->_cmd(); | |||||||||||||||||||||||||||||||||
| 60 | 9 | $self->{call} = [$self->{cmd}, %$params, @source_crs, '+to', @target_crs, '-']; | |||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||
| 62 | 9 | $self->_ffi_init($source_crs, $target_crs, $params); | |||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | 9 | return $self; | |||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||
| 68 | 15 | ▶ | sub _special_params { | ||||||||||||||||||||||||||||||||
|
Subroutine
_special_params: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||
| 69 | 15 | my ($self, $params) = @_; | |||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | # support -d even for older cs2cs versions | ||||||||||||||||||||||||||||||||||
| 72 | 15 | ▶ | if (defined $params->{-d} && defined $params->{-f}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $params->{"-d"} and defined $params->{"-f"}
MC/DC100%2/2
defined $params->{"-d"} and defined $params->{"-f"}
defined $params->{"-d"}
defined $params->{"-f"}
Truth table100%3/3
A and B
A= defined $params->{"-d"}B= defined $params->{"-f"}
| |||||||||||||||||||||||||||||||||||
| 73 | 1 | $params->{-f} = '%.' . (0 + $params->{-d}) . 'f'; | |||||||||||||||||||||||||||||||||
| 74 | 1 | delete $params->{-d}; | |||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | 15 | ▶ | croak "-E is unsupported" if defined $params->{'-E'}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 78 | 14 | ▶ | croak "-t is unsupported" if defined $params->{'-t'}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 79 | 13 | ▶ | croak "-v is unsupported" if defined $params->{'-v'}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||
| 81 | # -w3 must be supplied as a single parameter to cs2cs | ||||||||||||||||||||||||||||||||||
| 82 | 12 | ▶ | if (defined $params->{-w}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 83 | 1 | $params->{"-w$params->{-w}"} = ''; | |||||||||||||||||||||||||||||||||
| 84 | 1 | delete $params->{-w}; | |||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||
| 86 | 12 | ▶ | if (defined $params->{-W}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 87 | 1 | $params->{"-W$params->{-W}"} = ''; | |||||||||||||||||||||||||||||||||
| 88 | 1 | delete $params->{-W}; | |||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||
| 91 | $self->{ffi} = $INC{'Geo/LibProj/FFI.pm'} | ||||||||||||||||||||||||||||||||||
| 92 | 12 | ▶ | && ( $params->{XS} || ! defined $params->{XS} ); | ||||||||||||||||||||||||||||||||
|
Condition100%6/6
$INC{'Geo/LibProj/FFI.pm'} && ($params->{'XS'} || !defined($params->{'XS'}))
$params->{"XS"} or not defined $params->{"XS"}
MC/DC100%3/3
$INC{'Geo/LibProj/FFI.pm'} && ($params->{'XS'} || !defined($params->{'XS'}))
$INC{'Geo/LibProj/FFI.pm'}
$params->{"XS"}
not defined $params->{"XS"}
Truth table100%4/4
A && B or not(C)
A= $INC{'Geo/LibProj/FFI.pm'}B= $params->{"XS"}C= not defined $params->{"XS"}
| |||||||||||||||||||||||||||||||||||
| 93 | 12 | $self->{ffi_warn} = $params->{XS}; | |||||||||||||||||||||||||||||||||
| 94 | 12 | delete $params->{XS}; | |||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||
| 98 | 16 | ▶ | sub _cmd { | ||||||||||||||||||||||||||||||||
|
Subroutine
_cmd: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 99 | # try to find the cs2cs binary | ||||||||||||||||||||||||||||||||||
| 100 | 16 | foreach my $path (@PATH) { | |||||||||||||||||||||||||||||||||
| 101 | 5 | ▶ | if (defined $path) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 102 | 3 | my $cmd = File::Spec->catfile($path, $CMD); | |||||||||||||||||||||||||||||||||
| 103 | 3 | ▶ | return $cmd if -e $cmd; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||
| 105 | else { | ||||||||||||||||||||||||||||||||||
| 106 | # when the @PATH element is undefined, try the env PATH | ||||||||||||||||||||||||||||||||||
| 107 | 2 | eval { run3 [$CMD, '-lp'], \undef, \undef, \undef }; | |||||||||||||||||||||||||||||||||
| 108 | 2 | ▶ | return $CMD if ! $@ && $? == 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $@ and $? == 0
MC/DC50%1/2
not $@ and $? == 0
not $@
$? == 0
Truth table66%2/3
not(A) and B
A= not $@B= $? == 0
| |||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||
| 112 | # no luck; let's just hope it'll be on the PATH somewhere | ||||||||||||||||||||||||||||||||||
| 113 | 14 | return $CMD; | |||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||
| 117 | 25 | ▶ | sub _ffi_init { | ||||||||||||||||||||||||||||||||
|
Subroutine
_ffi_init: called CC=15 SCAR=27.1
| |||||||||||||||||||||||||||||||||||
| 118 | 25 | my ($self, $source_crs, $target_crs, $params) = @_; | |||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||
| 120 | 25 | ▶ | carp "Geo::LibProj::FFI is not loaded; falling back to IPC mode" if $self->{ffi_warn} && ! $self->{ffi}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"ffi_warn"} and not $self->{"ffi"}
MC/DC100%2/2
$self->{"ffi_warn"} and not $self->{"ffi"}
$self->{"ffi_warn"}
not $self->{"ffi"}
Truth table100%3/3
A and not(B)
A= $self->{"ffi_warn"}B= not $self->{"ffi"}
| |||||||||||||||||||||||||||||||||||
| 121 | 25 | ▶ | return unless $self->{ffi}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||
| 123 | my @params = grep { | ||||||||||||||||||||||||||||||||||
| 124 | 14 | $_ eq '-f' | |||||||||||||||||||||||||||||||||
| 125 | ? defined $params->{$_} && $params->{$_} ne $FORMAT_OUT | ||||||||||||||||||||||||||||||||||
| 126 | 8 | ▶ | : defined $params->{$_} | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $params->{$_} and $params->{$_} ne $Geo::LibProj::cs2cs::FORMAT_OUT
MC/DC100%2/2
defined $params->{$_} and $params->{$_} ne $Geo::LibProj::cs2cs::FORMAT_OUT
defined $params->{$_}
$params->{$_} ne $Geo::LibProj::cs2cs::FORMAT_OUT
Truth table100%3/3
A and B
A= defined $params->{$_}B= $params->{$_} ne $Geo::LibProj::cs2cs::FORMAT_OUT
| |||||||||||||||||||||||||||||||||||
| 127 | } keys %$params; | ||||||||||||||||||||||||||||||||||
| 128 | 14 | ▶ | carp "cs2cs control parameters are unsupported in XS mode; falling back to IPC mode" if $self->{ffi_warn} && @params; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"ffi_warn"} and @params
MC/DC100%2/2
$self->{"ffi_warn"} and @params
$self->{"ffi_warn"}
@params
Truth table100%3/3
A and B
A= $self->{"ffi_warn"}B= @params
| |||||||||||||||||||||||||||||||||||
| 129 | 14 | ▶ | return $self->{ffi} = 0 if @params; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||
| 131 | 10 | my $ctx = $self->{ffi_ctx} = Geo::LibProj::FFI::proj_context_create(); | |||||||||||||||||||||||||||||||||
| 132 | 10 | ▶ | carp "proj_context_create() failed; falling back to IPC mode" if $self->{ffi_warn} && ! $ctx; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"ffi_warn"} and not $ctx
MC/DC100%2/2
$self->{"ffi_warn"} and not $ctx
$self->{"ffi_warn"}
not $ctx
Truth table100%3/3
A and not(B)
A= $self->{"ffi_warn"}B= not $ctx
| |||||||||||||||||||||||||||||||||||
| 133 | 10 | ▶ | return $self->{ffi} = 0 if ! $ctx; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||
| 135 | 8 | Geo::LibProj::FFI::proj_context_use_proj4_init_rules($ctx, 1); | |||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||
| 137 | 8 | my $pj = $self->{ffi_pj} = Geo::LibProj::FFI::proj_create_crs_to_crs( | |||||||||||||||||||||||||||||||||
| 138 | $ctx, $source_crs, $target_crs, undef ); | ||||||||||||||||||||||||||||||||||
| 139 | 8 | ▶ | carp "proj_create_crs_to_crs() failed; falling back to IPC mode" if $self->{ffi_warn} && ! $pj; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"ffi_warn"} and not $pj
MC/DC100%2/2
$self->{"ffi_warn"} and not $pj
$self->{"ffi_warn"}
not $pj
Truth table100%3/3
A and not(B)
A= $self->{"ffi_warn"}B= not $pj
| |||||||||||||||||||||||||||||||||||
| 140 | 8 | ▶ | return $self->{ffi} = 0 if ! $pj; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||
| 144 | 15 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||
| 145 | 15 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||
| 147 | 15 | ▶ | Geo::LibProj::FFI::proj_destroy($self->{ffi_pj}) if $self->{ffi_pj}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 148 | 15 | ▶ | Geo::LibProj::FFI::proj_context_destroy($self->{ffi_ctx}) if $self->{ffi_ctx}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 149 | 15 | $self->{ffi_pj} = $self->{ffi_ctx} = 0; | |||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||
| 153 | 10 | ▶ | sub _ipc_error_check { | ||||||||||||||||||||||||||||||||
|
Subroutine
_ipc_error_check: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||
| 154 | 10 | my ($self, $eval_err, $os_err, $code, $stderr) = @_; | |||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||
| 156 | 10 | my $cmd = $CMD; | |||||||||||||||||||||||||||||||||
| 157 | 10 | ▶ | if (ref $self) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 158 | 7 | $self->{stderr} = $stderr; | |||||||||||||||||||||||||||||||||
| 159 | 7 | $self->{status} = $code >> 8; | |||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||
| 162 | 10 | ▶ | $stderr =~ s/^(.*\S)\s*\z/: $1/s if length $stderr; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 163 | 10 | ▶ | croak "`$cmd` failed to execute: $os_err" if $code == -1; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 164 | 9 | ▶ | croak "`$cmd` died with signal " . ($code & 0x7f) . $stderr if $code & 0x7f; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 165 | 9 | ▶ | croak "`$cmd` exited with status " . ($code >> 8) . $stderr if $code; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 166 | 8 | ▶ | croak $eval_err =~ s/\s+\z//r if $eval_err; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||
| 170 | 27 | ▶ | sub _format { | ||||||||||||||||||||||||||||||||
|
Subroutine
_format: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 171 | 27 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||
| 173 | 27 | ▶ | return sprintf $self->{format_in}, $value if looks_like_number $value; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 174 | 2 | return $value; | |||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||
| 178 | 10 | ▶ | sub transform { | ||||||||||||||||||||||||||||||||
|
Subroutine
transform: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 179 | 10 | my ($self, @source_points) = @_; | |||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||
| 181 | 10 | ▶ | return $self->_ffi_transform(@source_points) if $self->{ffi}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||
| 183 | 7 | my @in = (); | |||||||||||||||||||||||||||||||||
| 184 | 7 | foreach my $i (0 .. $#source_points) { | |||||||||||||||||||||||||||||||||
| 185 | 9 | my $p = $source_points[$i]; | |||||||||||||||||||||||||||||||||
| 186 | 9 | ▶ | push @in, $self->_format($p->[0] || 0) . " " | ||||||||||||||||||||||||||||||||
|
Condition100%6/6
$p->[0] || 0
$p->[1] || 0
$p->[2] || 0
MC/DC100%1/1
$p->[0] || 0
$p->[0]
MC/DC100%1/1
$p->[1] || 0
$p->[1]
MC/DC100%1/1
$p->[2] || 0
$p->[2]
Truth table100%2/2
A
A= $p->[0]
Truth table100%2/2
A
A= $p->[1]
Truth table100%2/2
A
A= $p->[2]
| |||||||||||||||||||||||||||||||||||
| 187 | . $self->_format($p->[1] || 0) . " " | ||||||||||||||||||||||||||||||||||
| 188 | . $self->_format($p->[2] || 0) . " $i"; | ||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||
| 190 | 7 | my $in = join "\n", @in; | |||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||
| 192 | 7 | my @out = (); | |||||||||||||||||||||||||||||||||
| 193 | 7 | my $err = ''; | |||||||||||||||||||||||||||||||||
| 194 | 7 | eval { | |||||||||||||||||||||||||||||||||
| 195 | 7 | local $/ = "\n"; | |||||||||||||||||||||||||||||||||
| 196 | 7 | run3 $self->{call}, \$in, \@out, \$err; | |||||||||||||||||||||||||||||||||
| 197 | }; | ||||||||||||||||||||||||||||||||||
| 198 | 7 | $self->_ipc_error_check($@, $!, $?, $err); | |||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||
| 200 | 7 | my @target_points = (); | |||||||||||||||||||||||||||||||||
| 201 | 7 | foreach my $line (@out) { | |||||||||||||||||||||||||||||||||
| 202 | 8 | ▶ | next unless $line =~ m{\s(\d+)\s*$}xa; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 203 | 7 | my $aux = $source_points[$1]->[3]; | |||||||||||||||||||||||||||||||||
| 204 | 7 | ▶ | next unless $line =~ m{^\s* (\S+) \s+ (\S+) \s+ (\S+) \s}xa; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 205 | 6 | ▶ | my @p = defined $aux ? ($1, $2, $3, $aux) : ($1, $2, $3); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||
| 207 | 6 | foreach my $j (0..2) { | |||||||||||||||||||||||||||||||||
| 208 | 18 | ▶ | $p[$j] = 0 + $p[$j] if looks_like_number $p[$j]; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||
| 211 | 6 | push @target_points, \@p; | |||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||
| 214 | 7 | ▶ | if ( (my $s = @source_points) != (my $t = @target_points) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 215 | 3 | croak "Source/target point count doesn't match ($s/$t): Assertion failed"; | |||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||
| 218 | 4 | ▶ | return @target_points if wantarray; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 219 | 3 | ▶ | return $target_points[0] if @target_points < 2; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 220 | 1 | croak "transform() with list argument prohibited in scalar context"; | |||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||
| 224 | 3 | ▶ | sub _ffi_transform { | ||||||||||||||||||||||||||||||||
|
Subroutine
_ffi_transform: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||
| 225 | 3 | my ($self, @source_points) = @_; | |||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||
| 227 | my @target_points = map { | ||||||||||||||||||||||||||||||||||
| 228 | 3 | my $p = Geo::LibProj::FFI::_trans( $self->{ffi_pj}, 1, [$_->[0], $_->[1], $_->[2], 'Inf'] ); | |||||||||||||||||||||||||||||||||
| 229 | 7 | $p->[3] = $_->[3]; | |||||||||||||||||||||||||||||||||
| 230 | 7 | ▶ | delete $p->[3] unless defined $p->[3]; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 231 | 7 | $p; | |||||||||||||||||||||||||||||||||
| 232 | } @source_points; | ||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||
| 234 | 3 | ▶ | return @target_points if wantarray; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 235 | 2 | ▶ | return $target_points[0] if @target_points < 2; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 236 | 1 | croak "transform() with list argument prohibited in scalar context"; | |||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||
| 240 | 4 | ▶ | sub version { | ||||||||||||||||||||||||||||||||
|
Subroutine
version: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 241 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||
| 243 | 4 | ▶ | my $ffi = ref $self ? $self->{ffi} : $INC{'Geo/LibProj/FFI.pm'}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 244 | 4 | ▶ | return Geo::LibProj::FFI::proj_info()->version if $ffi; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||
| 246 | 3 | my $out = ''; | |||||||||||||||||||||||||||||||||
| 247 | 3 | eval { | |||||||||||||||||||||||||||||||||
| 248 | 3 | run3 [ $self->_cmd ], \undef, \$out, \$out; | |||||||||||||||||||||||||||||||||
| 249 | }; | ||||||||||||||||||||||||||||||||||
| 250 | 3 | $self->_ipc_error_check($@, $!, $?, ''); | |||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||
| 252 | 1 | ▶ | return $1 if $out =~ m/\b(\d+\.\d+(?:\.\d\w*)?)\b/; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 253 | 1 | return $out; | |||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||
| 257 | 1 | ▶ | sub xs { shift->{ffi} } | ||||||||||||||||||||||||||||||||
|
Subroutine
xs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||
| 260 | 5 | 1; | |||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||
| 262 | __END__ | ||||||||||||||||||||||||||||||||||