| 1 | package Geo::GDAL::FFI::VSI::File; | ||||||||||||||||||||
| 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 Encode qw(decode encode); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 13 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 13 | ▶ | use FFI::Platypus::Buffer; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 13 | our $VERSION = '0.15'; | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | sub Open { | ||||||||||||||||||||
| 12 | 0 | ▶ | my ($class, $path, $access) = @_; | ||||||||||||||||||
|
Subroutine
Open: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 13 | 0 | ▶ | $access //= 'r'; | ||||||||||||||||||
|
Condition0%0/2
$access //= "r"
MC/DC0%0/1
$access //= "r"
$access
Truth table0%0/2
A
A= $access
| |||||||||||||||||||||
| 14 | 0 | my $self = {}; | |||||||||||||||||||
| 15 | 0 | $self->{handle} = Geo::GDAL::FFI::VSIFOpenExL(encode(utf8 => $path), $access, 1); | |||||||||||||||||||
| 16 | 0 | ▶ | unless ($self->{handle}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 17 | 0 | ▶ | confess Geo::GDAL::FFI::error_msg() // "Failed to open '$path' with access '$access'."; | ||||||||||||||||||
|
Condition0%0/2
Geo::GDAL::FFI::error_msg() // "Failed to open '${path}' with access '${access}'."
MC/DC0%0/1
Geo::GDAL::FFI::error_msg() // "Failed to open '${path}' with access '${access}'."
Geo::GDAL::FFI::error_msg()
Truth table0%0/2
A
A= Geo::GDAL::FFI::error_msg()
| |||||||||||||||||||||
| 18 | } | ||||||||||||||||||||
| 19 | 0 | return bless $self, $class; | |||||||||||||||||||
| 20 | } | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | sub DESTROY { | ||||||||||||||||||||
| 23 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 24 | 0 | $self->Close; | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | sub Close { | ||||||||||||||||||||
| 28 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
Close: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 29 | 0 | ▶ | return unless $self->{handle}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 30 | 0 | my $e = Geo::GDAL::FFI::VSIFCloseL($self->{handle}); | |||||||||||||||||||
| 31 | 0 | ▶ | confess Geo::GDAL::FFI::error_msg() // "Failed to close a VSIFILE." if $e == -1; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
Geo::GDAL::FFI::error_msg() // "Failed to close a VSIFILE."
MC/DC0%0/1
Geo::GDAL::FFI::error_msg() // "Failed to close a VSIFILE."
Geo::GDAL::FFI::error_msg()
Truth table0%0/2
A
A= Geo::GDAL::FFI::error_msg()
| |||||||||||||||||||||
| 32 | 0 | delete $self->{handle}; | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | sub Read { | ||||||||||||||||||||
| 36 | 0 | ▶ | my ($self, $len) = @_; | ||||||||||||||||||
|
Subroutine
Read: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 37 | 0 | ▶ | $len //= 1; | ||||||||||||||||||
|
Condition0%0/2
$len //= 1
MC/DC0%0/1
$len //= 1
$len
Truth table0%0/2
A
A= $len
| |||||||||||||||||||||
| 38 | 0 | my $buf = ' ' x $len; | |||||||||||||||||||
| 39 | 0 | my ($pointer, $size) = scalar_to_buffer $buf; | |||||||||||||||||||
| 40 | 0 | my $n = Geo::GDAL::FFI::VSIFReadL($pointer, 1, $len, $self->{handle}); | |||||||||||||||||||
| 41 | 0 | return substr $buf, 0, $n; | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | sub Write { | ||||||||||||||||||||
| 45 | 0 | ▶ | my ($self, $buf) = @_; | ||||||||||||||||||
|
Subroutine
Write: not called CC=1 SCAR=2.6
Pod
documented
| |||||||||||||||||||||
| 46 | 13 | ▶ | my $len = do {use bytes; length($buf)}; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.6
| |||||||||||||||||||||
| 47 | 0 | my $ffi = FFI::Platypus->new(); | |||||||||||||||||||
| 48 | 0 | my $address = $ffi->cast('string' => 'opaque', $buf); | |||||||||||||||||||
| 49 | 0 | return Geo::GDAL::FFI::VSIFWriteL($address, 1, $len, $self->{handle}); | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | sub Ingest { | ||||||||||||||||||||
| 53 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
Ingest: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 54 | 0 | my $s; | |||||||||||||||||||
| 55 | 0 | my $e = Geo::GDAL::FFI::VSIIngestFile($self->{handle}, '', \$s, 0, -1); | |||||||||||||||||||
| 56 | 0 | return $s; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 13 | 1; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | =pod | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | =encoding UTF-8 | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | =head1 NAME | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | Geo::GDAL::FFI::VSI::File - A GDAL virtual file | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | =head1 SYNOPSIS | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | =head1 DESCRIPTION | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | =head1 METHODS | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | =head2 Open | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | my $vsifile = Geo::GDAL::FFI::VSI::File->Open($name, $access); | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | Open a virtual file. $name is the name of the file to open. $access is | ||||||||||||||||||||
| 80 | 'r', 'r+', 'a', or 'w'. 'r' is the default. | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | Returns a Geo::GDAL::FFI::VSI::File object. | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | =head2 Close | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | Closes the file handle. Is done automatically when the object is | ||||||||||||||||||||
| 87 | destroyed. | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | =head2 Read($len) | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | Read $len bytes from the file. Returns the bytes in a Perl | ||||||||||||||||||||
| 92 | string. $len is optional and by default 1. | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | =head2 Write($buf) | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | Write the Perl string $buf into the file. Returns the number of | ||||||||||||||||||||
| 97 | successfully written bytes. | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | =head1 LICENSE | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | This software is released under the Artistic License. See | ||||||||||||||||||||
| 102 | L<perlartistic>. | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | =head1 AUTHOR | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | Ari Jolma - Ari.Jolma at gmail.com | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | =head1 SEE ALSO | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | L<Geo::GDAL::FFI> | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | L<Alien::gdal>, L<FFI::Platypus>, L<http://www.gdal.org> | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | =cut | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | __END__; | ||||||||||||||||||||