App-TextTemplatePermuteUtils
view release on metacpan or search on metacpan
lib/App/TextTemplatePermuteUtils.pm view on Meta::CPAN
sub template_permute {
my %args = @_;
my $clipboard = $args{clipboard} // '';
my $template = $args{template};
my $ttp = Text::Template::Permute->new;
$ttp->template($template);
my @res = $ttp->process;
if ($args{shuffle}) {
@res = List::Util::shuffle(@res);
}
if ($args{items} && $args{items} < @res) {
splice @res, $args{items};
}
unless ($args{array}) {
my $separator = $args{separator} // '';
$separator .= "\n" unless $separator =~ /\R\z/;
my $res = join $separator, @res;
@res = ($res);
}
if ($clipboard) {
require Clipboard::Any;
for my $content (@res) {
Clipboard::Any::add_clipboard_content(content => $content);
}
}
if ($clipboard eq 'only') {
[200, "OK"];
} elsif ($args{array}) {
[200, "OK", \@res];
} else {
[200, "OK", $res[0]];
}
}
1;
# ABSTRACT: CLI utilities related to Text::Template::Permute
__END__
=pod
=encoding UTF-8
=head1 NAME
App::TextTemplatePermuteUtils - CLI utilities related to Text::Template::Permute
=head1 VERSION
This document describes version 0.002 of App::TextTemplatePermuteUtils (from Perl distribution App-TextTemplatePermuteUtils), released on 2026-02-22.
=head1 DESCRIPTION
This distributions provides the following command-line utilities related to
text fragment:
=over
=item * L<template-permute>
=back
=head1 FUNCTIONS
=head2 template_permute
Usage:
template_permute(%args) -> [$status_code, $reason, $payload, \%result_meta]
Process a Text::Template::Permute template and output the results.
This function is not exported.
Arguments ('*' denotes required arguments):
=over 4
=item * B<array> => I<bool>
Return items as array, not as a single string.
=item * B<clipboard> => I<str>
Add items to clipboard.
=item * B<items> => I<posint>
Only return this many items.
=item * B<separator> => I<str>
String to add as separator between items (only when not specifying --array).
=item * B<shuffle> => I<bool>
ShuffleE<sol>randomize order or results.
=item * B<template> => I<str>
The template string.
=back
Returns an enveloped result (an array).
First element ($status_code) is an integer containing HTTP-like status code
(200 means OK, 4xx caller error, 5xx function error). Second element
($reason) is a string containing error message, or something like "OK" if status is
200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth
element (%result_meta) is called result metadata and is optional, a hash
that contains extra information, much like how HTTP response headers provide additional metadata.
( run in 1.193 second using v1.01-cache-2.11-cpan-b16cb0d3907 )