| 1 | package File::Dir::Dumper::Stream::JSON::Reader; | ||||||||||
| 2 | 3 | $File::Dir::Dumper::Stream::JSON::Reader::VERSION = '0.6.4'; | |||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 3 | ▶ | use 5.012; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 3 | ▶ | use parent 'File::Dir::Dumper::Base'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 3 | ▶ | use Carp (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 3 | ▶ | use JSON::MaybeXS qw(decode_json); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 3 | ▶ | use Class::XSAccessor accessors => { _in => 'in' }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | sub _init | ||||||||||
| 17 | { | ||||||||||
| 18 | 4 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 4 | my $args = shift; | |||||||||
| 20 | |||||||||||
| 21 | 4 | $self->_in( $args->{input} ); | |||||||||
| 22 | |||||||||||
| 23 | 4 | $self->_init_stream(); | |||||||||
| 24 | |||||||||||
| 25 | 4 | return; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | sub _readline | ||||||||||
| 29 | { | ||||||||||
| 30 | 18 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_readline: called CC=1 SCAR=0.0
| |||||||||||
| 31 | |||||||||||
| 32 | 18 | return readline( $self->_in() ); | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | sub _eof | ||||||||||
| 36 | { | ||||||||||
| 37 | 24 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_eof: called CC=1 SCAR=0.0
| |||||||||||
| 38 | |||||||||||
| 39 | 24 | return eof( $self->_in() ); | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | sub _init_stream | ||||||||||
| 43 | { | ||||||||||
| 44 | 4 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_init_stream: called CC=2 SCAR=7.6
| |||||||||||
| 45 | |||||||||||
| 46 | 4 | ▶ | if ( $self->_readline() ne "# JSON Stream by Shlomif - Version 0.2.0\n" ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | { | ||||||||||
| 48 | 0 | Carp::confess "No header for JSON stream"; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 4 | return; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | sub fetch | ||||||||||
| 55 | { | ||||||||||
| 56 | 10 | ▶ | my $self = shift; | ||||||||
|
Subroutine
fetch: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 57 | |||||||||||
| 58 | 10 | my $buffer = ""; | |||||||||
| 59 | 10 | my $line; | |||||||||
| 60 | |||||||||||
| 61 | 10 | ▶ | if ( $self->_eof() ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | { | ||||||||||
| 63 | 3 | return; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | LINES: | ||||||||||
| 67 | 7 | ▶ | while ( !$self->_eof() ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | { | ||||||||||
| 69 | 14 | $line = $self->_readline(); | |||||||||
| 70 | 14 | ▶ | if ( $line eq "--/f\n" ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | { | ||||||||||
| 72 | 7 | return decode_json($buffer); | |||||||||
| 73 | } | ||||||||||
| 74 | else | ||||||||||
| 75 | { | ||||||||||
| 76 | 7 | $buffer .= $line; | |||||||||
| 77 | } | ||||||||||
| 78 | } | ||||||||||
| 79 | 0 | Carp::confess "Error! Reached end of file without record terminator."; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | |||||||||||
| 83 | 3 | 1; # End of File::Dir::Dumper | |||||||||
| 84 | |||||||||||
| 85 | __END__ | ||||||||||