From: Matt S Trout Date: Sat, 16 May 2009 15:23:32 +0000 (+0100) Subject: check postspec loading, factor out column order handling to avoid making further... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7a42977ef6480e6e686b0bdad85e8c6f602541ce;p=engit%2FIron-Munger.git check postspec loading, factor out column order handling to avoid making further silly mistakes (I got the indices wrong first time) --- diff --git a/lib/IronMunger/PlaggerLoader.pm b/lib/IronMunger/PlaggerLoader.pm index 08daf15..db50215 100644 --- a/lib/IronMunger/PlaggerLoader.pm +++ b/lib/IronMunger/PlaggerLoader.pm @@ -32,14 +32,20 @@ class IronMunger::PlaggerLoader { ]; } + method _csv_column_order () { + my $x; + return map +($_ => $x++), qw(author title url at); + } + method _expand_postspecs_from_file(IO::All::File $file) { my $csv = Text::CSV_XS->new; my $io = $file->open; my @post_specs; + my %col_order = $self->_csv_column_order; while (my $post_raw = $csv->getline($io)) { my %post_spec; - @post_spec{qw{url at}} = @{$post_raw}[1,2]; - push(@post_specs, %post_spec); + @post_spec{qw{url at}} = @{$post_raw}[@col_order{qw{url at}}]; + push(@post_specs, \%post_spec); } return \@post_specs; } diff --git a/t/plagger_loader.t b/t/plagger_loader.t index f4b3002..e3bffd4 100644 --- a/t/plagger_loader.t +++ b/t/plagger_loader.t @@ -1,7 +1,7 @@ use strict; use warnings; use Test::More qw(no_plan); - +use IO::All; BEGIN { use_ok aliased => 'IronMunger::PlaggerLoader'; @@ -31,3 +31,15 @@ is_deeply( is($post->$key, $args{$key}, "Attribute ${key} ok"); } } + +my @postspecs = map + +{ + url => 'http://jdv79.blogspot.com/2009/05/testable-v007.html', + at => $_, + }, qw(2009-05-13T02:45:00 2009-05-14T16:00:00); + +my $specs = $loader->_expand_postspecs_from_file( + io('t/csv/my_Justin_DeVuyst.csv') + ); + +is_deeply($specs, \@postspecs, 'Post specs from file ok');