| 1 | # -*- perl -*- | ||
| 2 | |||
| 3 | # Copyright (c) 2010 AdCopy | ||
| 4 | # Author: Jeff Weisberg | ||
| 5 | # Created: 2010-Jan-14 12:46 (EST) | ||
| 6 | # Function: iterate over a file | ||
| 7 | # | ||
| 8 | # $Id: File.pm,v 1.1 2010/11/01 18:41:55 jaw Exp $ | ||
| 9 | |||
| 10 | package AC::MrGamoo::Iter::File; | ||
| 11 | use AC::MrGamoo::Iter; | ||
| 12 | use JSON; | ||
| 13 | our @ISA = 'AC::MrGamoo::Iter'; | ||
| 14 | use strict; | ||
| 15 | |||
| 16 | sub new { | ||
| 17 | my $class = shift; | ||
| 18 | my $fd = shift; | ||
| 19 | my $pf = shift; | ||
| 20 | |||
| 21 | return bless { | ||
| 22 | fd => $fd, | ||
| 23 | progress => $pf, | ||
| 24 | }, $class; | ||
| 25 | } | ||
| 26 | |||
| 27 | sub _nextrow { | ||
| 28 | my $me = shift; | ||
| 29 | |||
| 30 | if( $me->{buf} ){ | ||
| 31 | my $r = $me->{buf}; | ||
| 32 | delete $me->{buf}; | ||
| 33 | return $r; | ||
| 34 | } | ||
| 35 | |||
| 36 | my $fd = $me->{fd}; | ||
| 37 | my $l = scalar <$fd>; | ||
| 38 | return unless $l; | ||
| 39 | $me->{progress}->(); | ||
| 40 | return decode_json($l); | ||
| 41 | } | ||
| 42 | |||
| 43 | |||
| 44 | 1; |