Move get_file_from_glob() as a function to Krill.pm and test it
Change-Id: I16aea108f7df3190074c5f1113856c12c6480150
diff --git a/lib/KorAP/XML/Krill.pm b/lib/KorAP/XML/Krill.pm
index ee371aa..d548d37 100644
--- a/lib/KorAP/XML/Krill.pm
+++ b/lib/KorAP/XML/Krill.pm
@@ -13,6 +13,10 @@
use Cache::FastMmap;
use Mojo::DOM;
use File::Spec::Functions qw/catdir catfile catpath splitdir splitpath rel2abs/;
+use Exporter 'import';
+
+our @EXPORT_OK = qw(get_file_name_from_glob);
+
our $VERSION = '0.41';
@@ -292,6 +296,20 @@
return $self->{tokenizer}->to_json;
};
+# Functions
+
+sub get_file_name_from_glob ($) {
+ my $glob = shift;
+ $glob =~ s![\\\/},]!-!g; # Transform paths
+ $glob =~ s/[\*\?]//g; # Remove arbitrary fills
+ $glob =~ s/[\{\}\[\]]/-/g; # Remove class and multiple brackets
+ $glob =~ s/\-\-+/-/g; # Remove sequences of binding characters
+ $glob =~ s/^-//; # Clean beginning
+ $glob =~ s/\.zip$//; # Remove file extension
+ $glob =~ s/-$//; # Clean end
+ return $glob;
+};
+
1;
diff --git a/script/korapxml2krill b/script/korapxml2krill
index 54edaa8..0138423 100644
--- a/script/korapxml2krill
+++ b/script/korapxml2krill
@@ -12,7 +12,7 @@
use Pod::Usage;
use Cache::FastMmap;
use Directory::Iterator;
-use KorAP::XML::Krill;
+use KorAP::XML::Krill qw!get_file_name_from_glob!;
use KorAP::XML::Archive;
use KorAP::XML::Tokenizer;
use KorAP::XML::Batch::File;
@@ -162,7 +162,6 @@
VERSION
# Prototypes
-sub get_file_name_from_glob($);
sub get_file_name($);
# Parse comand
@@ -633,19 +632,6 @@
};
-sub get_file_name_from_glob ($) {
- my $glob = shift;
- $glob =~ s![\\\/]!-!g; # Transform paths
- $glob =~ s/[\*\?]//g; # Remove arbitrary fills
- $glob =~ s/[\{\}\[\]]/-/g; # Remove class and multiple brackets
- $glob =~ s/\-\-+/-/g; # Remove sequences of binding characters
- $glob =~ s/^-//; # Clean beginning
- $glob =~ s/-$//; # Clean end
- $glob =~ s/\.zip$//; # Remove file extension
- return $glob;
-};
-
-
# Convert sigle to path construct
s!^\s*([^_]+?)_([^\.]+?)\.(.+?)\s*$!$1/$2/$3! foreach @sigle;
diff --git a/t/krill.t b/t/krill.t
new file mode 100644
index 0000000..d670171
--- /dev/null
+++ b/t/krill.t
@@ -0,0 +1,34 @@
+use strict;
+use warnings;
+use utf8;
+use Test::More;
+use lib 'lib', '../lib';
+
+use_ok('KorAP::XML::Krill', 'get_file_name_from_glob');
+
+is(
+ get_file_name_from_glob('versuch'),
+ 'versuch'
+);
+
+is(
+ get_file_name_from_glob('versuch/alt\seltsam'),
+ 'versuch-alt-seltsam'
+);
+
+is(
+ get_file_name_from_glob('versuch/*.xml'),
+ 'versuch-.xml'
+);
+
+is(
+ get_file_name_from_glob('versuch//[a-z]{2,4}.xml'),
+ 'versuch-a-z-2-4-.xml'
+);
+
+is(
+ get_file_name_from_glob('versuch//[a-z]{2,4}.zip'),
+ 'versuch-a-z-2-4'
+);
+
+done_testing;