App-PickRandomLines
view release on metacpan or search on metacpan
script/pick view on Meta::CPAN
#!perl
### begin code_after_shebang
# Note: This script is a CLI for Riap function /App/PickRandomLines/pick_random_lines
# and generated automatically using Perinci::CmdLine::Gen version 0.502
### end code_after_shebang
# PERICMD_INLINE_SCRIPT: {"code_after_shebang":"...","config_dirs":null,"config_filename":"pick.conf","env_name":"PICK_OPT","include":null,"log":null,"pack_deps":1,"pod":0,"read_config":1,"read_env":1,"script_name":"pick","script_summary":"Pick one o...
# This script is generated by Perinci::CmdLine::Inline version 0.554 on Mon Nov 20 12:11:15 2023.
# Rinci metadata taken from these modules: App::PickRandomLines (no version)
# You probably should not manually edit this file.
## no critic: TestingAndDebugging::RequireUseStrict
# PODNAME: pick
# ABSTRACT: Pick one or more random lines from input (shorter alias for 'pick-random-lines')
# BEGIN DATAPACK CODE
package main::_DataPacker;
our $handler;
sub main::_DataPacker::INC { goto $handler }
package main;
{
my $toc;
my $data_linepos = 1;
$main::_DataPacker::handler = sub {
my $debug = $ENV{PERL_DATAPACKER_DEBUG};
if ($debug) {
my @caller0 = caller;
warn "[datapacker] Hook called with arguments: (".join(",", @_).") by package $caller0[0] in file $caller0[1] line $caller0[2]\n";
}
$toc ||= do {
my $fh = \*DATA;
my $header_line;
my $header_found;
while (1) {
my $header_line = <$fh>;
defined($header_line)
or die "Unexpected end of data section while reading header line";
chomp($header_line);
if ($header_line eq 'Data::Section::Seekable v1') {
$header_found++;
last;
}
}
die "Can't find header 'Data::Section::Seekable v1'"
unless $header_found;
my %toc;
my $i = 0;
while (1) {
$i++;
my $toc_line = <$fh>;
defined($toc_line)
or die "Unexpected end of data section while reading TOC line #$i";
chomp($toc_line);
$toc_line =~ /\S/ or last;
$toc_line =~ /^([^,]+),(\d+),(\d+)(?:,(.*))?$/
or die "Invalid TOC line #$i in data section: $toc_line";
$toc{$1} = [$2, $3, $4];
}
script/pick view on Meta::CPAN
=item B<--help>, B<-h>, B<-?>
Display help message and exit.
=item B<--version>, B<-v>
Display program's version and exit.
=back
=head1 COMPLETION
The script comes with a companion shell completer script (L<_pick>)
for this script.
=head2 bash
To activate bash completion for this script, put:
complete -C _pick pick
in your bash startup (e.g. F<~/.bashrc>). Your next shell session will then
recognize tab completion for the command. Or, you can also directly execute the
line above in your shell to activate immediately.
It is recommended, however, that you install modules using L<cpanm-shcompgen>
which can activate shell completion for scripts immediately.
=head2 tcsh
To activate tcsh completion for this script, put:
complete pick 'p/*/`pick`/'
in your tcsh startup (e.g. F<~/.tcshrc>). Your next shell session will then
recognize tab completion for the command. Or, you can also directly execute the
line above in your shell to activate immediately.
It is also recommended to install L<shcompgen> (see above).
=head2 other shells
For fish and zsh, install L<shcompgen> as described above.
=head1 CONFIGURATION FILE
This script can read configuration files. Configuration files are in the format of L<IOD>, which is basically INI with some extra features.
By default, these names are searched for configuration filenames (can be changed using C<--config-path>): F<~/.config/pick.conf>, F<~/pick.conf>, or F</etc/pick.conf>.
All found files will be read and merged.
To disable searching for configuration files, pass C<--no-config>.
You can put multiple profiles in a single file by using section names like C<[profile=SOMENAME]> or C<[SOMESECTION profile=SOMENAME]>. Those sections will only be read if you specify the matching C<--config-profile SOMENAME>.
You can also put configuration for multiple programs inside a single file, and use filter C<program=NAME> in section names, e.g. C<[program=NAME ...]> or C<[SOMESECTION program=NAME]>. The section will then only be used when the reading program match...
You can also filter a section by environment variable using the filter C<env=CONDITION> in section names. For example if you only want a section to be read if a certain environment variable is true: C<[env=SOMEVAR ...]> or C<[SOMESECTION env=SOMEVAR ...
To load and configure plugins, you can use either the C<-plugins> parameter (e.g. C<< -plugins=DumpArgs >> or C<< -plugins=DumpArgs@before_validate_args >>), or use the C<[plugin=NAME ...]> sections, for example:
[plugin=DumpArgs]
-event=before_validate_args
-prio=99
[plugin=Foo]
-event=after_validate_args
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:
algorithm (see --algorithm)
files (see --file)
format (see --format)
naked_res (see --naked-res)
num_lines (see --num-lines)
=head1 ENVIRONMENT
=head2 PICK_OPT
String. Specify additional command-line options.
=head1 FILES
=head2 ~/.config/pick.conf
=head2 ~/pick.conf
=head2 /etc/pick.conf
=head1 HOMEPAGE
Please visit the project's homepage at L<https://metacpan.org/release/App-PickRandomLines>.
=head1 SOURCE
Source repository is at L<https://github.com/perlancar/perl-App-PickRandomLines>.
=head1 SEE ALSO
L<Data::Unixish::pick>.
L<shuf>. The venerable Unix utility. C<shuf -n> is a Unix idiom for when wanting to pick one or several lines from an
input. Our C<pick> is generally slower than the optimized C-based utility, but
offers several pick algorithms like C<scan> (which does not need to hold the
entire input in memory for shuffling) and C<seek> (which does not need to scan
the entire input).
=head1 AUTHOR
perlancar <perlancar@cpan.org>
=head1 CONTRIBUTING
To contribute, you can send patches by email/via RT, or send pull requests on
GitHub.
Most of the time, you don't need to build the distribution yourself. You can
simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your
system), you can install L<Dist::Zilla>,
L<Dist::Zilla::PluginBundle::Author::PERLANCAR>,
L<Pod::Weaver::PluginBundle::Author::PERLANCAR>, and sometimes one or two other
script/pick view on Meta::CPAN
#sub _non_methods {
# my ($me, $role) = @_;
# my $info = $INFO{$role} or return {};
#
# my %non_methods = %{ $info->{non_methods} || {} };
#
# # this is only for backwards compatibility with older Moo, which
# # reimplements method tracking rather than calling our method
# my %not_methods = reverse %{ $info->{not_methods} || {} };
# return \%non_methods unless keys %not_methods;
#
# my $subs = $me->_all_subs($role);
# for my $sub (grep !/\A\(/, keys %$subs) {
# my $code = $subs->{$sub};
# if (exists $not_methods{$code}) {
# $non_methods{$sub} = $code;
# }
# }
#
# return \%non_methods;
#}
#
#sub _concrete_methods_of {
# my ($me, $role) = @_;
# my $info = $INFO{$role};
#
# return $info->{methods}
# if $info && $info->{methods};
#
# my $non_methods = $me->_non_methods($role);
#
# my $subs = $me->_all_subs($role);
# for my $sub (keys %$subs) {
# if ( exists $non_methods->{$sub} && $non_methods->{$sub} == $subs->{$sub} ) {
# delete $subs->{$sub};
# }
# }
#
# if ($info) {
# $info->{methods} = $subs;
# }
# return $subs;
#}
#
#sub methods_provided_by {
# my ($me, $role) = @_;
# $me->_require_module($role);
# croak "${role} is not a ${me}" unless $me->is_role($role);
# sort (keys %{$me->_concrete_methods_of($role)}, @{$INFO{$role}->{requires}||[]});
#}
#
#sub _install_methods {
# my ($me, $to, $role) = @_;
#
# my $methods = $me->_concrete_methods_of($role);
#
# my %existing_methods;
# @existing_methods{keys %{ $me->_all_subs($to) }} = ();
#
# # _concrete_methods_of caches its result on roles. that cache needs to be
# # invalidated after applying roles
# delete $INFO{$to}{methods} if $INFO{$to};
#
# foreach my $i (keys %$methods) {
# next
# if exists $existing_methods{$i};
#
# my $glob = _getglob "${to}::${i}";
# *$glob = $methods->{$i};
#
# # overloads using method names have the method stored in the scalar slot
# # and &overload::nil in the code slot.
# next
# unless $i =~ /^\(/
# && ((defined &overload::nil && $methods->{$i} == \&overload::nil)
# || (defined &overload::_nil && $methods->{$i} == \&overload::_nil));
#
# my $overload = ${ _getglob "${role}::${i}" };
# next
# unless defined $overload;
#
# *$glob = \$overload;
# }
#
# $me->_install_does($to);
#}
#
#sub _install_modifiers {
# my ($me, $to, $name) = @_;
# return unless my $modifiers = $INFO{$name}{modifiers};
# my $info = $INFO{$to};
# my $existing = ($info ? $info->{modifiers} : $COMPOSED{modifiers}{$to}) ||= [];
# my @modifiers = grep {
# my $modifier = $_;
# !grep $_ == $modifier, @$existing;
# } @{$modifiers||[]};
# push @$existing, @modifiers;
#
# if (!$info) {
# foreach my $modifier (@modifiers) {
# $me->_install_single_modifier($to, @$modifier);
# }
# }
#}
#
#my $vcheck_error;
#
#sub _install_single_modifier {
# my ($me, @args) = @_;
# defined($vcheck_error) or $vcheck_error = do {
# local $@;
# eval {
# require Class::Method::Modifiers;
# Class::Method::Modifiers->VERSION(1.05);
# 1;
# } ? 0 : $@;
# };
# $vcheck_error and die $vcheck_error;
# Class::Method::Modifiers::install_modifier(@args);
#}
#
script/pick view on Meta::CPAN
# env => {},
# prog => {},
# pkg => {},
# func => {},
# code => {},
# tmp_dir => {},
# trash_dir => {},
# },
# },
# },
#
# examples => [
# {value=>{}, valid=>1},
# {
# value=>{v=>1.1, summary=>"Some function", args=>{a1=>{}, a2=>{}}},
# valid=>1,
# },
# # XXX we have not implemented property & attribute checking
# ],
#
#}, {}];
#
#$schema->[1]{_prop}{args}{_value_prop}{meta} = $schema->[1];
#$schema->[1]{_prop}{args}{_value_prop}{element_meta} = $schema->[1];
#
## just so the dzil plugin won't complain about schema not being normalized.
## because this is a circular structure and normalizing creates a shallow copy.
#
#$schema = Data::Sah::Normalize::normalize_schema($schema);
#
#1;
## ABSTRACT: Rinci function metadata
#
#__END__
#
#=pod
#
#=encoding UTF-8
#
#=head1 NAME
#
#Sah::Schema::rinci::function_meta - Rinci function metadata
#
#=head1 VERSION
#
#This document describes version 1.1.98.0 of Sah::Schema::rinci::function_meta (from Perl distribution Sah-Schemas-Rinci), released on 2021-07-20.
#
#=head1 SYNOPSIS
#
#To check data against this schema (requires L<Data::Sah>):
#
# use Data::Sah qw(gen_validator);
# my $validator = gen_validator("rinci::function_meta*");
# say $validator->($data) ? "valid" : "INVALID!";
#
# # Data::Sah can also create validator that returns nice error message string
# # and/or coerced value. Data::Sah can even create validator that targets other
# # language, like JavaScript. All from the same schema. See its documentation
# # for more details.
#
#To validate function parameters against this schema (requires L<Params::Sah>):
#
# use Params::Sah qw(gen_validator);
#
# sub myfunc {
# my @args = @_;
# state $validator = gen_validator("rinci::function_meta*");
# $validator->(\@args);
# ...
# }
#
#To specify schema in L<Rinci> function metadata and use the metadata with
#L<Perinci::CmdLine> to create a CLI:
#
# # in lib/MyApp.pm
# package
# MyApp;
# our %SPEC;
# $SPEC{myfunc} = {
# v => 1.1,
# summary => 'Routine to do blah ...',
# args => {
# arg1 => {
# summary => 'The blah blah argument',
# schema => ['rinci::function_meta*'],
# },
# ...
# },
# };
# sub myfunc {
# my %args = @_;
# ...
# }
# 1;
#
# # in myapp.pl
# package
# main;
# use Perinci::CmdLine::Any;
# Perinci::CmdLine::Any->new(url=>'MyApp::myfunc')->run;
#
# # in command-line
# % ./myapp.pl --help
# myapp - Routine to do blah ...
# ...
#
# % ./myapp.pl --version
#
# % ./myapp.pl --arg1 ...
#
#Sample data:
#
# {} # valid
#
# {args=>{a1=>{},a2=>{}},summary=>"Some function",v=>1.1} # valid
#
#=head1 HOMEPAGE
#
#Please visit the project's homepage at L<https://metacpan.org/release/Sah-Schemas-Rinci>.
#
#=head1 SOURCE
( run in 0.574 second using v1.01-cache-2.11-cpan-140bd7fdf52 )