Index: /main/trunk/model-sites-dev/heritage-nz/collect/reports-2019/perllib/plugins/CSVFieldSeparator.pm
===================================================================
--- /main/trunk/model-sites-dev/heritage-nz/collect/reports-2019/perllib/plugins/CSVFieldSeparator.pm	(revision 32812)
+++ /main/trunk/model-sites-dev/heritage-nz/collect/reports-2019/perllib/plugins/CSVFieldSeparator.pm	(revision 32812)
@@ -0,0 +1,105 @@
+##########################################################################
+#
+# CSVFieldSeparator -- helper plugin that 'auto' works out what the 
+#                      comma-separated field character is
+#
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the 
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 2019 New Zealand Digital Library Project
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+package CSVFieldSeparator;
+
+use PrintInfo;
+
+use strict;
+no strict 'refs'; # make an exception so we can use variables as filehandles
+
+BEGIN {
+    @CSVFieldSeparator::ISA = ('PrintInfo');
+}
+
+my $arguments = 
+    [ 
+      { 'name' => "separate_char",
+	'desc' => "{CSVFieldSeparator.separate_char}",
+	'type' => "string",
+	'deft' => "auto",
+	'reqd' => "no" }
+    ];
+
+my $options = { 'name' => "CSVFieldSeparator",
+		'desc' => "{CSVFieldSeparator.desc}",
+		'abstract' => "yes",
+		'inherits' => "yes",
+		'args' => $arguments };
+
+sub new {
+    my ($class) = shift (@_);
+    my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
+    push(@$pluginlist, $class);
+
+    push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
+    push(@{$hashArgOptLists->{"OptList"}},$options);
+
+    my $self = new PrintInfo($pluginlist, $inputargs, $hashArgOptLists, 1);
+  
+    return bless $self, $class;
+
+}
+
+
+sub resolve_auto
+{
+    my ($self) = shift @_;
+    my ($line,$plugin_name,$outhandle,$verbosity) = @_;
+ 
+
+    # count number of char matches for common separates such as ',' ';' '\t' and '|'
+    my $comma_count = () = ($line =~ m/,/g);
+    my $separate_char = ",";
+    my $max_count = $comma_count; 
+    
+    my $semicolon_count = () = ($line =~ m/\;/g);
+    if ($semicolon_count > $max_count) {
+	$separate_char = ";";
+	$max_count = $semicolon_count;
+    }
+
+    my $tab_count       = () = ($line =~ m/\t/g);
+    if ($tab_count > $max_count) {
+	$separate_char = "\t";
+	$max_count = $tab_count;
+    }
+
+    my $pipe_count      = () = ($line =~ m/\|/g);
+    if ($pipe_count > $max_count) {
+	$separate_char = "|";
+	$max_count = $pipe_count;
+    }
+    
+    if ($outhandle) {
+	print $outhandle "$plugin_name: Auto selecting '$separate_char' as -separate_char\n" if ($verbosity) > 1;
+    }
+
+    return $separate_char;
+}
+
+1;
Index: /main/trunk/model-sites-dev/heritage-nz/collect/reports-2019/perllib/plugins/CSVPlugin.pm
===================================================================
--- /main/trunk/model-sites-dev/heritage-nz/collect/reports-2019/perllib/plugins/CSVPlugin.pm	(revision 32811)
+++ /main/trunk/model-sites-dev/heritage-nz/collect/reports-2019/perllib/plugins/CSVPlugin.pm	(revision 32812)
@@ -29,4 +29,6 @@
 use SplitTextFile;
 use MetadataRead;
+use CSVFieldSeparator;
+
 use strict;
 no strict 'refs'; # allow filehandles to be variables and viceversa
@@ -36,5 +38,5 @@
 # CSVPlugin is a sub-class of SplitTextFile.
 sub BEGIN {
-    @CSVPlugin::ISA = ('MetadataRead', 'SplitTextFile');
+    @CSVPlugin::ISA = ('MetadataRead', 'SplitTextFile', 'CSVFieldSeparator');
 }
 
@@ -42,9 +44,4 @@
 my $arguments = 
     [ 
-      { 'name' => "separate_char",
-	'desc' => "{CSVPlugin.separate_char}",
-	'type' => "string",
-	'deft' => "auto",
-	'reqd' => "no" },
       { 'name' => "process_exp",
 	'desc' => "{BaseImporter.process_exp}",
@@ -90,4 +87,5 @@
     push(@{$hashArgOptLists->{"OptList"}}, $options);
 
+    new CSVFieldSeparator($pluginlist, $inputargs, $hashArgOptLists);
     my $self = new SplitTextFile($pluginlist, $inputargs, $hashArgOptLists);
 
@@ -120,5 +118,5 @@
     my $separate_char = $self->{'separate_char'};
     if ($separate_char =~ m/^auto$/i) {
-	$separate_char = CSVSeparateChar::resolve_auto($csv_file_field_line,$self->{'plugin_type'},$self->{'outhandle'},$self->{'verbosity'});
+	$separate_char = $self->resolve_auto($csv_file_field_line,$self->{'plugin_type'},$self->{'outhandle'},$self->{'verbosity'});
 	# Replace the 'auto' setting the resolved value (for use later on)
 	$self->{'separate_char'} = $separate_char;
Index: /main/trunk/model-sites-dev/heritage-nz/collect/reports-2019/perllib/plugins/MetadataCSVPlugin.pm
===================================================================
--- /main/trunk/model-sites-dev/heritage-nz/collect/reports-2019/perllib/plugins/MetadataCSVPlugin.pm	(revision 32811)
+++ /main/trunk/model-sites-dev/heritage-nz/collect/reports-2019/perllib/plugins/MetadataCSVPlugin.pm	(revision 32812)
@@ -30,4 +30,5 @@
 use BaseImporter;
 use MetadataRead;
+use CSVFieldSeparator;
 
 use strict;
@@ -38,11 +39,10 @@
 use util;
 
-use CSVSeparateChar; 
-
 use Encode;
+use Text::CSV;
 
 # methods with identical signatures take precedence in the order given in the ISA list.
 sub BEGIN {
-    @MetadataCSVPlugin::ISA = ('MetadataRead', 'BaseImporter');
+    @MetadataCSVPlugin::ISA = ('MetadataRead', 'BaseImporter', 'CSVFieldSeparator');
 }
 
@@ -50,9 +50,4 @@
 
 my $arguments = [
-      { 'name' => "separate_char",
-	'desc' => "{CSVPlugin.separate_char}",
-	'type' => "string",
-	'deft' => "auto",
-	'reqd' => "no" },
       { 'name' => "process_exp",
 	'desc' => "{BaseImporter.process_exp}",
@@ -80,4 +75,5 @@
     push(@{$hashArgOptLists->{"OptList"}},$options);
 
+    new CSVFieldSeparator($pluginlist, $inputargs, $hashArgOptLists);
     my $self = new BaseImporter($pluginlist, $inputargs, $hashArgOptLists);
 
@@ -154,5 +150,5 @@
 
     if ($separate_char =~ m/^auto$/i) {
-	$separate_char = CSVSeparateChar::resolve_auto($csv_file_field_line,$self->{'plugin_type'},$outhandle,$self->{'verbosity'});
+	$separate_char = $self->resolve_auto($csv_file_field_line,$self->{'plugin_type'},$outhandle,$self->{'verbosity'});
     }
 
