App-TextTemplatePermuteUtils

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    Process a Text::Template::Permute template and output the results.

    This function is not exported.

    Arguments ('*' denotes required arguments):

    *   array => *bool*

        Return items as array, not as a single string.

    *   clipboard => *str*

        Add items to clipboard.

    *   items => *posint*

        Only return this many items.

    *   separator => *str*

        String to add as separator between items (only when not specifying
        --array).

lib/App/TextTemplatePermuteUtils.pm  view on Meta::CPAN

            summary => 'The template string',
            schema => 'str*',
            pos => 0,
            cmdline_src => 'stdin_or_file',
        },
        array => {
            summary => 'Return items as array, not as a single string',
            schema => 'bool*',
            cmdline_aliases => {a => {}},
        },
        clipboard => {
            summary => 'Add items to clipboard',
            schema => ['str*', in=>['tee','only']],
            cmdline_aliases => {
                Y => {is_flag=>1, summary=>'Shortcut for --clipboard=tee', code=>sub { $_[0]{clipboard} = 'tee' }},
                y => {is_flag=>1, summary=>'Shortcut for --clipboard=only', code=>sub { $_[0]{clipboard} = 'only' }},
            },
        },
        items => {
            summary => 'Only return this many items',
            schema => 'posint*',
            cmdline_aliases => {n => {}},
        },
        shuffle => {
            summary => 'Shuffle/randomize order or results',
            schema => 'bool*',

lib/App/TextTemplatePermuteUtils.pm  view on Meta::CPAN

        separator => {
            summary => 'String to add as separator between items (only when not specifying --array)',
            schema => 'str*',
            cmdline_aliases => {s => {}},
        },
    },
};
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

lib/App/TextTemplatePermuteUtils.pm  view on Meta::CPAN

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>

script/template-permute  view on Meta::CPAN

=head1 VERSION

This document describes version 0.002 of template-permute (from Perl distribution App-TextTemplatePermuteUtils), released on 2026-02-22.

=head1 SYNOPSIS

B<template-permute> B<L<--help|/"--help, -h, -?">> (or B<L<-h|/"--help, -h, -?">>, B<L<-?|/"--help, -h, -?">>)

B<template-permute> B<L<--version|/"--version, -v">> (or B<L<-v|/"--version, -v">>)

B<template-permute> [B<L<--array|/"--array, -a">>|B<L<-a|/"--array, -a">>|B<L<--no-array|/"--array, -a">>|B<L<--noarray|/"--array, -a">>] [B<L<--clipboard|/"-y">>=I<str>|B<L<-Y|/"-y">>|B<L<-y|/"-y">>] [B<L<--config-path|/"--config-path=s, -c">>=I<pat...

=head1 OPTIONS

C<*> marks required options.

=head2 Main options

=over

=item B<--array>, B<-a>

Return items as array, not as a single string.

=item B<--clipboard>=I<s>

Add items to clipboard.

Valid values:

 ["tee","only"]

=item B<--items>=I<s>, B<-n>

Only return this many items.

=item B<--separator>=I<s>, B<-s>

script/template-permute  view on Meta::CPAN

Shuffle/randomize order or results.

=item B<--template>=I<s>

The template string.

Can also be specified as the 1st command-line argument.

=item B<-y>

Shortcut for --clipboard=only.

See C<--clipboard>.

=item B<-Y>

Shortcut for --clipboard=tee.

See C<--clipboard>.

=back

=head2 Configuration options

=over

=item B<--config-path>=I<s>, B<-c>

Set path to configuration file.

script/template-permute  view on Meta::CPAN

 arg1=val1
 arg2=val2

 

which is equivalent to setting C<< -plugins=-DumpArgs@before_validate_args@99,-Foo@after_validate_args,arg1,val1,arg2,val2 >>.

List of available configuration parameters:

 array (see --array)
 clipboard (see --clipboard)
 format (see --format)
 items (see --items)
 naked_res (see --naked-res)
 separator (see --separator)
 shuffle (see --shuffle)
 template (see --template)

=head1 ENVIRONMENT

=head2 TEMPLATE_PERMUTE_OPT



( run in 0.937 second using v1.01-cache-2.11-cpan-2398b32b56e )