NAME
Business::DPD::SK::GeoRDB - download and read the DPD Slovakia GeoRDB
SYNOPSIS
use Business::DPD::SK::GeoRDB;
my $geordb = Business::DPD::SK::GeoRDB->new;
# fetch the newest GeoRDB_<version>_B016.zip if it is newer than ours
if (my $zip = $geordb->update) {
say "downloaded $zip";
}
say $geordb->version->{VERSIONNUMBER};
my $summary = $geordb->each_row('POSTALCODE', sub {
my ($row) = @_;
say join(' ', @{$row}{qw(COUNTRYCODE BEGINPOSTCODE ENDPOSTCODE)});
});
die 'truncated file' unless $summary->{complete};
DESCRIPTION
DPD Slovakia publishes its routing database (GeoRDB) as zip files named GeoRDB_YYMMDDVV_B016.zip on an SFTP server. Each zip contains one semicolon-separated text file. #DEF:GEOROUTING:TABLE;COLUMN;... lines name the columns of each table; data lines start with the table name.
This module keeps the newest zip in "data_dir" and streams rows of a single table from it without extracting the file.
Versions whose last two digits are 01 are DPD test versions and are ignored.
ATTRIBUTES
config_file
INI file with a [download] section holding hostname, username and password. Defaults to dpd-sk/geordb.ini below "sysconfdir" in Business::DPD::SK::SPc.
data_dir
Directory where the zip is stored. Defaults to dpd-sk below "sharedstatedir" in Business::DPD::SK::SPc.
file
The zip read by "each_row" and "version". Defaults to "local_file". Pass a path to read another zip.
sftp
A Net::SFTP::Foreign connection built from "config_file" on first use. Password authentication needs IO::Pty, and the server's host key must already be in the user's known_hosts.
METHODS
update
Downloads the newest production zip from the server if its version is higher than "local_version". The download is written to a .part file, read completely to verify it, renamed, and older zips are deleted. Returns the new path, or undef when nothing newer exists. Dies on SFTP or zip errors and then leaves the previous zip in place.
each_row
my $summary = $geordb->each_row($table, sub { my ($row) = @_; ... });
Calls the callback with a hash reference per row of $table, keyed by the column names of its #DEF line. Returns {rows => $count, complete => 0|1}; complete is true when the #END line was seen. Dies on decompression or CRC errors.
version
Returns the VERSION row: VERSIONNUMBER, VALIDFROM, VALIDTO and BARCODEID.
remote_latest
Name of the newest production zip on the server.
local_file
local_version
Path and version of the newest zip in "data_dir", or undef.
version_of
Business::DPD::SK::GeoRDB->version_of('GeoRDB_26110211_B016.zip'); # 26110211
Version number of a zip file name, or undef for other names and test versions.