Skip to content

Commit edd44b9

Browse files
committed
2.1.2 - fix pagination when paginator result key is a compound key
1 parent ccbeb57 commit edd44b9

6 files changed

Lines changed: 119 additions & 23 deletions

File tree

ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
Wed Feb 12 09:17:23 2025 Rob Lauer <rlauer6@comcast.net>
2+
3+
[2.1.2]:
4+
* NEWS.md: updated
5+
* VERSION: bump
6+
* src/main/perl/lib/Amazon/API.pm.in
7+
(invoke_api): fix pagination for compound keys
8+
(dig): new
9+
(bury): new
10+
111
Thu Dec 5 05:46:10 2024 Rob Lauer <rlauer6@comcast.net>
212

313
[2.1.1]:

NEWS.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,21 @@ as well as a running list of changes from previous versions. If
66
critical bugs are found in any of the software, notice of such bugs
77
and the versions in which they were fixed will be noted here, as well.
88

9-
# perl-Amazon-API 2.1.0 (2024-12-03)
9+
# perl-Amazon-API 2.1.2 (2025-02-12)
1010

11-
_Version 2.1.0 is a minor update to which fixes a few small bugs and
12-
updates the documetation. More importantly, this is the first release
13-
that I would consider production ready._
11+
_Version 2.1.2 is a minor update to which fixes a bug in the way
12+
pagination is implemented. Some paginators need to use a compound key
13+
to find the paged result set in the returned results element. For
14+
example, the CloudFront ListDistributions API uses
15+
'DistributionList.Items' as the result key...
1416

1517
## Fixes
1618

17-
* initialize log level to error
18-
* fix bug when invoking API directly (not using botocore)
19+
* fix paginatiors that use a compound key
1920

2021
## Enhancements
2122

22-
* perltidy'ing of Botocore generated classes is now disabled by
23-
default to make creating classes a little faster. See
24-
[cpan-dist/README.md](cpan-dist/README.md).
25-
* documentation cleanups and better more detailed explanations overall
23+
None
2624

2725
# perl-Amazon-API 2.1.1 (2024-12-05)
2826

@@ -40,6 +38,24 @@ was being generated.
4038
[cpan-dist/README.md](cpan-dist/README.md).
4139
* documentation cleanups and better more detailed explanations overall
4240

41+
# perl-Amazon-API 2.1.0 (2024-12-03)
42+
43+
_Version 2.1.0 is a minor update to which fixes a few small bugs and
44+
updates the documetation. More importantly, this is the first release
45+
that I would consider production ready._
46+
47+
## Fixes
48+
49+
* initialize log level to error
50+
* fix bug when invoking API directly (not using botocore)
51+
52+
## Enhancements
53+
54+
* perltidy'ing of Botocore generated classes is now disabled by
55+
default to make creating classes a little faster. See
56+
[cpan-dist/README.md](cpan-dist/README.md).
57+
* documentation cleanups and better more detailed explanations overall
58+
4359
# perl-Amazon-API 2.0.15 (2024-11-19)
4460

4561
_Version 2.0.15 is a minor update to which fixes a few small bugs_

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ by passing the `content_type` option to the constructor.
947947

948948
# VERSION
949949

950-
This documentation refers to version 2.1.1 of `Amazon::API`.
950+
This documentation refers to version 2.1.2 of `Amazon::API`.
951951

952952
# DIAGNOSTICS
953953

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.1
1+
2.1.2

src/main/perl/lib/Amazon/API.pm.in

Lines changed: 80 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,16 +1271,29 @@ sub invoke_api {
12711271
if ($use_paginator) {
12721272
my $result = $self->decode_response;
12731273

1274+
DEBUG(
1275+
sub {
1276+
return Dumper(
1277+
[ paginator => $paginator,
1278+
paged_results => @paged_results,
1279+
result => $result
1280+
]
1281+
);
1282+
}
1283+
);
1284+
1285+
my $actual_result = dig( $result, $paginator, 'result_key' );
1286+
12741287
return \@paged_results
1275-
if !$result->{ $paginator->{result_key} };
1288+
if !$actual_result;
12761289

12771290
DEBUG(
12781291
sub {
12791292
return Dumper( [ result => $result, ] );
12801293
}
12811294
);
12821295

1283-
push @paged_results, @{ $result->{ $paginator->{result_key} } };
1296+
push @paged_results, @{$actual_result};
12841297

12851298
DEBUG(
12861299
sub {
@@ -1293,9 +1306,8 @@ sub invoke_api {
12931306
}
12941307
);
12951308

1296-
if ( !$result->{ $paginator->{more_results} } ) {
1297-
delete $result->{ $paginator->{more_results} };
1298-
1309+
if ( !dig( $result, $paginator, 'more_results' ) ) {
1310+
# might have to dig here too, but generally I don't think so
12991311
if ( $paginator->{limit_key} ) {
13001312
delete $result->{ $paginator->{limit_key} };
13011313
}
@@ -1327,9 +1339,8 @@ sub invoke_api {
13271339
}
13281340
}
13291341

1330-
if ($use_paginator) {
1331-
return { $paginator->{result_key} => \@paged_results };
1332-
}
1342+
return bury( \@paged_results, $paginator, 'result_key' )
1343+
if $use_paginator;
13331344

13341345
my $results = $self->decode_response;
13351346

@@ -1343,15 +1354,74 @@ sub invoke_api {
13431354
# 'use_paginator' is tested above and if it is false (you told me not to use the
13441355
# paginator) we return the results...
13451356

1346-
if ( !$results->{ $paginator->{more_results} } ) {
1347-
delete $results->{ $paginator->{more_results} };
1357+
if ( !dig( $results, $paginator, 'more_results' ) ) {
13481358
delete $results->{ $paginator->{input_token} };
13491359
delete $results->{ $paginator->{limit_key} };
13501360
}
13511361

13521362
return $results;
13531363
}
13541364

1365+
########################################################################
1366+
# the analog to dig, we need to set the result to a hash element specified
1367+
# by a dot encoded string. Example: DistributionList.Item
1368+
########################################################################
1369+
sub bury {
1370+
########################################################################
1371+
my ( $result, $paginator, $key ) = @_;
1372+
1373+
return $result
1374+
if !$paginator;
1375+
1376+
$key = $paginator->{$key};
1377+
1378+
return { $key => $result }
1379+
if $key !~ /[.]/xsm;
1380+
1381+
my $parent = {};
1382+
my $child = $parent;
1383+
1384+
my @keys = split /[.]/xsm, $key;
1385+
my $result_key = pop @keys; # remove last element
1386+
1387+
foreach (@keys) {
1388+
$child->{$_} = {};
1389+
$child = $child->{$_};
1390+
}
1391+
1392+
$child->{$result_key} = $result;
1393+
1394+
return $parent;
1395+
}
1396+
1397+
########################################################################
1398+
# follow the . encoded key to find the hash element
1399+
# example: DistributionList.Items
1400+
########################################################################
1401+
sub dig {
1402+
########################################################################
1403+
my ( $result, $paginator, $key, $delete ) = @_;
1404+
1405+
return $result
1406+
if !$paginator || !$paginator->{$key};
1407+
1408+
$key = $paginator->{$key};
1409+
1410+
return $result->{$key}
1411+
if $key !~ /[.]/xsm;
1412+
1413+
foreach ( split /[.]/xsm, $key ) {
1414+
$result = $result->{$_};
1415+
$key = $_;
1416+
}
1417+
1418+
if ($delete) {
1419+
delete $result->{$key};
1420+
}
1421+
1422+
return $result;
1423+
}
1424+
13551425
########################################################################
13561426
sub print_error {
13571427
########################################################################

src/main/perl/lib/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ by passing the `content_type` option to the constructor.
947947

948948
# VERSION
949949

950-
This documentation refers to version 2.1.1 of `Amazon::API`.
950+
This documentation refers to version 2.1.2 of `Amazon::API`.
951951

952952
# DIAGNOSTICS
953953

0 commit comments

Comments
 (0)