/usr/share/perl5/Catmandu/Cmd/data.pm is in libcatmandu-perl 0.9505-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | package Catmandu::Cmd::data;
use Catmandu::Sane;
our $VERSION = '0.9505';
use parent 'Catmandu::Cmd';
use Catmandu qw(:all);
use Catmandu::Fix;
use namespace::clean;
sub command_opt_spec {
(
[ "from-store=s", "", { default => Catmandu->default_store } ],
[ "from-importer=s", "" ],
[ "from-bag=s", "" ],
[ "count", "" ],
[ "into-exporter=s", "" ],
[ "into-store=s", "", { default => Catmandu->default_store } ],
[ "into-bag=s", "" ],
[ "start=i", "" ],
[ "limit=i", "" ],
[ "total=i", "" ],
[ "cql-query|q=s", "" ],
[ "query=s", "" ],
[ "fix=s@", "fix expression(s) or fix file(s)" ],
[ "replace", "" ],
[ "verbose|v", "" ],
);
}
sub command {
my ($self, $opts, $args) = @_;
my $from_opts = {};
my $into_opts = {};
for (my $i = 0; $i < @$args; $i++) {
my $arg = $args->[$i];
if (my ($for, $key) = $arg =~ /^--(from|into)-([\w\-]+)$/) {
if (defined(my $val = $args->[++$i])) {
$key =~ s/-/_/g;
($for eq 'from' ? $from_opts : $into_opts)->{$key} = $val;
}
}
}
my $from;
my $into;
if ($opts->from_bag) {
$from = store($opts->from_store, $from_opts)->bag($opts->from_bag);
} else {
$from = importer($opts->from_importer, $from_opts);
}
if ($opts->query || $opts->cql_query) {
$self->usage_error("Bag isn't searchable") unless $from->can('searcher');
$from = $from->searcher(
cql_query => $opts->cql_query,
query => $opts->query,
limit => $opts->limit,
);
}
elsif (defined $opts->limit) {
$from = $from->take($opts->limit);
}
if ($opts->start || defined $opts->total) {
$from = $from->slice($opts->start, $opts->total);
}
if ($opts->count) {
return say $from->count;
}
if ($opts->into_bag) {
$into = store($opts->into_store, $into_opts)->bag($opts->into_bag);
} else {
$into = exporter($opts->into_exporter, $into_opts);
}
if (my $fix = $opts->fix) {
$from = Catmandu::Fix->new(fixes => $fix)->fix($from);
}
if ($opts->replace && $into->can('delete_all')) {
$into->delete_all;
}
if ($opts->verbose) {
$from = $from->benchmark;
}
my $n = $into->add_many($from);
$into->commit;
if ($opts->verbose) {
say STDERR $n == 1
? "added 1 object"
: "added $n objects";
say STDERR "done";
}
}
1;
__END__
=pod
=head1 NAME
Catmandu::Cmd::data - store, index, search, import, export or convert objects
=cut
|