App-RecordStream
view release on metacpan or search on metacpan
lib/App/RecordStream/InputStream.pm view on Meta::CPAN
my $this = shift;
return $this->{'STRING'};
}
# Performance! :(
sub get_fh {
return $_[0]->{'FH'};
}
sub get_record {
my $this = shift;
if ( $this->is_done() ) {
return $this->call_next_record();
}
my $fh = $this->get_fh();
my $line = <$fh>;
if ( ! $line ) {
close $fh;
$this->set_done();
# This is ugly, reaching into the other class
App::RecordStream::Operation::set_current_filename($this->get_filename());
return $this->call_next_record();
}
# Direct bless done in the name of performance
my $record = $json->decode($line);
bless $record, 'App::RecordStream::Record';
return $record;
}
sub call_next_record {
my $this = shift;
my $next = $this->get_next();
unless ( $next ) {
return undef;
}
# Prevent a deep recursion with many passed files
if ( $next && $next->is_done() ) {
$next = $next->get_next();
$this->{'NEXT'} = $next;
}
return $next->get_record();
}
sub get_filename {
my $this = shift;
if ( ! $this->is_done() ) {
return $this->get_file() if ( $this->get_file() );
return 'STRING_INPUT' if ( $this->get_string() );
return 'STREAM_INPUT' if ( $this->get_fh() );
return 'UNKNOWN';
}
elsif ( $this->get_next() ) {
return $this->get_next()->get_filename();
}
}
sub get_next {
my $this = shift;
return $this->{'NEXT'};
}
sub is_done {
return $_[0]->{'DONE'};
}
sub set_done {
my $this = shift;
$this->{'DONE'} = 1;
}
1;
( run in 0.605 second using v1.01-cache-2.11-cpan-39bf76dae61 )