App-PTP

 view release on metacpan or  search on metacpan

lib/App/PTP/Args.pm  view on Meta::CPAN

    'execute|e=s' => sub {
      push @{$cur_pipeline}, ['execute', \&do_execute, {%modes}, 'execute', $_[1]];
    },
    'M=s' => sub { push @{$cur_pipeline}, ['M', \&do_execute, {%modes}, 'M', $_[1]] },
    'load|l=s' => sub { push @{$cur_pipeline}, ['load', \&do_load, {%modes}, $_[1]] },
    'sort' => sub { push @{$cur_pipeline}, ['sort', \&do_sort, {%modes}] },
    'numeric-sort|ns' => sub {
      my $opt = {%modes, comparator => \'numeric'};
      push @{$cur_pipeline}, ['numeric-sort', \&do_sort, $opt];
    },
    'locale-sort|ls' => sub {
      my $opt = {%modes, comparator => \'locale'};
      push @{$cur_pipeline}, ['locale-sort', \&do_sort, $opt];
    },
    'semver-sort|ss' => sub {
      my $opt = {%modes, comparator => \'semver'};
      push @{$cur_pipeline}, ['semver-sort', \&do_sort, $opt];
    },
    'custom-sort|cs=s' => sub {
      my $opt = {%modes, comparator => $_[1]};
      push @{$cur_pipeline}, ['custom-sort', \&do_sort, $opt];
    },
    'unique|uniq|u' => sub {

lib/App/PTP/Cheat_Sheet.pod  view on Meta::CPAN

=item B<-n> I<code>: read from C<$_>, write the return values

=item B<-f> I<code> (B<--filter>): return I<true> to keep the line

=item B<-e> I<code> (B<--execute>): execute once per input file

=item B<-l> I<path> (B<--load>): execute the given file, once per input file

=item B<-M> I<module>: load the given module

=item B<--sort>, B<--ns> (B<--numeric-sort>), B<--ls> (B<--locale-sort>),
B<--ss> (B<--semver-sort>), B<--cs> I<code> (B<--custom-sort>)

=item B<-u> (B<--unique>), B<--gu> (B<--global-unique>)

=item B<--head> [I<n>], B<--tail> [I<n>], B<--reverse> (B<--tac>), B<--shuffle>

=item B<--eat>: discard the content of the file

=item B<--ml> I<code> (B<--mark-line>): set the marker for the line with the
return value

lib/App/PTP/Commands.pm  view on Meta::CPAN

  my ($content, $markers, $modes, $options) = @_;
  if (ref($modes->{comparator}) eq 'CODE') {
    # This branch is no longer used.
    @$content = sort { $modes->{comparator}() } @$content;
  } elsif (ref($modes->{comparator}) eq 'SCALAR') {
    if (${$modes->{comparator}} eq 'default') {
      @$content = sort @$content;
    } elsif (${$modes->{comparator}} eq 'numeric') {
      no warnings 'numeric';  ## no critic (ProhibitNoWarnings)
      @$content = sort { $a <=> $b } @$content;
    } elsif (${$modes->{comparator}} eq 'locale') {
      use locale;
      @$content = sort { $a cmp $b } @$content;
    } elsif (${$modes->{comparator}} eq 'semver') {
      my (%parsed, %warned);
      for my $line (@$content) {
        next if exists $parsed{$line};
        my $version = App::PTP::Util::Semver::parse($line);
        $parsed{$line} = $version;
        for my $warning (@{$version->{warnings}}) {
          print "WARNING: ${warning}\n" unless $warned{$warning}++;
        }

script/ptp  view on Meta::CPAN

program.

=item B<--ns>, B<--numeric-sort>

Sort the content of the input using a numeric sort. The numeric value of each
line is extracted by parsing a number at the beginning of the line (which should
look like a number).

The markers of the input lines are reset (no line is marked after this command).

=item B<--ls>, B<--locale-sort>

Sort the content of the input using a locale sensitive sorting. The exact
meaning of this depends on the configuration of your system (see the
L<perllocale> documentation for more details). In practice, it will do things
like correctly comparing equivalent characters and/or ignoring the case.

The markers of the input lines are reset (no line is marked after this command).

=item B<--ss>, B<--semver-sort>

Sort the content of the input as version strings, following the precedence
rules of L<Semantic Versioning|https://semver.org>. So, for example, C<1.9.0>
sorts before C<1.10.0> (instead of after it as a lexicographic sort would do)
and a pre-release version such as C<1.0.0-alpha> sorts before the corresponding

t/203-command-sort.t  view on Meta::CPAN

{
  my $data = ptp([qw(--sort)], 'default_data.txt');
  is($data, "\n.\\+\nBe\nab/cd\nfoobar=\nfoobaz\nlast\nlast=\ntest\n",
     'sort');
}{
  my $data = ptp([qw(--ls)], 'default_data.txt');
  my @expected = ("", ".\\+", "ab/cd", "Be", "foobar=", "foobaz", "last", "last=", "test");
  {
    # The order may vary depending on the system, so let's not hard-code the
    # expected output here.
    use locale;
    @expected = sort @expected;
  }
  is($data, join("\n", @expected)."\n", 'local sort');
}

my $numeric_input = "20ab\n1d\n20.5\n99\nabc\n";

{
  my $data = ptp([qw(--sort)], \$numeric_input);
  is($data, "1d\n20.5\n20ab\n99\nabc\n", 'non numeric sort');



( run in 1.822 second using v1.01-cache-2.11-cpan-ceb78f64989 )