PageRenderTime 2280ms CodeModel.GetById 39ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/App/PipeFilter.pm

https://github.com/rcaputo/app-pipefilter
Perl | 97 lines | 2 code | 3 blank | 92 comment | 0 complexity | 08755e35d92be0e6d9b50f71ca0861f5 MD5 | raw file
  1. package App::PipeFilter;
  2. 1;
  3. =pod
  4. =head1 NAME
  5. App::PipeFilter
  6. =head1 DESCRIPTION
  7. App::PipeFilter is a distribution of shell pipeline filters designed
  8. to work with structured data like JSON rather than whitespace
  9. separated fields.
  10. For example, jcut is a simple version of cut(1) that understands JSON
  11. objects rather than whitespace separated fields.
  12. % head -1 sample.json
  13. {"network":"freenode","channel":"#perl","nick":"dngor","karma":"120"}
  14. % jcut -o network -o channel < eg/sample.json | sort | uniq
  15. {"network":"efnet","channel":"#perl"}
  16. {"network":"efnet","channel":"#poe"}
  17. {"network":"efnet","channel":"#reflex"}
  18. {"network":"freenode","channel":"#perl"}
  19. {"network":"freenode","channel":"#poe"}
  20. {"network":"freenode","channel":"#reflex"}
  21. {"network":"magnet","channel":"#perl"}
  22. {"network":"magnet","channel":"#poe"}
  23. {"network":"magnet","channel":"#reflex"}
  24. The jsonpath filter supports more complex expressions using
  25. JSON::Path's variant of JSONPath.
  26. curl -s 'http://api.duckduckgo.com/?q=poe&o=json' |
  27. jsonpath -o '$..Topics.*.FirstURL' -o '$..Topics.*.Text' |
  28. grep -i perl |
  29. jmap -i col0 -o url -i col1 -o title |
  30. json2yaml
  31. ---
  32. title: Perl Object Environment, a library for event driven multitasking for the Perl programming language
  33. url: http://duckduckgo.com/Perl_Object_Environment
  34. =head1 DESIGN GOAL
  35. App::PipeFilter utilities generally follow the UNIX convention of
  36. printing one record per line of text. This maximizes compatibility
  37. with UNIX utilities like sort(1), uniq(1) and grep(1).
  38. =head1 PRO TIPS
  39. JSON isn't particularly concise, so put grep(1), jcut(1) and other
  40. filters that eliminate data as early as possible in pipelines.
  41. =head1 SEE ALSO
  42. L<jcat> - concatenate and print JSON files
  43. L<jcut> - cut out selected portions of each JSON object in a file
  44. L<jmap> - map input JSON fields to output JSON fields by renaming them
  45. L<json2yaml> - convert files of JSON objects into a stream of YAML objects
  46. L<jsonpath> - use JSON::Path to cut out selected portions of JSON objects
  47. L<jsort> - sort input files of JSON objects on key fields
  48. L<mysql2json> - convert mysql -B output to JSON object streams
  49. L<http://json.org/>
  50. L<http://search.cpan.org/perldoc?JSON::Path>
  51. L<http://goessner.net/articles/JsonPath/>
  52. =head1 BUGS
  53. L<https://rt.cpan.org/Public/Dist/Display.html?Name=App-PipeFilter>
  54. =head1 REPOSITORY
  55. L<https://github.com/rcaputo/app-pipefilter>
  56. =head1 COPYRIGHT and LICENSE
  57. App::PipeFilter
  58. is Copyright 2011 by Rocco Caputo.
  59. All rights are reserved.
  60. App::PipeFilter
  61. is released under the same terms as Perl itself.
  62. =cut
  63. # vim: ts=2 sw=2 expandtab