URI-Query-0.16/0000775000175000017500000000000012752505565012212 5ustar gavingavinURI-Query-0.16/TODO0000644000175000017500000000006712752505565012703 0ustar gavingavin- add a value() method to query a particular arg value URI-Query-0.16/README0000644000175000017500000000057012752505565013072 0ustar gavingavin This archive contains the distribution URI-Query, version 0.16: class providing URI query string manipulation This software is copyright (c) 2016 by Gavin Carr. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. This README file was generated by Dist::Zilla::Plugin::Readme v5.020. URI-Query-0.16/LICENSE0000644000175000017500000004364712752505565013233 0ustar gavingavinThis software is copyright (c) 2016 by Gavin Carr. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2016 by Gavin Carr. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2016 by Gavin Carr. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End URI-Query-0.16/dist.ini0000644000175000017500000000050212752505565013651 0ustar gavingavinname = URI-Query version = 0.16 author = Gavin Carr copyright_holder = Gavin Carr license = Perl_5 [@Basic] [AutoPrereqs] [Prereqs / TestRequires] Test::More = 0.88 ; for done_testing [PodSyntaxTests] [PodCoverageTests] [Test::Perl::Critic] [TestRelease] [ConfirmRelease] [UploadToCPAN] URI-Query-0.16/META.yml0000644000175000017500000000106212752505565013460 0ustar gavingavin--- abstract: 'class providing URI query string manipulation' author: - 'Gavin Carr ' build_requires: Test::More: 0.88 YAML: 0 warnings: 0 configure_requires: ExtUtils::MakeMaker: 0 dynamic_config: 0 generated_by: 'Dist::Zilla version 5.020, CPAN::Meta::Converter version 2.150001' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: URI-Query requires: Carp: 0 Clone: 0 URI::Escape: 0 overload: 0 parent: 0 perl: 5.00503 strict: 0 vars: 0 version: 0.16 URI-Query-0.16/MANIFEST0000644000175000017500000000067312752505565013347 0ustar gavingavin# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.020. ChangeLog LICENSE MANIFEST META.yml Makefile.PL README TODO dist.ini lib/URI/Query.pm t/01_constructor.t t/02_methods.t t/03_hash.t t/04_revert.t t/05_sep.t t/06_eq.t t/07_unesc.t t/08_changed.t t/08_clone.t t/author-critic.t t/release-pod-coverage.t t/release-pod-syntax.t t/t03/hash t/t03/hash_arrayref t/t03/hidden t/t05/default t/t05/explicit t/t05/standard URI-Query-0.16/ChangeLog0000644000175000017500000000230412752505565013761 0ustar gavingavinChangeLog --------- [2016-08-10] * Bump $VERSION to 0.16. * Add clone method via Clone. * Add trivial qstringify method stringify with leading '?'. [2015-11-18] * Convert to Dist::Zilla. [2015-11-03] * Bump $VERSION to 0.15; add Carp to prereqs. * Add strip_like method and unit tests. * Add changed attribute and has_changed() method and unit test. [2012-09-10] * Bump $VERSION to 0.10. * Remove value-based reordering in stringification. [2011-01-27] * Bump version to 0.09. * Change t/t05/default from symlink to dup, to avoid problems on windows etc. * Add ChangeLog to .gitignore. [2011-01-21] * Fix typo in URI::Query pod. * MANIFEST tweakage. * Add lots of nice pod. * Add support for cgi-packed-scalar-values, update unit tests. * Perldoc updates, and trailing whitespace pruning. * Add .gitignore; bump Test::More requirement to 0.88. * Add _init_from_arrayref method to Query, and unescape keys/values. * Add unescaping of keys and values in parse_qs, and unit test. * Remove all old arch-tags. [2010-01-20] * Upgrade use of uri_escape to uri_escape_utf8; bump version to 0.07. [2007-09-11] * Sort output hash key order for deterministic testing; bump to version 0.06. * Initial import, version 0.05. URI-Query-0.16/t/0000775000175000017500000000000012752505565012455 5ustar gavingavinURI-Query-0.16/t/06_eq.t0000644000175000017500000000111512752505565013550 0ustar gavingavin# Test 'eq' overloading use Test::More tests => 10; BEGIN { use_ok( URI::Query ) } use strict; my ($qq1, $qq2); ok($qq1 = URI::Query->new('foo=1&foo=2&bar=3'), 'qq1 constructor ok'); ok($qq2 = URI::Query->new('foo=1&bar=3&foo=2'), 'qq2 constructor ok'); is($qq1, $qq2, 'eq ok'); ok($qq2 = URI::Query->new('bar=3&foo=1&foo=2'), 'qq2 constructor ok'); is($qq1, $qq2, 'eq ok'); ok($qq2 = URI::Query->new('bar=3&foo=2&foo=1'), 'qq2 constructor ok'); isnt($qq1, $qq2, 'ne ok (value ordering preserved)'); ok($qq2 = URI::Query->new('bar=3'), 'qq2 constructor ok'); isnt($qq1, $qq2, 'ne ok'); URI-Query-0.16/t/05_sep.t0000644000175000017500000000253612752505565013741 0ustar gavingavin# Test separator handling use strict; use vars q($count); BEGIN { $count = 6 } use Test::More tests => $count; use_ok('URI::Query'); my ($qq, $out); # Load result strings my $test = 't05'; my %result = (); $test = "t/$test" if -d "t/$test"; die "missing data dir $test" unless -d $test; { opendir my $dir, "$test" or die "can't open $test"; for (readdir $dir) { next if m/^\./; open my $file, "<$test/$_" or die "can't read $test/$_"; { local $/ = undef; $result{$_} = <$file>; } chomp $result{$_}; } } my $print = shift @ARGV || 0; my $t = 3; sub report { my ($data, $file, $inc) = @_; $inc ||= 1; if ($print == $t) { print STDERR "--> $file\n"; print $data; exit 0; } $t += $inc; } ok($qq = URI::Query->new('foo=1&foo=2&bar=3;bog=abc;bar=7;fluffy=3'), "constructor ok"); $out = $qq->stringify; report $out, "standard"; is($out, $result{standard}, "standard stringify ok"); # Stringify with an explicit separator $out = $qq->stringify(';'); report $out, "explicit"; is($out, $result{explicit}, "explicit separator ok"); # Recheck standard in place $out = $qq->stringify; report $out, "standard"; is($out, $result{standard}, "standard stringify ok"); # Set default separator $qq->separator(';'); $out = $qq->stringify; report $out, "default"; is($out, $result{default}, "setting default separator ok"); URI-Query-0.16/t/t03/0000775000175000017500000000000012752505565013063 5ustar gavingavinURI-Query-0.16/t/t03/hash0000644000175000017500000000007112752505565013725 0ustar gavingavin--- bar: - 3 - 7 bog: abc fluffy: 3 foo: - 1 - 2 URI-Query-0.16/t/t03/hidden0000644000175000017500000000042312752505565014236 0ustar gavingavin URI-Query-0.16/t/t03/hash_arrayref0000644000175000017500000000010112752505565015612 0ustar gavingavin--- bar: - 3 - 7 bog: - abc fluffy: - 3 foo: - 1 - 2 URI-Query-0.16/t/03_hash.t0000644000175000017500000000260512752505565014070 0ustar gavingavin# URI::Query hash methods use strict; use vars q($count); BEGIN { $count = 5 } use Test::More tests => $count; use_ok('URI::Query'); my ($qq, $out); # Load result strings my $test = 't03'; my %result = (); $test = "t/$test" if -d "t/$test"; die "missing data dir $test" unless -d $test; { opendir my $dir, "$test" or die "can't open $test"; for (readdir $dir) { next if m/^\./; open my $file, "<$test/$_" or die "can't read $test/$_"; local $/ = undef; $result{$_} = <$file>; } } my $print = shift @ARGV || 0; my $t = 3; sub report { my ($data, $file, $inc) = @_; $inc ||= 1; if ($print == $t) { print STDERR "--> $file\n"; print $data; exit 0; } $t += $inc; } ok($qq = URI::Query->new('foo=1&foo=2&bar=3;bog=abc;bar=7;fluffy=3'), "constructor ok"); SKIP: { my $yaml = eval { require YAML }; skip "YAML not found", 2 unless $yaml; # Require YAML 0.39 on Windows (reported by Andy Grundman) if ($^O =~ m/^MSWin/i && ! defined eval { YAML->VERSION(0.39) }) { skip "YAML >= 0.39 required on windows", 2; } $out = YAML::Dump(scalar($qq->hash)); report $out, "hash"; is($out, $result{hash}, 'hash ok'); $out = YAML::Dump(scalar($qq->hash_arrayref)); report $out, "hash_arrayref"; is($out, $result{hash_arrayref}, 'hash_arrayref ok'); } $out = $qq->hidden; report $out, "hidden"; is($out, $result{hidden}, 'hidden ok'); URI-Query-0.16/t/07_unesc.t0000644000175000017500000000222312752505565014262 0ustar gavingavin# Test input unescaping # # Fixing bug #35170: https://rt.cpan.org/Public/Bug/Display.html?id=35170 # # RFC2396: Within a query component, the characters ";", "/", "?", # ":", "@", "&", "=", "+", ",", and "$" are reserved. # use strict; use Test::More; BEGIN { use_ok( 'URI::Query' ) } my $data_esc = { group => 'prod%2Cinfra%2Ctest', 'op%3Aset' => 'x%3Dy', }; my $data_unesc = { group => 'prod,infra,test', 'op:set' => 'x=y', }; my $qs_esc = 'group=prod%2Cinfra%2Ctest&op%3Aset=x%3Dy'; my ($qq, $qs); ok($qq = URI::Query->new($qs_esc), 'qq string constructor ok'); is_deeply(scalar $qq->hash, $data_unesc, '$qq->hash keys and values are unescaped'); is("$qq", $qs_esc, 'stringified keys/values escaped ok'); ok($qq = URI::Query->new($data_esc), 'qq hashref constructor ok'); is_deeply(scalar $qq->hash, $data_unesc, '$qq->hash keys and values are unescaped'); is("$qq", $qs_esc, 'stringified keys/values escaped ok'); ok($qq = URI::Query->new(%$data_esc), 'qq hash constructor ok'); is_deeply(scalar $qq->hash, $data_unesc, '$qq->hash keys and values are unescaped'); is("$qq", $qs_esc, 'stringified keys/values escaped ok'); done_testing; URI-Query-0.16/t/08_clone.t0000644000175000017500000000127612752505565014255 0ustar gavingavin# Test URI::Query clone() use strict; use vars q($count); use Test::More; use_ok('URI::Query'); my $qq; ok($qq = URI::Query->new('foo=1&foo=2&bar=3;bog=abc;bar=7;fluffy=3'), "constructor ok"); my $str1 = $qq->stringify; my $qstr = $qq->qstringify; is($qstr, "?$str1", "qstringify ok: $qstr"); # Basic clone test is($qq->clone->stringify, $str1, 'unchanged clone stringifies identically'); # Clone and make a change isnt($qq->clone->strip('fluffy')->stringify, $qq->stringify, 'changed clone stringifies differently'); # Identical changes stringify identically is($qq->clone->strip('fluffy')->qstringify, $qq->strip('fluffy')->qstringify, 'same changes qstringify identically'); done_testing; URI-Query-0.16/t/04_revert.t0000644000175000017500000000074312752505565014456 0ustar gavingavin# Test URI::Query revert() use strict; use vars q($count); BEGIN { $count = 4 } use Test::More tests => $count; use_ok('URI::Query'); my $qq; ok($qq = URI::Query->new('foo=1&foo=2&bar=3;bog=abc;bar=7;fluffy=3'), "constructor ok"); my $str1 = $qq->stringify; # Strip $qq->strip(qw(foo fluffy)); my $str2 = $qq->stringify; isnt($str1, $str2, "strings different after strip"); # Revert $qq->revert; my $str3 = $qq->stringify; is($str1, $str3, "strings identical after revert"); URI-Query-0.16/t/t05/0000775000175000017500000000000012752505565013065 5ustar gavingavinURI-Query-0.16/t/t05/default0000644000175000017500000000005112752505565014426 0ustar gavingavinbar=3;bar=7;bog=abc;fluffy=3;foo=1;foo=2 URI-Query-0.16/t/t05/explicit0000644000175000017500000000005112752505565014623 0ustar gavingavinbar=3;bar=7;bog=abc;fluffy=3;foo=1;foo=2 URI-Query-0.16/t/t05/standard0000644000175000017500000000005112752505565014602 0ustar gavingavinbar=3&bar=7&bog=abc&fluffy=3&foo=1&foo=2 URI-Query-0.16/t/08_changed.t0000644000175000017500000000211312752505565014535 0ustar gavingavin# Test URI::Query has_changed() use strict; use vars q($count); BEGIN { $count = 11 } use Test::More tests => $count; use_ok('URI::Query'); my $qq; ok($qq = URI::Query->new('foo=1&foo=2&bar=3;bog=;bar=7;fluffy=3'), "constructor ok"); ok(! $qq->has_changed, 'has_changed is false after constructor'); # strip $qq->strip(qw(bogus)); ok(! $qq->has_changed, 'has_changed is false after strip on missing variable'); $qq->strip(qw(foo fluffy)); ok($qq->has_changed > 0, 'has_changed is true after strip'); # revert $qq->revert; ok(! $qq->has_changed, 'has_changed is false after revert'); # strip except $qq->strip_except(qw(foo bar bog bar fluffy)); ok(! $qq->has_changed, 'has_changed is false after strip_except on all variables'); $qq->strip_except(qw(foo)); ok($qq->has_changed > 0, 'has_changed is true after strip_except'); # revert $qq->revert; ok(! $qq->has_changed, 'has_changed is false after revert'); # strip_null $qq->strip_null; ok($qq->has_changed > 0, 'has_changed is true after strip_null'); # revert $qq->revert; ok(! $qq->has_changed, 'has_changed is false after revert'); URI-Query-0.16/t/02_methods.t0000644000175000017500000000417412752505565014612 0ustar gavingavin# URI::Query tests use Test::More tests => 22; BEGIN { use_ok( URI::Query ) } use strict; my $qq; # Basics - scalar version ok($qq = URI::Query->new('foo=1&foo=2&bar=3;bog=abc;bar=7;fluffy=3'), "constructor ok"); is($qq->stringify, 'bar=3&bar=7&bog=abc&fluffy=3&foo=1&foo=2', sprintf("stringifies ok (%s)", $qq->stringify)); # strip ok($qq->strip(qw(foo bog)), "strip ok"); is($qq->stringify, 'bar=3&bar=7&fluffy=3', sprintf("strip correct (%s)", $qq->stringify)); # Simple replace $qq = URI::Query->new('foo=1&foo=2&bar=3;bog=abc;bar=7;fluffy=3'); ok($qq->replace(foo => 'xyz', bog => 'magic', extra => 1), "replace ok"); is($qq->stringify, 'bar=3&bar=7&bog=magic&extra=1&fluffy=3&foo=xyz', sprintf("replace correct (%s)", $qq->stringify)); # Composite replace ok($qq->replace(foo => [ 123, 456, 789 ], extra => 2), "replace ok"); is($qq->stringify, 'bar=3&bar=7&bog=magic&extra=2&fluffy=3&foo=123&foo=456&foo=789', sprintf("replace correct (%s)", $qq->stringify)); # Auto-stringification is("$qq", 'bar=3&bar=7&bog=magic&extra=2&fluffy=3&foo=123&foo=456&foo=789', sprintf("auto-stringification ok (%s)", $qq . '')); # strip_except ok($qq->strip_except(qw(bar foo extra)), "strip_except ok"); is($qq->stringify, 'bar=3&bar=7&extra=2&foo=123&foo=456&foo=789', sprintf("strip_except correct (%s)", $qq->stringify)); # strip_null ok($qq = URI::Query->new(foo => 1, foo => 2, bar => '', bog => 'abc', zero => 0, fluffy => undef), "array constructor ok"); ok($qq->strip_null, "strip_null ok"); is($qq->stringify, 'bog=abc&foo=1&foo=2&zero=0', sprintf("strip_null correct (%s)", $qq->stringify)); # strip_like ok($qq = URI::Query->new('foo=1&foo=2&bar=3;bog=abc;bar=7;fluffy=3;zero=0'), "constructor ok"); ok($qq->strip_like(qr/^b/), "strip_like ok"); is($qq->stringify, 'fluffy=3&foo=1&foo=2&zero=0', sprintf("strip_like correct (%s)", $qq->stringify)); ok($qq->strip_like(qr/^f[lzx]/), "strip_like ok"); is($qq->stringify, 'foo=1&foo=2&zero=0', sprintf("strip_like correct (%s)", $qq->stringify)); ok($qq->strip_like(qr/\d/), "strip_like ok"); is($qq->stringify, 'foo=1&foo=2&zero=0', sprintf("strip_like correct (%s)", $qq->stringify)); URI-Query-0.16/t/author-critic.t0000644000175000017500000000066612752505565015425 0ustar gavingavin#!perl BEGIN { unless ($ENV{AUTHOR_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for testing by the author'); } } use strict; use warnings; use Test::More; use English qw(-no_match_vars); eval "use Test::Perl::Critic"; plan skip_all => 'Test::Perl::Critic required to criticise code' if $@; Test::Perl::Critic->import( -profile => "perlcritic.rc" ) if -e "perlcritic.rc"; all_critic_ok(); URI-Query-0.16/t/01_constructor.t0000644000175000017500000000277512752505565015540 0ustar gavingavin# Basic URI::Query tests use Test::More; use_ok(URI::Query); use strict; my $qq; # Constructor - scalar version ok($qq = URI::Query->new('foo=1&foo=2&bar=3;bog=abc;bar=7;fluffy=3'), "scalar constructor ok"); is($qq->stringify, 'bar=3&bar=7&bog=abc&fluffy=3&foo=1&foo=2', sprintf("stringifies ok (%s)", $qq->stringify)); # Constructor - array version ok($qq = URI::Query->new(foo => 1, foo => 2, bar => 3, bog => 'abc', bar => 7, fluffy => 3), "array constructor ok"); is($qq->stringify, 'bar=3&bar=7&bog=abc&fluffy=3&foo=1&foo=2', sprintf("stringifies ok (%s)", $qq->stringify)); # Constructor - hashref version ok($qq = URI::Query->new({ foo => [ 1, 2 ], bar => [ 3, 7 ], bog => 'abc', fluffy => 3 }), "hashref constructor ok"); is($qq->stringify, 'bar=3&bar=7&bog=abc&fluffy=3&foo=1&foo=2', sprintf("stringifies ok (%s)", $qq->stringify)); # Constructor - CGI.pm-style hashref version, packed values ok($qq = URI::Query->new({ foo => "1\0002", bar => "3\0007", bog => 'abc', fluffy => 3 }), "cgi-style hashref constructor ok"); is($qq->stringify, 'bar=3&bar=7&bog=abc&fluffy=3&foo=1&foo=2', sprintf("stringifies ok (%s)", $qq->stringify)); # Bad constructor args { no warnings qw(once); for my $bad ((undef, '', \"foo", [ foo => 1 ], \*bad)) { my $b2 = $bad; $b2 = '[undef]' unless defined $bad; $qq = URI::Query->new($bad); ok(ref $qq eq 'URI::Query', "bad '$b2' constructor ok"); is($qq->stringify, '', sprintf("stringifies ok (%s)", $qq->stringify)); } } done_testing; URI-Query-0.16/t/release-pod-syntax.t0000644000175000017500000000045612752505565016371 0ustar gavingavin#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use Test::More; use Test::Pod 1.41; all_pod_files_ok(); URI-Query-0.16/t/release-pod-coverage.t0000644000175000017500000000057212752505565016635 0ustar gavingavin#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests. use Test::Pod::Coverage 1.08; use Pod::Coverage::TrustPod; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); URI-Query-0.16/Makefile.PL0000644000175000017500000000247012752505565014165 0ustar gavingavin # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.020. use strict; use warnings; use 5.005030; use ExtUtils::MakeMaker ; my %WriteMakefileArgs = ( "ABSTRACT" => "class providing URI query string manipulation", "AUTHOR" => "Gavin Carr ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "URI-Query", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "URI::Query", "PREREQ_PM" => { "Carp" => 0, "Clone" => 0, "URI::Escape" => 0, "overload" => 0, "parent" => 0, "strict" => 0, "vars" => 0 }, "TEST_REQUIRES" => { "Test::More" => "0.88", "YAML" => 0, "warnings" => 0 }, "VERSION" => "0.16", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "Clone" => 0, "Test::More" => "0.88", "URI::Escape" => 0, "YAML" => 0, "overload" => 0, "parent" => 0, "strict" => 0, "vars" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); URI-Query-0.16/lib/0000775000175000017500000000000012752505565012760 5ustar gavingavinURI-Query-0.16/lib/URI/0000775000175000017500000000000012752505565013417 5ustar gavingavinURI-Query-0.16/lib/URI/Query.pm0000644000175000017500000003427112752505565015067 0ustar gavingavin# # Class providing URI query string manipulation # package URI::Query; use 5.00503; use strict; use parent 'Clone'; use URI::Escape qw(uri_escape_utf8 uri_unescape); use Carp; use overload '""' => \&stringify, 'eq' => sub { $_[0]->stringify eq $_[1]->stringify }, 'ne' => sub { $_[0]->stringify ne $_[1]->stringify }; use vars q($VERSION); $VERSION = '0.16'; # ------------------------------------------------------------------------- # Remove all occurrences of the given parameters sub strip { my $self = shift; foreach (@_) { delete $self->{qq}->{$_} and $self->{changed}++; } $self; } # Remove all parameters except those given sub strip_except { my $self = shift; my %keep = map { $_ => 1 } @_; foreach (keys %{$self->{qq}}) { next if $keep{$_}; delete $self->{qq}->{$_} and $self->{changed}++; } $self; } # Remove all empty/undefined parameters sub strip_null { my $self = shift; foreach (keys %{$self->{qq}}) { next if @{$self->{qq}->{$_}}; delete $self->{qq}->{$_} and $self->{changed}++; } $self; } # Remove all parameters matching $re sub strip_like { my $self = shift; my $re = shift or croak "Missing regex param to strip_like"; croak "Invalid param '$re' to strip_like - must be regex" if ! ref $re || ref $re ne 'Regexp'; croak "Too many params to strip_like - only one permitted" if @_; foreach (keys %{$self->{qq}}) { next if $_ !~ $re; delete $self->{qq}->{$_} and $self->{changed}++; } $self; } # Replace all occurrences of the given parameters sub replace { my $self = shift; my %arg = @_; for my $key (keys %arg) { $self->{qq}->{$key} = []; if (ref $arg{$key} eq 'ARRAY') { push @{$self->{qq}->{$key}}, $_ foreach @{$arg{$key}}; } else { push @{$self->{qq}->{$key}}, $arg{$key}; } $self->{changed}++; } $self; } # Return the stringified qq hash sub stringify { my $self = shift; my $sep = shift || $self->{sep} || '&'; my @out = (); for my $key (sort keys %{$self->{qq}}) { for my $value (@{$self->{qq}->{$key}}) { push @out, sprintf("%s=%s", uri_escape_utf8($key), uri_escape_utf8($value)); } } join $sep, @out; } # Return the stringified qq hash with a leading '?' sub qstringify { my $self = shift; return '?' . $self->stringify(@_); } sub revert { my $self = shift; # Revert qq to the qq_orig hashref $self->{qq} = $self->_deepcopy($self->{qq_orig}); $self->{changed} = 0; $self; } sub has_changed { my $self = shift; $self->{changed} > 0 ? 1 : 0; } # ------------------------------------------------------------------------- # Convenience methods # Return the current qq hash(ref) with one-elt arrays flattened sub hash { my $self = shift; my %qq = %{$self->{qq}}; # Flatten one element arrays for (sort keys %qq) { $qq{$_} = $qq{$_}->[0] if @{$qq{$_}} == 1; } return wantarray ? %qq : \%qq; } # Return the current qq hash(ref) with all elements as arrayrefs sub hash_arrayref { my $self = shift; my %qq = %{$self->{qq}}; # (Don't flatten one element arrays) return wantarray ? %qq : \%qq; } # Return the current query as a string of html hidden input tags sub hidden { my $self = shift; my $str = ''; for my $key (sort keys %{$self->{qq}}) { for my $value (@{$self->{qq}->{$key}}) { $str .= qq(\n); } } return $str; } # ------------------------------------------------------------------------- # Set the output separator to use by default sub separator { my $self = shift; $self->{sep} = shift; } # Deep copy routine, originally swiped from a Randal Schwartz column sub _deepcopy { my ($self, $this) = @_; if (! ref $this) { return $this; } elsif (ref $this eq "ARRAY") { return [map $self->_deepcopy($_), @$this]; } elsif (ref $this eq "HASH") { return {map { $_ => $self->_deepcopy($this->{$_}) } keys %$this}; } elsif (ref $this eq "CODE") { return $this; } elsif (sprintf $this) { # Object! As a last resort, try copying the stringification value return sprintf $this; } else { die "what type is $_? (" . ref($this) . ")"; } } # Parse query string, storing as hash (qq) of key => arrayref pairs sub _parse_qs { my $self = shift; my $qs = shift; for (split /[&;]/, $qs) { my ($key, $value) = map { uri_unescape($_) } split /=/, $_, 2; $self->{qq}->{$key} ||= []; push @{$self->{qq}->{$key}}, $value if defined $value && $value ne ''; } $self } # Process arrayref arguments into hash (qq) of key => arrayref pairs sub _init_from_arrayref { my ($self, $arrayref) = @_; while (@$arrayref) { my $key = shift @$arrayref; my $value = shift @$arrayref; my $key_unesc = uri_unescape($key); $self->{qq}->{$key_unesc} ||= []; if (defined $value && $value ne '') { my @values; if (! ref $value) { @values = split "\0", $value; } elsif (ref $value eq 'ARRAY') { @values = @$value; } else { die "Invalid value found: $value. Not string or arrayref!"; } push @{$self->{qq}->{$key_unesc}}, map { uri_unescape($_) } @values; } } } # Constructor - either new($qs) where $qs is a scalar query string or a # a hashref of key => value pairs, or new(key => val, key => val); # In the array form, keys can repeat, and/or values can be arrayrefs. sub new { my $class = shift; my $self = bless { qq => {} }, $class; if (@_ == 1 && ! ref $_[0] && $_[0]) { $self->_parse_qs($_[0]); } elsif (@_ == 1 && ref $_[0] eq 'HASH') { $self->_init_from_arrayref([ %{$_[0]} ]); } elsif (scalar(@_) % 2 == 0) { $self->_init_from_arrayref(\@_); } # Clone the qq hashref to allow reversion $self->{qq_orig} = $self->_deepcopy($self->{qq}); # Changed flag $self->{changed} = 0; return $self; } # ------------------------------------------------------------------------- 1; =head1 NAME URI::Query - class providing URI query string manipulation =head1 SYNOPSIS # Constructor - using a GET query string $qq = URI::Query->new($query_string); # OR Constructor - using a hashref of key => value parameters $qq = URI::Query->new($cgi->Vars); # OR Constructor - using an array of successive keys and values $qq = URI::Query->new(@params); # Clone the current object $qq2 = $qq->clone; # Revert back to the initial constructor state (to do it all again) $qq->revert; # Remove all occurrences of the given parameters $qq->strip('page', 'next'); # Remove all parameters except the given ones $qq->strip_except('pagesize', 'order'); # Remove all empty/undefined parameters $qq->strip_null; # Replace all occurrences of the given parameters $qq->replace(page => $page, foo => 'bar'); # Set the argument separator to use for output (default: unescaped '&') $qq->separator(';'); # Output the current query string print "$qq"; # OR $qq->stringify; # Stringify with explicit argument separator $qq->stringify(';'); # Output the current query string with a leading '?' $qq->qstringify; # Stringify with a leading '?' and an explicit argument separator $qq->qstringify(';'); # Get a flattened hash/hashref of the current parameters # (single item parameters as scalars, multiples as an arrayref) my %qq = $qq->hash; # Get a non-flattened hash/hashref of the current parameters # (parameter => arrayref of values) my %qq = $qq->hash_arrayref; # Get the current query string as a set of hidden input tags print $qq->hidden; # Check whether the query has changed since construction if ($qq->has_changed) { print "changed version: $qq\n"; } =head1 DESCRIPTION URI::Query provides simple URI query string manipulation, allowing you to create and manipulate URI query strings from GET and POST requests in web applications. This is primarily useful for creating links where you wish to preserve some subset of the parameters to the current request, and potentially add or replace others. Given a query string this is doable with regexes, of course, but making sure you get the anchoring and escaping right is tedious and error-prone - this module is simpler. =head2 CONSTRUCTOR URI::Query objects can be constructed from scalar query strings ('foo=1&bar=2&bar=3'), from a hashref which has parameters as keys, and values either as scalars or arrayrefs of scalars (to handle the case of parameters with multiple values e.g. { foo => '1', bar => [ '2', '3' ] }), or arrays composed of successive parameters-value pairs e.g. ('foo', '1', 'bar', '2', 'bar', '3'). For instance: # Constructor - using a GET query string $qq = URI::Query->new($query_string); # Constructor - using an array of successive keys and values $qq = URI::Query->new(@params); # Constructor - using a hashref of key => value parameters, # where values are either scalars or arrayrefs of scalars $qq = URI::Query->new($cgi->Vars); URI::Query also handles L-style hashrefs, where multiple values are packed into a single string, separated by the "\0" (null) character. All keys and values are URI unescaped at construction time, and are stored and referenced unescaped. So a query string like: group=prod%2Cinfra%2Ctest&op%3Aset=x%3Dy is stored as: 'group' => 'prod,infra,test' 'op:set' => 'x=y' You should always use the unescaped/normal variants in methods i.e. $qq->replace('op:set' => 'x=z'); NOT: $qq->replace('op%3Aset' => 'x%3Dz'); You can also construct a new URI::Query object by cloning an existing one: $qq2 = $qq->clone; =head2 MODIFIER METHODS All modifier methods change the state of the URI::Query object in some way, and return $self, so they can be used in chained style e.g. $qq->revert->strip('foo')->replace(bar => 123); Note that URI::Query stashes a copy of the parameter set that existed at construction time, so that any changes made by these methods can be rolled back using 'revert()'. So you don't (usually) need to keep multiple copies around to handle incompatible changes. =over 4 =item revert() Revert the current parameter set back to that originally given at construction time i.e. discard all changes made since construction. =item strip($param1, $param2, ...) Remove all occurrences of the given parameters and their values from the current parameter set. =item strip_except($param1, $param2, ...) Remove all parameters EXCEPT those given from the current parameter set. =item strip_null() Remove all parameters that have a value of undef from the current parameter set. =item replace($param1 => $value1, $param2, $value2, ...) Replace the values of the given parameters in the current parameter set with these new ones. Parameter names must be scalars, but values can be either scalars or arrayrefs of scalars, when multiple values are desired. Note that 'replace' can also be used to add or append, since there's no requirement that the parameters already exist in the current parameter set. =item strip_like($regex) Remove all parameters whose names match the given (qr-quoted) regex e.g. $qq->strip_like(qr/^utm/) Does NOT match against parameter values. =item separator($separator) Set the argument separator to use for output. Default: '&'. =back =head2 ACCESSOR METHODS =over 4 =item has_changed() If the query is actually changed by any of the modifier methods (strip, strip_except, strip_null, strip_like, or replace) it sets an internal changed flag which can be access by: $qq->has_changed revert() resets the has_changed flag to false. =back =head2 OUTPUT METHODS =over 4 =item "$qq", stringify(), stringify($separator) Return the current parameter set as a conventional param=value query string, using $separator as the separator if given. e.g. foo=1&bar=2&bar=3 Note that all parameters and values are URI escaped by stringify(), so that query-string reserved characters do not occur within elements. For instance, a parameter set of: 'group' => 'prod,infra,test' 'op:set' => 'x=y' will be stringified as: group=prod%2Cinfra%2Ctest&op%3Aset=x%3Dy =item qstringify(), qstringify($separator) Convenience method to stringify with a leading '?' e.g. ?foo=1&bar=2&bar=3 =item hash() Return a hash (in list context) or hashref (in scalar context) of the current parameter set. Single-item parameters have scalar values, while while multiple-item parameters have arrayref values e.g. { foo => 1, bar => [ 2, 3 ], } =item hash_arrayref() Return a hash (in list context) or hashref (in scalar context) of the current parameter set. All values are returned as arrayrefs, including those with single values e.g. { foo => [ 1 ], bar => [ 2, 3 ], } =item hidden() Returns the current parameter set as a concatenated string of hidden input tags, one per parameter-value e.g. =back =head1 BUGS AND CAVEATS Please report bugs and/or feature requests to C, or through the web interface at L. Should allow unescaping of input to be turned off, for situations in which it's already been done. Please let me know if you find you actually need this. I don't think it makes sense on the output side though, since you need to understand the structure of the query to escape elements correctly. =head1 PATCHES URI::Query code lives at L. Patches / pull requests welcome! =head1 AUTHOR Gavin Carr =head1 COPYRIGHT Copyright 2004-2015, Gavin Carr. This program is free software. You may copy or redistribute it under the same terms as perl itself. =cut =for Pod::Coverage new # vim:sw=4:et