App-Sets

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

     impossible platform

0.974     2016-04-06 22:11:35+02:00 Europe/Rome
   - a couple Windows Win32 seem to be happy with the tests now
   - release

0.973_07  2016-04-05 19:36:48+02:00 Europe/Rome (TRIAL RELEASE)
   - made test about presence of 'sort' more strict

0.973_06  2016-04-03 00:58:07+02:00 Europe/Rome (TRIAL RELEASE)
   - added option for binmode
   - setting :raw:encoding(UTF-8) as default binmode for STDOUT

0.973_05  2015-05-15 18:45:54 Europe/Rome
   - hopefully fixed issue with pipe open on Windows

0.973_04  2015-05-10 18:34:31 Europe/Rome
   - performance enhancement upon sorting
   - added command-line options for sort selection
   - added documentation

0.973_03  2015-05-10 13:37:24 Europe/Rome

bin/sets  view on Meta::CPAN

version 0.978

=pod

=encoding utf-8

=head1 USAGE

   sets [--usage] [--help] [--man] [--version]

   sets [--binmode|-b <string>]
        [--cache-sorted|-S <suffix>]
        [--internal-sort|-I]
        [--loglevel|-l <level>]
        [--sorted|-s]
        [--trim|-t]
        expression...

=head1 EXAMPLES

   # intersect two files

bin/sets  view on Meta::CPAN

uses a backslash to escape the spaces, as well as the fourth example in
which the escape character is repeated due to the interpolation rules
of the shell. The last example leverages upon the shell rules for
escaping AND the fact that simple expressions like that can be specified
as multiple arguments instead of a single string.

=head1 OPTIONS

=over

=item --binmode | -b I<string>

set a string for calling C<binmode> on STDOUT. By default,
C<:raw:encoding(UTF-8)> is set, to normalize newlines handling and
expect UTF-8 data in.

=item --cache-sorted | -S I<suffix>

input files are sorted and saved into a file with the same name and the
I<suffix> appended, so that if this file exists it is used instead of
the input file. In this way it is possible to generate sorted files on
the fly and reuse them if available. For example, suppose that you want
to remove the items in C<removeme> from files C<file1> and C<file2>; in

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

use Getopt::Long
  qw< GetOptionsFromArray :config pass_through no_ignore_case bundling >;
use Pod::Usage qw< pod2usage >;
use Log::Log4perl::Tiny qw< :easy :dead_if_first LOGLEVEL >;
use App::Sets::Parser;
use App::Sets::Iterator;
use App::Sets::Operations;
use App::Sets::Sort qw< sort_filehandle >;

my %config = (
   binmode => ':raw:encoding(UTF-8)',
   loglevel => 'INFO',
   parsedebug => 0,
);

sub populate_config {
   my (@args) = @_;

   $config{sorted} = 1                if $ENV{SETS_SORTED};
   $config{trim}   = 1                if $ENV{SETS_TRIM};
   $config{cache}  = $ENV{SETS_CACHE} if exists $ENV{SETS_CACHE};
   $config{loglevel}  = $ENV{SETS_LOGLEVEL}
      if exists $ENV{SETS_LOGLEVEL};
   $config{parsedebug}  = $ENV{SETS_PARSEDEBUG}
      if exists $ENV{SETS_PARSEDEBUG};
   $config{internal_sort} = $ENV{SETS_INTERNAL_SORT}
      if exists $ENV{SETS_INTERNAL_SORT};
   $config{binmode} = $ENV{SETS_BINMODE} if $ENV{SETS_BINMODE};
   GetOptionsFromArray(
      \@args, \%config, qw< man help usage version
        binmode|b=s
        cache|cache-sorted|S=s
        internal_sort|internal-sort|I!
        loglevel|l=s
        sorted|s!
        trim|t!
        >
     )
     or pod2usage(
      -verbose  => 99,
      -sections => 'USAGE',

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

   } ## end if (@args > 1)
   else {
      $input = shift @args;
   }

   LOGLEVEL('DEBUG') if $config{parsedebug};
   DEBUG "parsing >$input<";
   my $expression = App::Sets::Parser::parse($input, 0);
   LOGLEVEL($config{loglevel});

   binmode STDOUT, $config{binmode};

   my $it = expression($expression);
   while (defined(my $item = $it->drop())) {
      print {*STDOUT} $item;
      print {*STDOUT} "\n" if $config{trim};
   }
   return;
} ## end sub run

sub escape {

lib/App/Sets/Sort.pm  view on Meta::CPAN

our %EXPORT_TAGS = (
   default => [ @EXPORT ],
   all => [ @EXPORT_OK ],
);

sub _test_external_sort {
   my $filename;

   eval {
      (my $fh, $filename) = tempfile(); # might croak
      binmode $fh, ':raw';
      print {$fh} "one\ntwo\nthree\nfour\n" or die 'whatever';
      close $fh or die 'whatever';
   } or return;

   my $fh = eval {
      open my $tfh, '-|', 'sort', '-u', $filename;
      $tfh;
   } or return;
   my @lines = <$fh>;
   return unless scalar(@lines) == 4;



( run in 0.986 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )