Forks-Super

 view release on metacpan or  search on metacpan

lib/Forks/Super/LazyEval.pm  view on Meta::CPAN

	my $array = $this->array;
	return shift @$array;
    }
    sub UNSHIFT {
	my ($this, @list) = @_;
	my $array = $this->array;
	unshift @$array, @list;
    }
    sub SPLICE {
	my ($this, $offset, $length, @list) = @_;
	$offset ||= 0;
	$length ||= $this->FETCHSIZE - $offset;
	my $array = $this->array;
	return splice @$array, $offset, $length, @list;
    }
    sub array {
	my $this = shift;
	if (!$this->{array}) {
	    $this->{array} = [ $this->{result}->_fetch ];
	}
	$this->{array};
    }
    sub hash {
	my $this = shift;
	if (!$this->{hash}) {
	    $this->{hash} = { $this->{result}->_fetch };
	}
	$this->{hash};
    }
    sub _fetch {
	my $this = shift;
	return $this->{result}->_fetch;
    }
}

{
    package Forks::Super::bg_qx;
    our @ISA = qw(Forks::Super::bg_eval);
    sub TIESCALAR {
	my ($pkg,$command,@other_options) = @_;
	my $result = Forks::Super::LazyEval::bg_qx $command, @other_options;
	my $self = { result => $result };
	bless $self, $pkg;
    }
    sub TIEARRAY {
	my ($pkg,$command,@other_options) = @_;
	my $result = Forks::Super::LazyEval::bg_qx $command, @other_options;
	my $self = { result => $result, is_array => 1 };
	bless $self, $pkg;
    }
    sub TIEHASH {
	my ($pkg,$command,@other_options) = @_;
	my $result = Forks::Super::LazyEval::bg_qx $command, @other_options;
	my $self = { result => $result, is_hash => 1 };
	bless $self, $pkg;
    }
    sub array {
	my $this = shift;
	if (!$this->{array}) {
	    my $eol = quotemeta($/);
	    $this->{array} = [ split m{(?<=$eol)}, $this->{result}->_fetch ];
	}
	$this->{array};
    }
    sub hash {
	my $this = shift;
	if (!$this->{hash}) {
	    my $eol = quotemeta($/);
	    $this->{hash} = { split m{(?<=$eol)}, $this->{result}->_fetch };
	}
	$this->{hash};
    }
}

1;

=head1 NAME

Forks::Super::LazyEval - deferred processing of output from a background proc

=head1 VERSION

0.97

=head1 DESCRIPTION

Implementation of L<Forks::Super::bg_qx|Forks::Super/bg_qx>
and L<Forks::Super::bg_eval|Forks::Super/bg_eval> functions,
and C<Forks::Super::bg_qx> and C<Forks::Super::bg_eval> tied
classes for retrieving results of external commands and
Perl subroutines executed in background processes.

See L<Forks::Super|Forks::Super> for details.

=head1 AUTHOR

Marty O'Brien, E<lt>mob@cpan.orgE<gt>

=head1 LICENSE AND COPYRIGHT

Copyright (c) 2010-2018, Marty O'Brien.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.8 or,
at your option, any later version of Perl 5 you may have available.

See http://dev.perl.org/licenses/ for more information.

=cut



( run in 0.453 second using v1.01-cache-2.11-cpan-71847e10f99 )