read DBF files using XBase module
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 16 Dec 2012 21:58:45 +0000 (22:58 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 16 Dec 2012 21:58:45 +0000 (22:58 +0100)
bin/debian-install.sh
lib/MojoFacets/Import/DBF.pm [new file with mode: 0644]
t/MojoFacets-Import-DBF.t [new file with mode: 0755]

index 6aef031..394a377 100755 (executable)
@@ -1,3 +1,3 @@
 #!/bin/sh -x
 
-sudo apt-get install libhtml-tableextract-perl libjson-perl libmodule-install-perl libstatistics-descriptive-perl libmodule-install-perl libtext-unaccent-perl libmojolicious-perl libtext-csv-perl
+sudo apt-get install libhtml-tableextract-perl libjson-perl libmodule-install-perl libstatistics-descriptive-perl libmodule-install-perl libtext-unaccent-perl libmojolicious-perl libtext-csv-perl libdbd-xbase-perl
diff --git a/lib/MojoFacets/Import/DBF.pm b/lib/MojoFacets/Import/DBF.pm
new file mode 100644 (file)
index 0000000..aa426c0
--- /dev/null
@@ -0,0 +1,40 @@
+package MojoFacets::Import::DBF;
+
+use warnings;
+use strict;
+
+use base 'Mojo::Base';
+
+use XBase;
+
+use Data::Dump qw(dump);
+
+__PACKAGE__->attr('full_path');
+
+sub ext { '.dbf' };
+
+sub data {
+       my $self = shift;
+
+
+       my $table = new XBase $self->full_path or die XBase->errstr;
+
+       my $data = {
+               header => [ $table->field_names ],
+               types  => [ $table->field_types ],
+               lenghts=> [ $table->field_lengths ],
+               decimals=> [ $table->field_decimals ],
+               items => [],
+       };
+
+       for (0 .. $table->last_record) {
+               my $item = $table->get_record_as_hash($_);
+               warn "$_ ",dump($item);
+               push @{ $data->{items} }, $item;
+       }
+
+       return $data;
+
+}
+
+1
diff --git a/t/MojoFacets-Import-DBF.t b/t/MojoFacets-Import-DBF.t
new file mode 100755 (executable)
index 0000000..92dad0d
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 3;
+use Data::Dump qw(dump);
+
+use lib 'lib';
+
+use_ok('MojoFacets::Import::DBF');
+
+my $path = $ARGV[0] || (glob 'data/*/*/*.DBF')[0];
+diag "using $path";
+
+ok( my $o = MojoFacets::Import::DBF->new( full_path => $path ), 'new' );
+
+ok( my $data = $o->data, 'data' );
+diag dump($data);