Introduce korapxml2krill command
Change-Id: I2495b95a65eaea3dbb394a3ea98097c6636f6b47
diff --git a/Changes b/Changes
index 68549bc..ec02d21 100755
--- a/Changes
+++ b/Changes
@@ -1,7 +1,8 @@
0.44 2022-01-04
- Fixed autosecrets migration. (diewald)
- Format page numbers in pagination (diewald).
- - Introduce tei2korapxml command via plugin.
+ - Introduce tei2korapxml command via plugin (diewald).
+ - Introduce korapxml2tei command via plugin (diewald).
0.43 2021-11-05
- New menu class that has an entry at the very end,
diff --git a/README.md b/README.md
index 6e810c3..3f374aa 100644
--- a/README.md
+++ b/README.md
@@ -242,6 +242,8 @@
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
+- `KorAPXML2Krill`: For integrated calls to [korapxml2krill](https://github.com/KorAP/KorAP-XML-Krill), if installed
+
## Troubleshooting
diff --git a/lib/Kalamar/Plugin/KorAPXML2Krill.pm b/lib/Kalamar/Plugin/KorAPXML2Krill.pm
new file mode 100644
index 0000000..293d0d8
--- /dev/null
+++ b/lib/Kalamar/Plugin/KorAPXML2Krill.pm
@@ -0,0 +1,16 @@
+package Kalamar::Plugin::KorAPXML2Krill;
+use Mojo::Base 'Mojolicious::Plugin';
+use Mojo::Base -strict;
+sub register {
+ my ($plugin, $mojo) = @_;
+ if (eval {
+ require KorAP::XML::Krill;
+ 1;
+ }) {
+ # Add additional command path
+ push(@{$mojo->commands->namespaces}, __PACKAGE__);
+ return 1;
+ };
+ return 0;
+};
+1;
diff --git a/lib/Kalamar/Plugin/KorAPXML2Krill/korapxml2krill.pm b/lib/Kalamar/Plugin/KorAPXML2Krill/korapxml2krill.pm
new file mode 100644
index 0000000..2c6aeec
--- /dev/null
+++ b/lib/Kalamar/Plugin/KorAPXML2Krill/korapxml2krill.pm
@@ -0,0 +1,12 @@
+package Kalamar::Plugin::KorAPXML2Krill::korapxml2krill;
+use Mojo::Base 'Mojolicious::Command';
+has description => 'Merge KorAP-XML data and create Krill documents';
+has usage => sub {
+ return qx{korapxml2krill --help};
+};
+sub run {
+ shift;
+ system('korapxml2krill', @_);
+ return 1;
+};
+1;
diff --git a/t/plugin/korapxml2krill.t b/t/plugin/korapxml2krill.t
new file mode 100644
index 0000000..52a0791
--- /dev/null
+++ b/t/plugin/korapxml2krill.t
@@ -0,0 +1,25 @@
+use Test::More;
+use Test::Mojo;
+use Test::Output;
+eval {
+ require KorAP::XML::Krill;
+ 1;
+} || do {
+ plan skip_all => "KorAP::XML::Krill is not installed";
+};
+my $t = Test::Mojo->new(Kalamar => {
+ Kalamar => {
+ plugins => ['KorAPXML2Krill']
+ }
+});
+my $app = $t->app;
+my $cmds = $app->commands;
+ok(grep/::KorAPXML2Krill/, @{$cmds->namespaces}, 'Namespace is set');
+stdout_like(
+ sub {
+ $cmds->run('korapxml2krill','-v');
+ },
+ qr{\[archive\|extract\]}
+);
+done_testing;
+1;