#pseudo code # error handling omitted! sub parser_factory { my $file_path = shift; my %options = @_; fh = open_file($file_path) my $iterator = sub { # closure ; flag end of data/closing file omitted while( header = read(fh)) { length = get_length(header) body = read(fh,length) type = get_type(header) class =get_record_class(header) # return class name return class->new(body); } } return $iterator }