FFI/Driver.pm

filter: Statementstmt 32.0% 16 / 50 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 71.4% 5 / 7 Podpod 100% 2 / 2 totaltotal 22.7% 23 / 101 CC 16 SCAR 52.9
CC
16
Cov
20%
Create
272.0
GetName
2.0
BEGIN
1.0
CRAP 198.1
« FFI/Feature.pm ↑ Summary FFI/Geometry.pm »
1 package Geo::GDAL::FFI::Driver;
2 13 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use base 'Geo::GDAL::FFI::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 13 our $VERSION = '0.15';
9
10 sub GetName {
11 0 ▶ my $self = shift;
Subroutine GetName: not called CC=1 SCAR=6.9
Pod documented
12 0 return $self->GetDescription;
13 }
14
15 sub Create {
16 0 ▶ my ($self, $name, $args, $h) = @_;
Subroutine Create: not called CC=16 SCAR=56.1
Pod documented
17 0 ▶ $name //= '';
Condition0%0/2
$name //= ""
l!l
00
MC/DC0%0/1
$name //= ""
$name
Truth table0%0/2
A
A= $name
Aresult
11
00
18 0 ▶ $args //= {};
Condition0%0/2
$args //= {}
l!l
00
MC/DC0%0/1
$args //= {}
$args
Truth table0%0/2
A
A= $args
Aresult
11
00
19 0 ▶ $args = {Width => $args, Height => $h} unless ref $args;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args 0 0 0
20 0 my $o = 0;
21 0 for my $key (keys %{$args->{Options}}) {
22 0 $o = Geo::GDAL::FFI::CSLAddString($o, "$key=$args->{Options}{$key}");
23 }
24 0 my $ds;
25 0 ▶ if ($args->{Source}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args->{'Source'}) { } 0 0 0
elsif (not $args->{'Width'}) { } 0 0 0
26 0 my $src = ${$args->{Source}};
27 0 ▶ my $s = $args->{Strict} // 0;
Condition0%0/2
$args->{"Strict"} // 0
l!l
00
MC/DC0%0/1
$args->{"Strict"} // 0
$args->{"Strict"}
Truth table0%0/2
A
A= $args->{"Strict"}
Aresult
11
00
28 0 my $ffi = FFI::Platypus->new;
29 0 my $p = $ffi->closure($args->{Progress});
30 0 $ds = Geo::GDAL::FFI::GDALCreateCopy($$self, $name, $src, $s, $o, $p, $args->{ProgressData});
31 } elsif (not $args->{Width}) {
32 0 $ds = Geo::GDAL::FFI::GDALCreate($$self, $name, 0, 0, 0, 0, $o);
33 } else {
34 0 my $w = $args->{Width};
35 0 ▶ $h //= $args->{Height} // $w;
Condition0%0/6
$h //= $args->{"Height"} // $w
l!l&&r!l&&!r
000
$args->{"Height"} // $w
l!l&&r!l&&!r
000
MC/DC0%0/3
$h //= $args->{"Height"} // $w
$h $args->{"Height"} $w
Truth table0%0/4
A //= B // C
A= $hB= $args->{"Height"}C= $w
ABCresult
1XX1
01X1
0011
0000
36 0 ▶ my $b = $args->{Bands} // 1;
Condition0%0/2
$args->{"Bands"} // 1
l!l
00
MC/DC0%0/1
$args->{"Bands"} // 1
$args->{"Bands"}
Truth table0%0/2
A
A= $args->{"Bands"}
Aresult
11
00
37 0 ▶ my $dt = $args->{DataType} // 'Byte';
Condition0%0/2
$args->{"DataType"} // "Byte"
l!l
00
MC/DC0%0/1
$args->{"DataType"} // "Byte"
$args->{"DataType"}
Truth table0%0/2
A
A= $args->{"DataType"}
Aresult
11
00
38 0 my $tmp = $Geo::GDAL::FFI::data_types{$dt};
39 0 ▶ unless (defined $tmp) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tmp) 0 0 0
40 0 confess "Unknown constant: $dt.";
41 0 Geo::GDAL::FFI::CSLDestroy($o);
42 }
43 0 $ds = Geo::GDAL::FFI::GDALCreate($$self, $name, $w, $h, $b, $tmp, $o);
44 }
45 0 Geo::GDAL::FFI::CSLDestroy($o);
46 0 my $msg = Geo::GDAL::FFI::error_msg();
47 0 ▶ if (!$ds || $msg) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ds or $msg) 0 0 0
Condition0%0/3
not $ds or $msg
l!l&&r!l&&!r
000
MC/DC0%0/2
not $ds or $msg
not $ds $msg
Truth table0%0/3
not(A) or B
A= not $dsB= $msg
ABresult
1X1
011
000
48 0 ▶ $msg //= "Driver " . $self->Name . " failed to create dataset '$name'.";
Condition0%0/2
$msg //= 'Driver ' . $self->Name . " failed to create dataset '${name}'."
l!l
00
MC/DC0%0/1
$msg //= 'Driver ' . $self->Name . " failed to create dataset '${name}'."
$msg
Truth table0%0/2
A
A= $msg
Aresult
11
00
49 0 confess $msg;
50 }
51 0 return bless \$ds, 'Geo::GDAL::FFI::Dataset';
52 }
53
54 13 1;
55
56 =pod
57
58 =encoding UTF-8
59
60 =head1 NAME
61
62 Geo::GDAL::FFI::Driver - A GDAL data access driver
63
64 =head1 SYNOPSIS
65
66 =head1 DESCRIPTION
67
68 A format driver. Use the Driver method of a Geo::GDAL::FFI object to
69 obtain one.
70
71 =head1 METHODS
72
73 =head2 GetName
74
75 my $name = $driver->GetName;
76
77 Returns the name of the driver.
78
79 =head2 Create
80
81 my $name = $driver->Create($name, {Width => 100, ...});
82
83 Create a dataset. $name is the name for the dataset to create. Named
84 arguments are the following.
85
86 =over 4
87
88 =item C<Width>
89
90 Optional, but required to create a raster dataset.
91
92 =item C<Height>
93
94 Optional, default is the same as width.
95
96 =item C<Bands>
97
98 Optional, the number of raster bands in the dataset, default is one.
99
100 =item C<DataType>
101
102 Optional, the data type (a string) for the raster cells, default is
103 'Byte'.
104
105 =item C<Source>
106
107 Optional, the dataset to copy.
108
109 =item C<Progress>
110
111 Optional, used only in dataset copy, a reference to a subroutine. The
112 subroutine is called with three arguments C<($fraction, $msg, $data)>,
113 where C<$fraction> is a number, C<$msg> is a string, and C<$data> is a
114 pointer that is given as the progress data argument.
115
116 =item C<ProgressData>
117
118 Optional, used only in dataset copy, a reference.
119
120 =item C<Strict>
121
122 Optional, used only in dataset copy, default is false (0).
123
124 =item C<Options>
125
126 Optional, driver specific creation options, default is reference to an
127 empty hash.
128
129 =back
130
131 my $name = $driver->Create($name, $width);
132
133 A simple syntax for calling Create to create a raster dataset.
134
135 =head1 LICENSE
136
137 This software is released under the Artistic License. See
138 L<perlartistic>.
139
140 =head1 AUTHOR
141
142 Ari Jolma - Ari.Jolma at gmail.com
143
144 =head1 SEE ALSO
145
146 L<Geo::GDAL::FFI>
147
148 L<Alien::gdal>, L<FFI::Platypus>, L<http://www.gdal.org>
149
150 =cut
151
152 __END__;
« FFI/Feature.pm ↑ Summary FFI/Geometry.pm »