From bbc9d71075cae7d564bb9d0285b7b298b0e9e6c7 Mon Sep 17 00:00:00 2001 From: "perlancar (on netbook-zenbook-ux305)" Date: Thu, 11 Jul 2019 08:33:20 +0700 Subject: [dist] Update release note style in Changes --- Changes | 56 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/Changes b/Changes index efc990a..a2c5d9e 100644 --- a/Changes +++ b/Changes @@ -1,16 +1,16 @@ -0.310 2018-10-18 (PERLANCAR) +0.310 2018-10-18 Released-By: PERLANCAR - [Bugfix] envresmulti(): If all statuses are 304, return final status as 304 instead of 200. -0.30 2017-02-03 (PERLANCAR) +0.30 2017-02-03 Released-By: PERLANCAR - EnvResultMulti: Allow add_result() to override status/message keys. -0.29 2016-12-28 (PERLANCAR) +0.29 2016-12-28 Released-By: PERLANCAR - No functional changes. @@ -18,26 +18,26 @@ copy-paste prereq relationship with x_copypaste. -0.28 2016-12-27 (PERLANCAR) +0.28 2016-12-27 Released-By: PERLANCAR - No functional changes. - [dist] Use _SPEC and _COPYPASTE prefixes for dependencies. -0.27 2016-12-26 (PERLANCAR) +0.27 2016-12-26 Released-By: PERLANCAR - Downgrade prereq String::Trim::More from RuntimeRequires to DevelopSuggests, copy-paste routine trim_blank_lines(). -0.26 2016-12-15 (PERLANCAR) +0.26 2016-12-15 Released-By: PERLANCAR - risub: Add method default_dry_run to check default dry-run mode (Rinci 1.1.83). -0.25 2016-11-21 (PERLANCAR) +0.25 2016-11-21 Released-By: PERLANCAR - [doc] Fix typo in Synopsis. @@ -45,7 +45,7 @@ shortcut to instantiate this class. -0.24 2015-09-03 (PERLANCAR) +0.24 2015-09-03 Released-By: PERLANCAR - No functional changes. @@ -54,25 +54,25 @@ requirement. -0.23 2015-09-03 (PERLANCAR) +0.23 2015-09-03 Released-By: PERLANCAR - Assume LANG=C will use the default en_US, this fixes lots of '{en_US ...}' marks on lots of dists using this. -0.22 2015-09-03 (PERLANCAR) +0.22 2015-09-03 Released-By: PERLANCAR - Mark requested language to aid debugging. -0.21 2014-12-11 (PERLANCAR) +0.21 2014-12-11 Released-By: PERLANCAR - No functional changes. - [ux] Add example of using riresmulti() in Synopsis. -0.20 2014-12-10 (PERLANCAR) +0.20 2014-12-10 Released-By: PERLANCAR - No functional changes. @@ -80,12 +80,12 @@ String::Trim::More. -0.19 2014-11-07 (PERLANCAR) +0.19 2014-11-07 Released-By: PERLANCAR - Regard status 304 as success. -0.18 2014-10-29 (PERLANCAR) +0.18 2014-10-29 Released-By: PERLANCAR - [Incompatible change] envresmulti(): change 'response' terminology to 'result' to follow Rinci 1.1.63, so now the method @@ -94,7 +94,7 @@ 'responses'. -0.17 2014-10-28 (PERLANCAR) +0.17 2014-10-28 Released-By: PERLANCAR [INCOMPATIBLE CHANGES] @@ -111,19 +111,19 @@ They all use langprop() under the hood. -0.16 2014-10-28 (PERLANCAR) +0.16 2014-10-28 Released-By: PERLANCAR - Add envresmulti() (Perinci::Object::EnvResultMulti). -0.15 2014-10-20 (PERLANCAR) +0.15 2014-10-20 Released-By: PERLANCAR - No functional changes. - Fix typo in test which caused CT failure reports. -0.14 2014-10-16 (PERLANCAR) +0.14 2014-10-16 Released-By: PERLANCAR - langprop(): Search PROP.alt.lang.xx in addition to PROP.alt.lang.xx_XX. @@ -131,43 +131,43 @@ - Rename module files. -0.13 2014-01-03 (SHARYANTO) +0.13 2014-01-03 Released-By: SHARYANTO - Trim language from locale env (e.g. "en_US.UTF-8" to "en_US") to avoid unnecessary mark. -0.12 2013-12-11 (SHARYANTO) +0.12 2013-12-11 Released-By: SHARYANTO - langprop() now observes LANG/LANGUAGE environment. -0.11 2012-08-29 (SHARYANTO) +0.11 2012-08-29 Released-By: SHARYANTO - function: Add features() and can_dry_run(). -0.10 2012-03-23 (SHARYANTO) +0.10 2012-03-23 Released-By: SHARYANTO - No functional changes. Resolve circular dependency problem with SHARYANTO-Utils by splitting SHARYANTO::String::Util to its own dist. [RT#75987, thanks Slaven] -0.09 2012-03-22 (SHARYANTO) +0.09 2012-03-22 Released-By: SHARYANTO - No functional changes. Try to work around dependency problem (some systems cannot find SHARYANTO::String::Util, new in SHARYANTO-Utils 0.16+). -0.08 2012-03-20 (SHARYANTO) +0.08 2012-03-20 Released-By: SHARYANTO - No functional changes. Fix Perl version dependency ('parent' requires 5.10.1). -0.07 2012-03-15 (SHARYANTO) +0.07 2012-03-15 Released-By: SHARYANTO [FIXES] @@ -179,14 +179,14 @@ - langprop(): rename option 'mark_fallback_text' to 'mark_different_lang'. -0.06 2012-03-15 (SHARYANTO) +0.06 2012-03-15 Released-By: SHARYANTO [ENHANCEMENTS] - Add 'rimeta'. -0.05 2012-03-15 (SHARYANTO) +0.05 2012-03-15 Released-By: SHARYANTO [INCOMPATIBLE CHANGES] @@ -200,7 +200,7 @@ - Add langprop() method. -0.04 2012-01-26 (SHARYANTO) +0.04 2012-01-26 Released-By: SHARYANTO - First release, rename from Sub-Spec-Object to Perinci-Object. Now follows Rinci (currently 1.1) specification instead of Sub::Spec 1.0 -- cgit v1.2.3 From a6d0f4e3fe3fef365ce3682520e3279178cbeb7f Mon Sep 17 00:00:00 2001 From: "perlancar (on netbook-dell-xps13)" Date: Sat, 2 Jan 2021 07:48:19 +0700 Subject: envresmulti: Allow adding payload in add_result() --- lib/Perinci/Object.pm | 6 ++++-- lib/Perinci/Object/EnvResultMulti.pm | 32 +++++++++++++++++++++++++++++++- t/EnvResultMulti.t | 15 +++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/lib/Perinci/Object.pm b/lib/Perinci/Object.pm index 7cd5100..093dc03 100644 --- a/lib/Perinci/Object.pm +++ b/lib/Perinci/Object.pm @@ -2,7 +2,9 @@ package Perinci::Object; +# AUTHORITY # DATE +# DIST # VERSION use 5.010001; @@ -118,8 +120,8 @@ sub riresmeta { my $envres = envresmulti(); # add result for each item - $envres->add_result(200, "OK", {item_id=>1}); - $envres->add_result(202, "OK", {item_id=>2, note=>"blah"}); + $envres->add_result(200, "OK", {item_id=>1, payload=>"a"}); + $envres->add_result(202, "OK", {item_id=>2, note=>"blah", payload=>"b"}); $envres->add_result(404, "Not found", {item_id=>3}); ... diff --git a/lib/Perinci/Object/EnvResultMulti.pm b/lib/Perinci/Object/EnvResultMulti.pm index c29a20a..c1cfaab 100644 --- a/lib/Perinci/Object/EnvResultMulti.pm +++ b/lib/Perinci/Object/EnvResultMulti.pm @@ -1,6 +1,8 @@ package Perinci::Object::EnvResultMulti; +# AUTHORITY # DATE +# DIST # VERSION use 5.010; @@ -18,11 +20,16 @@ sub new { sub add_result { my ($self, $status, $message, $extra) = @_; + $extra //= {}; my $num_ok = 0; my $num_nok = 0; push @{ ${$self}->[3]{results} }, - {status=>$status, message=>$message, %{ $extra // {} }}; + {status=>$status, message=>$message, %$extra}; + if (exists $extra->{payload}) { + ${$self}->[2] //= []; + push @{ ${$self}->[2] }, $extra->{payload}; + } for (@{ ${$self}->[3]{results} // [] }) { if ($_->{status} =~ /\A(2|304)/) { $num_ok++; @@ -89,6 +96,16 @@ sub add_result { # ]}] } # myfunc +To add a payload for each result: + + my $envres = Perinci::Object::EnvResultMulti->new; + $envres->add_result(200, "OK", {item_id=>1, payload=>"a"}); + $envres->add_result(200, "OK", {item_id=>2, payload=>"b"}); + $envres->add_result(200, "OK", {item_id=>3, payload=>"c"}); + + return $envres->as_struct; + # => [200, "All success", ["a","b","c"], ...] + =head1 DESCRIPTION @@ -110,6 +127,19 @@ specified, the default is C<< [200, "Success/no items"] >>. Add an item result. +Extra keys: + +=over + +=item * item_id + +=item * payload + +If you want to add a payload for this result. The final overall payload will be +an array composed from this payload. + +=back + =head1 SEE ALSO diff --git a/t/EnvResultMulti.t b/t/EnvResultMulti.t index eebc815..8d9564f 100644 --- a/t/EnvResultMulti.t +++ b/t/EnvResultMulti.t @@ -24,6 +24,21 @@ subtest "all success" => sub { ], "final results") or diag explain $res; }; +subtest "all success, with payload" => sub { + my $envres = envresmulti; + $envres->add_result(200, "OK", {item_id=>1, payload=>"a"}); + $envres->add_result(202, "OK", {item_id=>2, note=>"blah", payload=>"b"}); + $envres->add_result(304, "Not modified", {item_id=>3}); + my $res = $envres->as_struct; + is($res->[0], 200, "final status"); + is_deeply($res->[2], ["a","b"], "final payload"); + is_deeply($res->[3]{results}, [ + {status=>200, message=>"OK", item_id=>1, payload=>"a"}, + {status=>202, message=>"OK", item_id=>2, note=>"blah", payload=>"b"}, + {status=>304, message=>"Not modified", item_id=>3}, + ], "final results") or diag explain $res; +}; + subtest "partial success (success first)" => sub { my $envres = envresmulti; my $res; -- cgit v1.2.3 From 2f6e01f4815655b4a005d38dd24c0520cddf0172 Mon Sep 17 00:00:00 2001 From: "perlancar (on netbook-dell-xps13)" Date: Sat, 2 Jan 2021 07:48:57 +0700 Subject: Release v0.311 --- Changes | 5 +++++ dist.ini | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index a2c5d9e..3910181 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,8 @@ +0.311 2021-01-02 Released-By: PERLANCAR; Urgency: medium + + - envresmulti: Allow adding payload in add_result(). + + 0.310 2018-10-18 Released-By: PERLANCAR - [Bugfix] envresmulti(): If all statuses are 304, return final diff --git a/dist.ini b/dist.ini index 22e8b9d..180cad1 100644 --- a/dist.ini +++ b/dist.ini @@ -1,4 +1,4 @@ -version=0.310 +version=0.311 name=Perinci-Object @@ -19,9 +19,10 @@ Exporter=5.57 [Prereqs / DevelopX_spec] -phase=develop -relationship=x_spec -Rinci=1.1.83 +Rinci=1.1.94 [Prereqs / DevelopX_copypaste] -phase=develop -relationship=x_copypaste String::Trim::More=0.02 + -- cgit v1.2.3