From e05ff8ffa5f31e30e8327198e6dc8298fd7bd9f9 Mon Sep 17 00:00:00 2001 From: Evan Carroll Date: Sun, 12 Oct 2008 13:51:16 -0500 Subject: [PATCH] release of 0.09 --- META.yml | 23 ----------------------- lib/DataExtract/FixedWidth.pm | 8 ++++++-- t/13-RightAlignFirstCol.t | 27 +++++++++++++++++++++++++++ t/data/RightAlign1Col.txt | 23 +++++++++++++++++++++++ 4 files changed, 56 insertions(+), 25 deletions(-) delete mode 100644 META.yml create mode 100644 t/13-RightAlignFirstCol.t create mode 100644 t/data/RightAlign1Col.txt diff --git a/META.yml b/META.yml deleted file mode 100644 index fb15e7b..0000000 --- a/META.yml +++ /dev/null @@ -1,23 +0,0 @@ ---- -abstract: 'The one stop shop for parsing static column width text tables!' -author: - - 'Evan ' -build_requires: - Test::More: 0 -distribution_type: module -generated_by: 'Module::Install version 0.77' -license: perl -meta-spec: - url: http://module-build.sourceforge.net/META-spec-v1.4.html - version: 1.4 -name: DataExtract-FixedWidth -no_index: - directory: - - inc - - t -requires: - Moose: 0.58 - perl: 5.01 -resources: - license: http://dev.perl.org/licenses/ -version: 0.08 diff --git a/lib/DataExtract/FixedWidth.pm b/lib/DataExtract/FixedWidth.pm index 5bb3b04..9e4b7dc 100644 --- a/lib/DataExtract/FixedWidth.pm +++ b/lib/DataExtract/FixedWidth.pm @@ -2,7 +2,7 @@ package DataExtract::FixedWidth; use Moose; use Carp; -our $VERSION = '0.08'; +our $VERSION = '0.09'; sub BUILD { my $self = shift; @@ -110,8 +110,12 @@ sub _heuristic_trigger { ## The (?=\S) fixes a bug that creates null columns in the event any ## one column has trailing whitespace (because you'll have '\S\s ' ## this was a bug revealed in the dataset NullFirstRow.txt + # + ## the ^\s+ makes it so that right alligned tables + ## spaces on the left of the first non-whitespace character in + ## the first col work push @unpack, length($1) - while $mask =~ m/(\S+\s+(?=\S))/g + while $mask =~ m/((?:^\s+)?\S+\s+(?=\S))/g ; $self->unpack_string( $self->_helper_unpack( \@unpack ) ); diff --git a/t/13-RightAlignFirstCol.t b/t/13-RightAlignFirstCol.t new file mode 100644 index 0000000..743b834 --- /dev/null +++ b/t/13-RightAlignFirstCol.t @@ -0,0 +1,27 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use feature ':5.10'; + +use DataExtract::FixedWidth; +use IO::File; + +use Test::More tests => 1; + +use File::Spec; +my $file = File::Spec->catfile( 't', 'data', 'RightAlign1Col.txt' ); +my $fh = IO::File->new( $file ); +my @lines = grep /\w/, $fh->getlines; + +my $defw = DataExtract::FixedWidth->new({ + heuristic => \@lines +}); + +# 'a8a5a7a7A*' In pre v0.9 releases. +#say $defw->unpack_string; + +is ( + $defw->unpack_string + , 'a11a5a7a7A*' + , 'Spaces on left pass - right align ready' +); diff --git a/t/data/RightAlign1Col.txt b/t/data/RightAlign1Col.txt new file mode 100644 index 0000000..b030b3d --- /dev/null +++ b/t/data/RightAlign1Col.txt @@ -0,0 +1,23 @@ + program vers proto port service + 100000 4 udp 111 portmapper + 100000 3 udp 111 portmapper + 100000 2 udp 111 portmapper + 100000 4 tcp 111 portmapper + 100000 3 tcp 111 portmapper + 100000 2 tcp 111 portmapper + 100021 1 udp 32775 nlockmgr + 100021 2 udp 32775 nlockmgr + 100021 3 udp 32775 nlockmgr + 100021 4 udp 32775 nlockmgr + 100021 1 tcp 32769 nlockmgr + 100021 2 tcp 32769 nlockmgr + 100021 3 tcp 32769 nlockmgr + 100021 4 tcp 32769 nlockmgr + 100024 1 tcp 32770 status + 100024 1 udp 32793 status + 100133 1 tcp 32770 + 100133 1 udp 32793 + 200001 1 tcp 32770 + 200001 1 udp 32793 + 200001 2 tcp 32770 + 200001 2 udp 32793 -- 2.11.4.GIT