AWS-S3
view release on metacpan or search on metacpan
lib/AWS/S3/FileIterator.pm view on Meta::CPAN
# - fetch 100 items
# - store them
# - iterate internally until we get to 'page 2'
# - return the result.
# If the page size is 105 and page number is 1, then we:
# - fetch 100 items
# - fetch the next 100 items
# - return the first 105 items, keeping the remaining 95 items
# - on page '2', fetch the next 100 items and return 105 items, saving 90 items.
# If the page size is 105 and page number is 3, then we:
# - fetch items until our internal 'start' marker is 316-420
# - return items 316-420
sub next_page {
my $s = shift;
# Advance to page X before proceding:
if ( ( !$s->{__fetched_first_page}++ ) && $s->page_number ) {
# Advance to $s->page_number
my $start_page = $s->page_number;
my $to_discard = $start_page * $s->page_size;
my $discarded = 0;
while ( 1 ) {
my $item = $s->_next
or last;
$discarded++ if $item->{key} =~ $s->pattern;
last if $discarded > $to_discard;
} # end while()
} # end if()
my @chunk = ();
t/010_basic.t view on Meta::CPAN
while( my @files = $iter->next_page )
{
foreach my $file ( @files )
{
is ${$file->contents}, $info{$file->key}, "file(@{[$file->key]}).contents works on iterated files";
last if $counted++ > 4;
}# end foreach()
last;
}# end while()
# Make sure that if we say we want to start on page 11, we *start* on page 11:
$iter = $bucket->files( page_size => 1, page_number => 18 );
SMALL_ITER: {
for( 18..25 )
{
my ($file) = $iter->next_page;
my $number = sprintf('%03d', $_);
is $file->key, "bar/baz/foo.$number.txt", "file $number is what we expected";
}# end for()
};
t/aws/s3/file_iterator.t view on Meta::CPAN
page_size => 1,
bucket => $bucket,
pattern => qr/\d+/,
);
my $number_of_request;
my $xml = get_data_section('LongResult');
my $mocked_response = Mocked::HTTP::Response->new( 200,$xml );
local *LWP::UserAgent::Determined::request = sub { $number_of_request++; return $mocked_response };
is( $iterator->next_page->[0]->key,5,'start at file 5' );
is( $iterator->next_page->[0]->key,6,'... file 6' );
is( $iterator->next_page->[0]->key,7,'... file 7' );
is( $iterator->next_page->[0]->key,8,'... file 8' );
is( $iterator->next_page->[0]->key,9,'... file 9' );
is( $iterator->next_page->[0]->key,0,'do a new request and get file 0' );
is( $number_of_request,2,'did two requests' );
};
done_testing();
( run in 0.313 second using v1.01-cache-2.11-cpan-0d8aa00de5b )