The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

App::PipeFilter::JsonSort - a sort(1)-like filter that understands JSON fields

VERSION

version 0.005

SYNOPSIS

Here is the jsort(1) pipeline filter.

  #!/usr/bin/perl
  use App::PipeFilter::JsonSort;
  exit App::PipeFilter::JsonSort->new_with_options()->run();

DESCRIPTION

App::PipeFilter::JsonSort implements a pipeline filter similar to sort(1), except that the -k flags describe JSON fields rather than whitespace-separated columns.

This filter currently provides a small subset of the options that sort(1) does.

PUBLIC ATTRIBUTES

This filter uses sort(1) and cut(1) to do most of its work.

k

The k() attribute names one or more key JSON fields to sort by. It is analogous to the -k flag for sort(1). MooseX::Getopt sets k() to the values of the -k options from the command line.

n

The boolean n() attribute (set by the -n command line flag) tells App::PipeFilter::JsonSort to sort numerically. It sorts lexicographically by default.

If specified, -n is passed to sort(1).

r

The boolean r() attribute (set by the -r command line flag) instructs App::PipeFilter::JsonSort to reverse the sort.

If spedified, -r is passed to sort(1).

PUBLIC METHODS

encode_output

encode_output() prepeands JSON records with the values of their key fields in tab-separated form. This output will be piped through sort(1) to do the actual sorting, and through cut(1) to remove the tab-separated sorting columns.

open_output

open_output() opens output through sort(1) and cut(1). It's a huge cheat, but it works for simple cases.

SEE ALSO

You may read this module's implementation in its entirety at

  perldoc -m App::PipeFilter::JsonSort

This class subclasses App::PipeFilter::Generic::Generic. It is customized with App::PipeFilter::Role::Reader::Sysread, App::PipeFilter::Role::Input::Json and App::PipeFilter::Role::Transform::None.

App::PipeFilter has top-level documentation including a table of contents for all the libraries and utilities included in the project.

BUGS

https://rt.cpan.org/Public/Dist/Display.html?Name=App-PipeFilter

REPOSITORY

https://github.com/rcaputo/app-pipefilter

COPYRIGHT AND LICENSE

App::PipeFilter::JsonSort is Copyright 2011 by Rocco Caputo. All rights are reserved. App::PipeFilter::JsonSort is released under the same terms as Perl itself.