| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 2 |  |  | 2 |  | 653 | use strict; | 
|  | 2 |  |  |  |  | 8 |  | 
|  | 2 |  |  |  |  | 50 |  | 
| 2 | 2 |  |  | 2 |  | 9 | use warnings; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 51 |  | 
| 3 | 2 |  |  | 2 |  | 13 | use utf8; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 19 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | package App::RecordStream::Operation::tojsonarray; | 
| 6 | 2 |  |  | 2 |  | 83 | use base qw(App::RecordStream::Operation); | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 513 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | sub init { | 
| 9 | 2 |  |  | 2 | 0 | 3 | my $this = shift; | 
| 10 | 2 |  |  |  |  | 5 | my $args = shift; | 
| 11 | 2 |  |  |  |  | 11 | $this->parse_options($args); | 
| 12 | 2 |  |  |  |  | 5 | $this->{COUNT} = 0; | 
| 13 |  |  |  |  |  |  | } | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | sub accept_line { | 
| 16 | 4 |  |  | 4 | 0 | 7 | my $this = shift; | 
| 17 | 4 |  |  |  |  | 5 | my $line = shift; | 
| 18 |  |  |  |  |  |  | $this->push_line( | 
| 19 | 4 | 100 |  |  |  | 25 | $this->{COUNT}++ == 0 | 
| 20 |  |  |  |  |  |  | ? "[$line" | 
| 21 |  |  |  |  |  |  | : ",$line" | 
| 22 |  |  |  |  |  |  | ); | 
| 23 | 4 |  |  |  |  | 16 | return 1; | 
| 24 |  |  |  |  |  |  | } | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | sub stream_done { | 
| 27 | 2 |  |  | 2 | 0 | 5 | my $this = shift; | 
| 28 |  |  |  |  |  |  | $this->push_line( | 
| 29 |  |  |  |  |  |  | $this->{COUNT} | 
| 30 | 2 | 100 |  |  |  | 11 | ? "]" | 
| 31 |  |  |  |  |  |  | : "[]" | 
| 32 |  |  |  |  |  |  | ); | 
| 33 |  |  |  |  |  |  | } | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | sub usage { | 
| 36 | 0 |  |  | 0 | 0 |  | my $this = shift; | 
| 37 | 0 |  |  |  |  |  | return < | 
| 38 |  |  |  |  |  |  | Usage: recs tojsonarray [files] | 
| 39 |  |  |  |  |  |  | __FORMAT_TEXT__ | 
| 40 |  |  |  |  |  |  | This command outputs the record stream as a single JSON array.  It | 
| 41 |  |  |  |  |  |  | complements the fromjsonarray command. | 
| 42 |  |  |  |  |  |  | __FORMAT_TEXT__ | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | Examples | 
| 45 |  |  |  |  |  |  | # Save the record stream to a file suitable for loading by any JSON parser | 
| 46 |  |  |  |  |  |  | ... | recs tojsonarray > recs.json | 
| 47 |  |  |  |  |  |  | USAGE | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | 1; |