Introduce tei2korapxml command
Change-Id: I6b862a46a1b56d27474264793aebed3257f7643f
diff --git a/Changes b/Changes
index cce08ac..68549bc 100755
--- a/Changes
+++ b/Changes
@@ -1,8 +1,9 @@
0.44 2022-01-04
- Fixed autosecrets migration. (diewald)
- Format page numbers in pagination (diewald).
+ - Introduce tei2korapxml command via plugin.
-0.43 2021-12-01
+0.43 2021-11-05
- New menu class that has an entry at the very end,
similar to the input text prefix,
that is always available. (lerepp)
diff --git a/Makefile.PL b/Makefile.PL
index 893879f..1b52abc 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -13,6 +13,7 @@
'Test::More' => 0,
'Test::Mojo::Session' => 1.06,
'Test::Mojo::WithRoles' => 0.02,
+ 'Test::Output' => 0,
},
LICENSE => 'freebsd',
PREREQ_PM => {
diff --git a/README.md b/README.md
index a028a87..6e810c3 100644
--- a/README.md
+++ b/README.md
@@ -241,7 +241,7 @@
- `Auth`: For integrating user management
supported by [Kustvakt full](https://github.com/KorAP/Kustvakt/tree/master/full).
- `Piwik`: For integrating Matomo/Piwik
-
+- `Tei2KorAPXML`: For integrated calls to [tei2korapxml](https://github.com/KorAP/KorAP-XML-TEI), if installed
## Troubleshooting
diff --git a/lib/Kalamar/Plugin/Tei2KorAPXML.pm b/lib/Kalamar/Plugin/Tei2KorAPXML.pm
new file mode 100644
index 0000000..0a219a0
--- /dev/null
+++ b/lib/Kalamar/Plugin/Tei2KorAPXML.pm
@@ -0,0 +1,21 @@
+package Kalamar::Plugin::Tei2KorAPXML;
+use Mojo::Base 'Mojolicious::Plugin';
+use Mojo::Base -strict;
+
+sub register {
+ my ($plugin, $mojo) = @_;
+
+ if (eval {
+ require KorAP::XML::TEI;
+ 1;
+ }) {
+
+ # Add additional command path
+ push(@{$mojo->commands->namespaces}, __PACKAGE__);
+ return 1;
+ };
+
+ return 0;
+};
+
+1;
diff --git a/lib/Kalamar/Plugin/Tei2KorAPXML/tei2korapxml.pm b/lib/Kalamar/Plugin/Tei2KorAPXML/tei2korapxml.pm
new file mode 100644
index 0000000..2292853
--- /dev/null
+++ b/lib/Kalamar/Plugin/Tei2KorAPXML/tei2korapxml.pm
@@ -0,0 +1,15 @@
+package Kalamar::Plugin::Tei2KorAPXML::tei2korapxml;
+use Mojo::Base 'Mojolicious::Command';
+
+has description => 'Conversion of TEI P5 based formats to KorAP-XML';
+has usage => sub {
+ return qx{tei2korapxml --help};
+};
+
+sub run {
+ shift;
+ system('tei2korapxml', @_);
+ return 1;
+};
+
+1;
diff --git a/t/plugin/tei2korapxml.t b/t/plugin/tei2korapxml.t
new file mode 100644
index 0000000..6954281
--- /dev/null
+++ b/t/plugin/tei2korapxml.t
@@ -0,0 +1,33 @@
+use Test::More;
+use Test::Mojo;
+use Test::Output;
+
+eval {
+ require KorAP::XML::TEI;
+ 1;
+} || do {
+ plan skip_all => "KorAP::XML::TEI is not installed";
+};
+
+my $t = Test::Mojo->new(Kalamar => {
+ Kalamar => {
+ plugins => ['Tei2KorAPXML']
+ }
+});
+
+my $app = $t->app;
+
+my $cmds = $app->commands;
+
+ok(grep/::Tei2KorAPXML/, @{$cmds->namespaces}, 'Namespace is set');
+
+stdout_like(
+ sub {
+ $cmds->run('tei2korapxml','-v');
+ },
+ qr{cat corpus\.i5\.xml}
+);
+
+done_testing;
+
+1;