Geo::GDAL  2.3
Streaming a dataset

The code here does not have any warranty. It is recommended that before using any of this code, you look into it and try to understand what it does, what input it needs, etc. Do not blindly execute anything!

This example will stream a vector dataset as GML through an object, which implements write and close methods.

my $layer = Geo::OGR::DataSource::Open(<data source name here>)->GetLayer(<layer name here>);
{
package Writer;
sub write {
# note that the object itself is not available!
my ($w) = @_;
print $w;
}
sub close {
# note that the object itself is not available!
print "done\n";
}
}
my $writer = bless {}, 'Writer';
Geo::OGR::Driver('GML')->Create($writer)->CopyLayer($layer, <layer name here>);