File Coverage

blib/lib/Geo/GDAL/FFI/VSI.pm
Criterion Covered Total %
statement 17 39 43.5
branch 0 8 0.0
condition 0 16 0.0
subroutine 6 12 50.0
pod 3 6 50.0
total 26 81 32.1


line stmt bran cond sub pod time code
1             package Geo::GDAL::FFI::VSI;
2 5     5   91 use v5.10;
  5         20  
3 5     5   29 use strict;
  5         28  
  5         133  
4 5     5   31 use warnings;
  5         32  
  5         217  
5 5     5   29 use Encode qw(decode encode);
  5         12  
  5         349  
6 5     5   32 use Carp;
  5         10  
  5         329  
7 5     5   36 use FFI::Platypus::Buffer;
  5         11  
  5         3386  
8             require Exporter;
9              
10             our $VERSION = 0.0800;
11              
12             our @ISA = qw(Exporter);
13             our @EXPORT_OK = qw(Mkdir Rmdir ReadDir FOpen Unlink Rename);
14              
15             sub FOpen {
16 0     0 1   return Geo::GDAL::FFI::VSI::File->Open(@_);
17             }
18              
19             sub Unlink {
20 0     0 0   my ($path) = @_;
21 0           my $e = Geo::GDAL::FFI::VSIUnlink(encode(utf8 => $path));
22 0 0 0       confess Geo::GDAL::FFI::error_msg() // "Failed to unlink '$path'." if $e == -1;
23             }
24              
25             sub Rename {
26 0     0 0   my ($path, $new_path) = @_;
27 0           my $e = Geo::GDAL::FFI::VSIRename(encode(utf8 => $path), encode(utf8 => $new_path));
28 0 0 0       confess Geo::GDAL::FFI::error_msg() // "Failed to rename '$path' to '$new_path'." if $e == -1;
29             }
30              
31             sub Mkdir {
32 0     0 1   my ($path, $mode) = @_;
33 0   0       $mode //= hex '0x0666';
34 0           my $e = Geo::GDAL::FFI::VSIMkdir(encode(utf8 => $path), $mode);
35 0 0 0       confess Geo::GDAL::FFI::error_msg() // "Failed to mkdir '$path'." if $e == -1;
36             }
37              
38             sub Rmdir {
39 0     0 0   my ($path) = @_;
40 0           my $e = Geo::GDAL::FFI::VSIRmdir(encode(utf8 => $path));
41 0 0 0       confess Geo::GDAL::FFI::error_msg() // "Failed to rmdir '$path'." if $e == -1;
42             }
43              
44             sub ReadDir {
45 0     0 1   my ($path, $max_files) = @_;
46 0   0       $max_files //= 0;
47 0           my $csl = Geo::GDAL::FFI::VSIReadDirEx(encode(utf8 => $path), $max_files);
48 0           my @dir;
49 0           for my $i (0 .. Geo::GDAL::FFI::CSLCount($csl)-1) {
50 0           push @dir, decode utf8 => Geo::GDAL::FFI::CSLGetField($csl, $i);
51             }
52 0           Geo::GDAL::FFI::CSLDestroy($csl);
53 0           return @dir;
54             }
55              
56             1;
57              
58             =pod
59              
60             =encoding UTF-8
61              
62             =head1 NAME
63              
64             Geo::GDAL::FFI::VSI - A GDAL virtual file system
65              
66             =head1 SYNOPSIS
67              
68             use Geo::GDAL::FFI::VSI qw/FOpen Mkdir ReadDir/;
69              
70             =head1 DESCRIPTION
71              
72             =head1 METHODS
73              
74             =head2 FOpen($path, $access)
75              
76             my $file = FOpen('/vsimem/file', 'w');
77              
78             Short for Geo::GDAL::FFI::VSI::File::Open
79              
80             =head2 Mkdir($path, $mode)
81              
82             $mode is optional and by default 0x0666.
83              
84             =head2 ReadDir($path, $max_files)
85              
86             $max_files is optional and by default 0, i.e., read all names of files
87             in the dir.
88              
89             =head1 LICENSE
90              
91             This software is released under the Artistic License. See
92             L.
93              
94             =head1 AUTHOR
95              
96             Ari Jolma - Ari.Jolma at gmail.com
97              
98             =head1 SEE ALSO
99              
100             L
101              
102             L, L, L
103              
104             =cut
105              
106             __END__;