From 3e873262659821cba83569b8b495348255d3dee2 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Thu, 21 Sep 2017 15:52:01 +0100 Subject: [PATCH] Added otucode listings for codepoint_open command --- lib/Pear/LocalLoop/Command/codepoint_open.pm | 25 ++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/Pear/LocalLoop/Command/codepoint_open.pm b/lib/Pear/LocalLoop/Command/codepoint_open.pm index 3c865e9..6a54e09 100644 --- a/lib/Pear/LocalLoop/Command/codepoint_open.pm +++ b/lib/Pear/LocalLoop/Command/codepoint_open.pm @@ -12,27 +12,37 @@ has usage => sub { shift->extract_usage }; sub run { my ( $self, @args ) = @_; + getopt \@args, + 'o|outcodes=s' => \my @outcodes; + 'q|quiet' => \my $quiet_mode; + my $cpo_dir = $self->app->home->child('etc')->child('code-point-open'); my $zip_file = $cpo_dir->child('codepo_gb.zip')->realpath->to_string; my $output_dir = $cpo_dir->child('codepo_gb')->realpath->to_string; unless ( -d $output_dir ) { - print "Unzipping code-point-open data\n"; + print "Unzipping code-point-open data\n" unless $quiet_mode; system( 'unzip', '-q', $zip_file, '-d', $output_dir ); } my $cpo = Geo::UK::Postcode::CodePointOpen->new( path => $output_dir ); use Devel::Dwarn; -my $i = 0; +Dwarn \@outcodes; + + print 'Importing data for ' . $#outcodes ? join( ' ', @outcodes ) : 'all' . 'outcodes\n' + unless $quiet_mode; + my $i = 0; my $iter = $cpo->read_iterator( + outcodes => \@outcodes, include_lat_long => 1, split_postcode => 1, ); -while ( my $pc = $iter->() ) { - Dwarn $pc; - last if $i++ > 10; -} + while ( my $pc = $iter->() ) { + $i++; + } + + Dwarn $i; } =head1 SYNOPSIS @@ -41,7 +51,8 @@ while ( my $pc = $iter->() ) { Options: - none, for now... + -o|--outcodes : limit to specified outcodes (can be defined + multiple times) =cut