App-safer
view release on metacpan or search on metacpan
lib/App/safer.pm view on Meta::CPAN
args => {
action => {
schema => ['str*', in=>[qw/list-encodings encode/]],
default => 'encode',
cmdline_aliases => {
a => {},
l => {
is_flag => 1,
summary => 'Shortcut for --action=list-encodings, specify another -l for --detail listing',
code => sub {
$_[0]{action} = 'list-encodings';
if ($num_l_specified++) {
$_[0]{detail} = 1;
}
},
},
},
},
detail => {
schema => 'bool*',
summary => 'Show detail information in list',
},
encoding => {
schema => 'str*',
default => 'alphanum_kebab_nodashend_lc',
cmdline_aliases => {e=>{}},
completion => sub {
require Complete::Util;
my %args = @_;
my $encres = _list_encodings(detail => 1);
Complete::Util::complete_array_elem(
array => [map { $_->{encoding} } @{ $encres->[2] }],
summaries => [map { $_->{summary} } @{ $encres->[2] }],
word => $args{word},
);
},
},
# TODO: encoding_args
text => {
schema => 'str*',
pos => 0,
},
}, # args
examples => [
{
summary => 'List available encodings',
argv => ["-l"],
},
{
summary => 'List available encodings (verbose mode)',
argv => ["-ll"],
},
{
summary => 'Convert a single text',
src => "echo 'Foo Bar, Co., Ltd.' | [[prog]]",
src_plang => "bash",
},
{
summary => 'Convert each line then show result and add to clipboard (required clipadd from App::ClipboardUtils)',
src => "clipadd -c [[prog]] --tee",
src_plang => "bash",
test => 0,
'x.doc.show_result' => 0,
},
],
};
sub app {
$num_l_specified = 0;
my %args = @_;
my $action = $args{action} // 'encode';
my $text = $args{text};
my $encoding = $args{encoding} // 'alphanum_kebab_nodashend_lc';
my $detail = $args{detail};
if ($action eq 'list-encodings') {
return _list_encodings(detail => $detail);
}
$text = do { local $/; scalar <> } unless defined $text;
$text //= "";
require Text::Safer;
[200, "OK", Text::Safer::encode_safer($text, $encoding)];
}
1;
# ABSTRACT: CLI for Text::Safer
__END__
=pod
=encoding UTF-8
=head1 NAME
App::safer - CLI for Text::Safer
=head1 VERSION
This document describes version 0.003 of App::safer (from Perl distribution App-safer), released on 2025-06-15.
=head1 SYNOPSIS
See L<safer> script.
=head1 FUNCTIONS
=head2 app
Usage:
app(%args) -> [$status_code, $reason, $payload, \%result_meta]
CLI for Text::Safer.
Examples:
( run in 2.120 seconds using v1.01-cache-2.11-cpan-df04353d9ac )