#! /usr/bin/perl -w

use strict;

use Geo::Postcodes::DK 0.20;

################################################################################
#                                                                              #
#                             multiselection_dk                                #
#                             -----------------                                #
#               Arne Sommer - perl@bbop.org - 07. September 2006               #
#                                                                              #
################################################################################

my ($status, @lines) = Geo::Postcodes::DK::verify_selectionlist(@ARGV);
  # @lines is diagnostic output if the check failed.
  # @lines is a fixed argument list if the check succeeded.
  #  e.g. ('and', 'not') -> ('and not').

if ($status == 0)
{
  print "Usage: \n",
        " * multiselection_dk [all|none]\n",
        " * multiselection_dk [" , 
        join("|", Geo::Postcodes::get_initial_selectionmodes()),
        "]? <method> <string> [[",
        join("|", Geo::Postcodes::get_selectionmodes()),
        "]? [<method> <string>]]*\n\n";

  print "Legal methods: ", join(", ", Geo::Postcodes::DK::get_methods()), "\n\n";

  print "Diagnostic output:\n";

  foreach (@lines)
  {
    print " * $_\n";
  }

  exit;
}

my @methods = Geo::Postcodes::DK::get_methods();
  # Get all the methods supported by this class.

foreach my $m (@methods)
{
  printf("%-14s", ucfirst($m)); # Print headers for each column
}
print "\n";

foreach my $P (Geo::Postcodes::DK->selection(@lines)) # Iterate over objects
{
  foreach my $m (@methods)     # Iterate over the methods for each object
  {
    printf("%-14s", $P->$m() || ""); # Print the column data, catching 'undef'
  }
  print "\n";
}
print "\n";

