HTTP-Exception-0.04006000755001750001750 012277252372 13204 5ustar00tmutmu000000000000README100755001750001750 2327112277252372 14175 0ustar00tmutmu000000000000HTTP-Exception-0.04006NAME HTTP::Exception - throw HTTP-Errors as (Exception::Class-) Exceptions VERSION version 0.04006 SYNOPSIS HTTP::Exception lets you throw HTTP-Errors as Exceptions. use HTTP::Exception; # throw a 404 Exception HTTP::Exception->throw(404); # later in your framework eval { ... }; if (my $e = HTTP::Exception->caught) { # do some errorhandling stuff print $e->code; # 404 print $e->status_message; # Not Found } You can also throw HTTP::Exception-subclasses like this. # same 404 Exception eval { HTTP::Exception::404->throw(); }; eval { HTTP::Exception::NOT_FOUND->throw(); }; And catch them accordingly. # same 404 Exception eval { HTTP::Exception::404->throw(); }; if (my $e = HTTP::Exception::405->caught) { do stuff } # won't catch if (my $e = HTTP::Exception::404->caught) { do stuff } # will catch if (my $e = HTTP::Exception::NOT_FOUND->caught) { do stuff } # will catch if (my $e = HTTP::Exception::4XX->caught) { do stuff } # will catch all 4XX Exceptions if (my $e = HTTP::Exception->caught) { do stuff } # will catch every HTTP::Exception if (my $e = Exception::Class->caught) { do stuff } # catch'em all You can create Exceptions and not throw them, because maybe you want to set some fields manually. See "FIELDS" in HTTP::Exception and "ACCESSORS" in HTTP::Exception for more info. # is not thrown, ie doesn't die, only created my $e = HTTP::Exception->new(404); # usual stuff works $e->code; # 404 $e->status_message # Not Found # set status_message to something else $e->status_message('Nothing Here') # fails, because code is only an accessor, see section ACCESSORS below # $e->code(403); # and finally throw our prepared exception $e->throw; DESCRIPTION Every HTTP::Exception is a Exception::Class - Class. So the same mechanisms apply as with Exception::Class-classes. In fact have a look at Exception::Class' docs for more general information on exceptions and Exception::Class::Base for information on what methods a caught exception also has. HTTP::Exception is only a factory for HTTP::Exception::XXX (where X is a number) subclasses. That means that HTTP::Exception->new(404) returns a HTTP::Exception::404 object, which in turn is a HTTP::Exception::Base - Object. Don't bother checking a caught HTTP::Exception::...-class with "isa" as it might not contain what you would expect. Use the code- or status_message-attributes and the is_ -methods instead. The subclasses are created at compile-time, ie the first time you make "use HTTP::Exception". See paragraph below for the naming scheme of those subclasses. Subclassing the subclasses works as expected. NAMING SCHEME HTTP::Exception::XXX X is a Number and XXX is a valid HTTP-Statuscode. All HTTP-Statuscodes are supported. See chapter "COMPLETENESS" in HTTP::Exception HTTP::Exception::STATUS_MESSAGE STATUS_MESSAGE is the same name as a HTTP::Status Constant WITHOUT the HTTP_ at the beginning. So see "CONSTANTS" in HTTP::Status for more details. IMPORTING SPECIFIC ERROR RANGES It is possible to load only specific ranges of errors. For example use HTTP::Exception qw(5XX); HTTP::Exception::500->throw; # works HTTP::Exception::400->throw; # won't work anymore will only create HTTP::Exception::500 till HTTP::Exception::510. In theory this should save some memory, but I don't have any numbers, that back up this claim. You can load multiple ranges use HTTP::Exception qw(3XX 4XX 5XX); And there are aliases for ranges use HTTP::Exception qw(CLIENT_ERROR) The following aliases exist and load the specified ranges: REDIRECTION => 3XX CLIENT_ERROR => 4XX SERVER_ERROR => 5XX ERROR => 4XX 5XX ALL => 1XX 2XX 3XX 4XX 5XX And of course, you can load multiple aliased ranges use HTTP::Exception qw(REDIRECTION ERROR) ALL is the same as not specifying any specific range. # the same use HTTP::Exception qw(ALL); use HTTP::Exception; ACCESSORS (READONLY) code A valid HTTP-Statuscode. See HTTP::Status for information on what codes exist. is_info Return TRUE if "$self-"code> is an *Informational* status code (1xx). This class of status code indicates a provisional response which can't have any content. is_success Return TRUE if "$self-"code> is a *Successful* status code (2xx). is_redirect Return TRUE if "$self-"code> is a *Redirection* status code (3xx). This class if status code indicates that further action needs to be taken by the user agent in order to fulfill the request. is_error Return TRUE if "$self-"code> is an *Error* status code (4xx or 5xx). The function return TRUE for both client error or a server error status codes. is_client_error Return TRUE if "$self-"code> is an *Client Error* status code (4xx). This class of status code is intended for cases in which the client seems to have erred. is_server_error Return TRUE if "$self-"code> is an *Server Error* status code (5xx). This class of status codes is intended for cases in which the server is aware that it has erred or is incapable of performing the request. *POD for is_ methods is Copy/Pasted from HTTP::Status, so check back there and alert me of changes.* FIELDS Fields are the same as ACCESSORS except they can be set. Either you set them during Exception creation (->new) or Exception throwing (->throw). HTTP::Exception->new(200, status_message => "Everything's fine"); HTTP::Exception::200->new(status_message => "Everything's fine"); HTTP::Exception::OK->new(status_message => "Everything's fine"); HTTP::Exception->throw(200, status_message => "Everything's fine"); HTTP::Exception::200->throw(status_message => "Everything's fine"); HTTP::Exception::OK->throw(status_message => "Everything's fine"); Catch them in your Webframework like this eval { ... } if (my $e = HTTP::Exception->caught) { print $e->code; # 200 print $e->status_message # "Everything's fine" instead of the usual ok } status_message DEFAULT The HTTP-Statusmessage as provided by HTTP::Status A Message, that represents the Execptions' Status for Humans. PLACK HTTP::Exception can be used with Plack::Middleware::HTTPExceptions. But HTTP::Exception does not depend on Plack, you can use it anywhere else. It just plays nicely with Plack. COMPLETENESS For the sake of completeness, HTTP::Exception provides exceptions for non-error-http-statuscodes. This means you can do HTTP::Exception->throw(200); which throws an Exception of type OK. Maybe useless, but complete. A more realworld-example would be a redirection # all are exactly the same HTTP::Exception->throw(301, location => 'google.com'); HTTP::Exception::301->throw(location => 'google.com'); HTTP::Exception::MOVED_PERMANENTLY->throw(location => 'google.com'); CAVEATS The HTTP::Exception-Subclass-Creation relies on HTTP::Status. It's possible that the Subclasses change, when HTTP::Status' constants are changed. New Subclasses are created automatically, when constants are added to HTTP::Status. That means in turn, that Subclasses disappear, when constants are removed from HTTP::Status. Some constants were added to HTTP::Status' in February 2012. As a result HTTP::Exception broke. But that was the result of uncareful coding on my side. I think, that breaking changes are now quite unlikely. AUTHOR Thomas Mueller, "" SEE ALSO Exception::Class, Exception::Class::Base Consult Exception::Class' documentation for the Exception-Mechanism and Exception::Class::Base' docs for a list of methods our caught Exception is also capable of. HTTP::Status Constants, Statuscodes and Statusmessages Plack, especially Plack::Middleware::HTTPExceptions Have a look at Plack, because it rules in general. In the first place, this Module was written as the companion for Plack::Middleware::HTTPExceptions, but since it doesn't depend on Plack, you can use it anywhere else, too. BUGS Please report any bugs or feature requests to "bug-http-exception at rt.cpan.org", or through the web interface at . I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. SUPPORT You can find documentation for this module with the perldoc command. perldoc HTTP::Exception You can also look for information at: * RT: CPAN's request tracker * AnnoCPAN: Annotated CPAN documentation * CPAN Ratings * Search CPAN LICENSE AND COPYRIGHT Copyright 2010 Thomas Mueller. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. Changes100755001750001750 614112277252372 14565 0ustar00tmutmu000000000000HTTP-Exception-0.040060.04006 2014-02-14 00:27:50+01:00 Europe/Berlin typo fix (thanks dsteinbrunner) 0.04005 2014-02-14 00:03:43+01:00 Europe/Berlin corrected Encoding in dist.ini, due to CPAN Testers reporting an invalid byte sequence in the Makefile 0.04004 2012-08-17 01:00:11 Europe/Berlin Dist::Zilla::Plugin::GitHub::Meta extracts correct Metainfos now 0.04003 2012-08-17 00:38:56 Europe/Berlin Versions are now handled by Dist::Zilla::Plugin::PkgVersion deleted 2 unused testclasses 0.04002 2012-08-17 00:08:19 Europe/Berlin RT 79021: Eliminate warnings about "subroutine redefined" * subroutine redefined warnings under mod_perl silenced * created testcase "emulating" mod_perl removed shebang in authortests 0.04001 2012-02-24 22:55:01 Europe/Berlin RT 75271: AutoPrereq of Dist::Zilla found too many dependencies, * fixed by stating dependencies explicitly (thanks jquelin) 0.04 2012-02-18 22:04:20 Europe/Berlin HTTP::Status 6.03 added a status, that broke this module moved to Dist::Zilla 0.03001 2010-03-11 Fixed tests not to emit warnings anymore 0.03000 2010-03-11 Added possibility to import only specific error ranges Added tests and Pod for this 0.02006 2010-03-08 Added minimum version requirements to prerequisites 0.02005 2010-03-05 Added Pod VERSION sections back in, thanks to ShipIt::Step::ChangePodVersion ;) 0.02004 2010-03-04 Corrected $VERSION for changed modules 0.02003 2010-03-04 Removed parent.pm - dependency Added base.pm - dependency, works better and is longer in Core HTTP::Request::Common required for t/05-plack.t, othwerwise skipped 0.02002 2010-03-04 Some small POD enhancements for H::E::Base and H::E::Loader 0.02001 2010-03-04 Fixed POD for HTTP::Exception::nXX-Classes (again copy/paste) Updated README 0.02000 2010-03-03 Added "Tween-Classes" to the hierarchy (1XX .. 5XX) Added Tests for "Tween-Classes" to the hierarchy (1XX .. 5XX) Fixed t/06-is_methods.t not to use Plack::Test anymore Changed HTTP::Exception::Base to use as_string from Exception::Class::Base Added location field for 3XX Exceptions Added message and error as synonym for status_message (compat for Exception::Class) Fixed t/06-is_methods.t to not include Plack::Test anymore (evil copy/paste) Forgot dates in the Changes-File :\ 0.01007 2010-03-03 fixed some POD 0.01006 2010-03-02 changed EMail-Address in packages to my CPAN-EMail 0.01005 2010-03-02 removed VERSION from pod, too much hassle to keep in sync with $VERSION 0.01004 2010-03-02 still trying to shipit 0.01003 2010-03-02 no changes to the module itself, just trying to get shipit to work 0.01002 2010-03-02 removed MANIFEST.SKIP from MANIFEST Corrected BuildRequirements in Build.PL (added Test::Exception) Corrected Requirements in Makefile.PL, thought it is recreated automatically fixed t/05.plack to be skipped on systems without Plack 0.01001 2010-03-02 Corrected Requirements in Build.PL 0.01000 2010-02-29 First Implementation of HTTP::Exceptions t000755001750001750 012277252372 13370 5ustar00tmutmu000000000000HTTP-Exception-0.04006eol.t100755001750001750 41512277252372 14457 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; BEGIN { unless ( $ENV{RELEASE_TESTING} ) { plan( skip_all => "Author tests not required for installation" ); } eval "use Test::EOL"; plan skip_all => 'Test::EOL required for testing EOL' if $@; } all_perl_files_ok;pod.t100755001750001750 51112277252372 14457 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use warnings; use Test::More; unless ( $ENV{RELEASE_TESTING} ) { plan( skip_all => "Author tests not required for installation" ); } # Ensure a recent version of Test::Pod my $min_tp = 1.22; eval "use Test::Pod $min_tp"; plan skip_all => "Test::Pod $min_tp required for testing POD" if $@; all_pod_files_ok(); LICENSE100755001750001750 4366112277252372 14327 0ustar00tmutmu000000000000HTTP-Exception-0.04006This software is copyright (c) 2012 by Thomas Müller. 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) 2012 by Thomas Müller. 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, Suite 500, Boston, MA 02110-1335 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) 2012 by Thomas Müller. 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 INSTALL100755001750001750 171012277252372 14320 0ustar00tmutmu000000000000HTTP-Exception-0.04006 This is the Perl distribution HTTP-Exception. Installing HTTP-Exception is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm HTTP::Exception If you are installing into a system-wide directory, you may need to pass the "-S" flag to cpanm, which uses sudo to install the module: % cpanm -S HTTP::Exception ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan HTTP::Exception ## Manual installation As a last resort, you can manually install it. Download the tarball, untar it, then build it: % perl Makefile.PL % make && make test Then install it: % make install If you are installing into a system-wide directory, you may need to run: % sudo make install ## Documentation HTTP-Exception documentation is available as POD. You can run perldoc from a shell to read the documentation: % perldoc HTTP::Exception dist.ini100755001750001750 175212277252372 14741 0ustar00tmutmu000000000000HTTP-Exception-0.04006name = HTTP-Exception author = Thomas Müller license = Perl_5 copyright_holder = Thomas Müller copyright_year = 2012 [GatherDir] exclude_match = komodo exclude_match = kpf [Prereqs] warnings = 0 base = 0 strict = 0 Scalar::Util = 1.22 Test::Exception = 0.29 HTTP::Status = 5.817 Exception::Class = 1.29 Test::More = 0.88 Test::NoWarnings = 1.04 [Git::Check] allow_dirty = [Git::NextVersion] [Git::CommitBuild] [PkgVersion] [PodVersion] [NextRelease] time_zone = Europe/Berlin [PruneCruft] [ManifestSkip] [MetaYAML] [License] ;[ExtraTests] ;[ExecDir] ;[ShareDir] [MakeMaker] [Manifest] [InstallGuide] [GitHub::Meta] repo = http_exception fork = 0 ;[PodWeaver] [PodSyntaxTests] [PodCoverageTests] [ReadmeFromPod] [TestRelease] [ConfirmRelease] [UploadToCPAN] [Git::Tag] time_zone = Europe/Berlin [Git::Push] [InstallRelease] install_command = cpanm . [Twitter] hash_tags = #perl META.yml100755001750001750 134512277252372 14544 0ustar00tmutmu000000000000HTTP-Exception-0.04006--- abstract: 'throw HTTP-Errors as (Exception::Class-) Exceptions' author: - 'Thomas Müller ' build_requires: {} configure_requires: ExtUtils::MakeMaker: 6.30 dynamic_config: 0 generated_by: 'Dist::Zilla version 5.013, CPAN::Meta::Converter version 2.132140' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: HTTP-Exception requires: Exception::Class: 1.29 HTTP::Status: 5.817 Scalar::Util: 1.22 Test::Exception: 0.29 Test::More: 0.88 Test::NoWarnings: 1.04 base: 0 strict: 0 warnings: 0 resources: bugtracker: https://github.com/tmueller/http_exception/issues repository: git://github.com/tmueller/http_exception.git version: 0.04006 MANIFEST100755001750001750 174412277252372 14427 0ustar00tmutmu000000000000HTTP-Exception-0.04006# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.013. Changes INSTALL LICENSE MANIFEST META.yml Makefile.PL README dist.ini lib/HTTP/Exception.pm lib/HTTP/Exception/1XX.pm lib/HTTP/Exception/2XX.pm lib/HTTP/Exception/3XX.pm lib/HTTP/Exception/4XX.pm lib/HTTP/Exception/5XX.pm lib/HTTP/Exception/Base.pm lib/HTTP/Exception/Loader.pm t/00-load.t t/01-exceptions.t t/02-combinations.t t/03-nice.t t/04-subclassing.t t/05-plack.t t/06-is_methods.t t/07-status_messages.t t/10-fields_1xx.t t/11-fields_2xx.t t/12-fields_3xx.t t/13-fields_4xx.t t/14-fields_5xx.t t/15-fields_ec.t t/20-load_1XX.t t/21-load_2XX.t t/22-load_3XX.t t/23-load_4XX.t t/24-load_5XX.t t/25-load_all.t t/26-load_server_error.t t/27-load_client_error.t t/28-load_errors.t t/29-load_redirection.t t/30-implicit_all.t t/31-load_mixed.t t/32-load_warnings.t t/boilerplate.t t/eol.t t/eol_special.t t/lib/Test/HTTP/Exception/Ranges.pm t/manifest.t t/pod.t xt/release/pod-coverage.t xt/release/pod-syntax.t 00-load.t100755001750001750 65512277252372 15042 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; BEGIN { use_ok 'HTTP::Exception::1XX'; use_ok 'HTTP::Exception::2XX'; use_ok 'HTTP::Exception::3XX'; use_ok 'HTTP::Exception::4XX'; use_ok 'HTTP::Exception::5XX'; use_ok 'HTTP::Exception::Base'; use_ok 'HTTP::Exception'; } # use_ok 'HTTP::Exception::Loader' removed because it emits redefined # warnings, it's not recommended to use Loader directly anyway done_testing;03-nice.t100755001750001750 146212277252372 15061 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::Exception; use Test::More; use HTTP::Exception; # do we play nicely with other user defined exception? use Exception::Class ('User::Defined::Exception' => {}); throws_ok sub { User::Defined::Exception->throw; }, 'User::Defined::Exception'; eval { User::Defined::Exception->throw; }; ok !defined HTTP::Exception->caught , 'HTTP::Exception not caught'; ok defined User::Defined::Exception->caught, 'User::Defined::Exception caught'; ok defined Exception::Class->caught , 'Exception::Class caught'; eval { HTTP::Exception::200->throw; }; ok defined HTTP::Exception->caught , 'HTTP::Exception caught'; ok !defined User::Defined::Exception->caught, 'User::Defined::Exception not caught'; ok defined Exception::Class->caught , 'Exception::Class caught'; done_testing;Makefile.PL100755001750001750 267712277252372 15256 0ustar00tmutmu000000000000HTTP-Exception-0.04006 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.013. use strict; use warnings; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "throw HTTP-Errors as (Exception::Class-) Exceptions", "AUTHOR" => "Thomas M\x{fc}ller ", "BUILD_REQUIRES" => {}, "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "HTTP-Exception", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "HTTP::Exception", "PREREQ_PM" => { "Exception::Class" => "1.29", "HTTP::Status" => "5.817", "Scalar::Util" => "1.22", "Test::Exception" => "0.29", "Test::More" => "0.88", "Test::NoWarnings" => "1.04", "base" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => {}, "VERSION" => "0.04006", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Exception::Class" => "1.29", "HTTP::Status" => "5.817", "Scalar::Util" => "1.22", "Test::Exception" => "0.29", "Test::More" => "0.88", "Test::NoWarnings" => "1.04", "base" => 0, "strict" => 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); 05-plack.t100755001750001750 433212277252372 15236 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; BEGIN { # Plack 0.9913 brings us Plack::Middleware::HTTPExceptions eval "use Plack 0.9913"; plan skip_all => "Plack 0.9913 or newer required for this test" if $@; eval "use HTTP::Request::Common"; plan skip_all => "HTTP::Request::Common required for this test" if $@; } use HTTP::Exception; use Plack::Test; use HTTP::Status; use HTTP::Request::Common; { package My::HTTP::Exception; use base 'HTTP::Exception::405'; sub code { 404 } sub my_info { 'Interesting Info' } } { package My::HTTP::Exception::WithStatusMessage; use base 'HTTP::Exception::405'; sub code { 404 } sub status_message { 'Nothing here' } } my @tests = ({ path => '/ok', exception => sub { HTTP::Exception::UNAUTHORIZED->throw; }, expected_code => 401, },{ path => '/secret', exception => sub { HTTP::Exception::402->throw; }, expected_code => 402, },{ path => '/not_found', exception => sub { HTTP::Exception->throw(403); }, expected_code => 403, },{ path => '/custom', exception => sub { My::HTTP::Exception->throw; }, expected_code => 404, expected_content => HTTP::Status::status_message(405), },{ path => '/custom/with/message', exception => sub { My::HTTP::Exception::WithStatusMessage->throw; }, expected_code => 404, expected_content => 'Nothing here', }); my $app = sub { my $env = shift; my ($found_test) = grep { $_->{path} eq $env->{PATH_INFO} } @tests; HTTP::Exception::500->throw unless ($found_test); $found_test->{exception}->(); }; use Plack::Middleware::HTTPExceptions; $app = Plack::Middleware::HTTPExceptions->wrap($app); test_psgi $app, sub { my $cb = shift; my $res = $cb->(GET "/"); is $res->code, 500; is $res->content, 'Internal Server Error'; for my $test (@tests) { my $res = $cb->(GET ($test->{path})); is $res->code, $test->{expected_code}; is $res->content, $test->{expected_content} || HTTP::Status::status_message($test->{expected_code}); } }; done_testing;manifest.t100755001750001750 44512277252372 15511 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use warnings; use Test::More; # TODO Make manifest test pass unless ( $ENV{RELEASE_TESTING} ) { plan( skip_all => "Author tests not required for installation" ); } eval "use Test::CheckManifest 0.9"; plan skip_all => "Test::CheckManifest 0.9 required" if $@; ok_manifest(); 20-load_1XX.t100755001750001750 23512277252372 15536 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use lib 't/lib'; use Test::HTTP::Exception::Ranges; Test::HTTP::Exception::Ranges::simple_test_range_ok(qw~1XX~); done_testing;21-load_2XX.t100755001750001750 23512277252372 15540 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use lib 't/lib'; use Test::HTTP::Exception::Ranges; Test::HTTP::Exception::Ranges::simple_test_range_ok(qw~2XX~); done_testing;22-load_3XX.t100755001750001750 23512277252372 15542 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use lib 't/lib'; use Test::HTTP::Exception::Ranges; Test::HTTP::Exception::Ranges::simple_test_range_ok(qw~3XX~); done_testing;23-load_4XX.t100755001750001750 23512277252372 15544 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use lib 't/lib'; use Test::HTTP::Exception::Ranges; Test::HTTP::Exception::Ranges::simple_test_range_ok(qw~4XX~); done_testing;24-load_5XX.t100755001750001750 23512277252372 15546 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use lib 't/lib'; use Test::HTTP::Exception::Ranges; Test::HTTP::Exception::Ranges::simple_test_range_ok(qw~5XX~); done_testing;25-load_all.t100755001750001750 30312277252372 15667 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use lib 't/lib'; use Test::HTTP::Exception::Ranges; use HTTP::Exception qw(ALL); Test::HTTP::Exception::Ranges::test_range_ok(100, 200, 300, 400, 500); done_testing;boilerplate.t100755001750001750 261412277252372 16225 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use warnings; use Test::More; unless ( $ENV{RELEASE_TESTING} ) { plan( skip_all => "Author tests not required for installation" ); } sub not_in_file_ok { my ($filename, %regex) = @_; open( my $fh, '<', $filename ) or die "couldn't open $filename for reading: $!"; my %violated; while (my $line = <$fh>) { while (my ($desc, $regex) = each %regex) { if ($line =~ $regex) { push @{$violated{$desc}||=[]}, $.; } } } if (%violated) { fail("$filename contains boilerplate text"); diag "$_ appears on lines @{$violated{$_}}" for keys %violated; } else { pass("$filename contains no boilerplate text"); } } sub module_boilerplate_ok { my ($module) = @_; not_in_file_ok($module => 'the great new $MODULENAME' => qr/ - The great new /, 'boilerplate description' => qr/Quick summary of what the module/, 'stub function definition' => qr/function[12]/, ); } TODO: { local $TODO = "Need to replace the boilerplate text"; not_in_file_ok(README => "The README is used..." => qr/The README is used/, "'version information here'" => qr/to provide version information/, ); not_in_file_ok(Changes => "placeholder date/time" => qr(Date/time) ); module_boilerplate_ok('lib/HTTP/Exception.pm'); } done_testing;eol_special.t100755001750001750 67212277252372 16164 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; BEGIN { unless ( $ENV{RELEASE_TESTING} ) { plan( skip_all => "Author tests not required for installation" ); } eval "use Test::EOL"; plan skip_all => 'Test::EOL required for testing EOL' if $@; } for my $filename (qw~Changes~) { unless (-f $filename) { diag "$filename does not exist"; next; } eol_unix_ok $filename, "$filename is ok"; } done_testing; 15-fields_ec.t100755001750001750 330612277252372 16062 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use HTTP::Exception; my @tests = (100,200,300,400,500); for my $status_code (@tests) { my $e = HTTP::Exception->new($status_code); # no real testing, i think Exception::Class has enough tests # so just checking, whether there is something or not ok defined $e->message() , '$e->message() is "'.$e->message() .qq~" ($status_code)~; ok defined $e->error() , '$e->error() is "'.$e->error() .qq~" ($status_code)~; ok defined $e->pid() , '$e->pid() is "'.$e->pid() .qq~" ($status_code)~; ok defined $e->uid() , '$e->uid() is "'.$e->uid() .qq~" ($status_code)~; ok defined $e->gid() , '$e->gid() is "'.$e->gid() .qq~" ($status_code)~; ok defined $e->euid() , '$e->euid() is "'.$e->euid() .qq~" ($status_code)~; ok defined $e->egid() , '$e->egid() is "'.$e->egid() .qq~" ($status_code)~; ok defined $e->time() , '$e->time() is "'.$e->time() .qq~" ($status_code)~; ok defined $e->package() , '$e->package() is "'.$e->package() .qq~" ($status_code)~; ok defined $e->file() , '$e->file() is "'.$e->file() .qq~" ($status_code)~; ok defined $e->line() , '$e->line() is "'.$e->line() .qq~" ($status_code)~; ok defined $e->trace() , '$e->trace() is "'.$e->trace() .qq~" ($status_code)~; ok defined $e->as_string() , '$e->as_string() is "'.$e->as_string() .qq~" ($status_code)~; ok defined $e->full_message(), '$e->full_message() is "'.$e->full_message().qq~" ($status_code)~; } done_testing;01-exceptions.t100755001750001750 661212277252372 16324 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::Exception; use Test::More; use HTTP::Exception; use HTTP::Status; my @exception_class_classes = Exception::Class::Classes(); my %exception_class_classes; @exception_class_classes{@exception_class_classes} = undef; ################################################################################ # HTTP::Exception Tests ok exists $exception_class_classes{'HTTP::Exception'}, 'HTTP::Exception acts as loader and exception'; throws_ok sub { HTTP::Exception->throw(200) }, 'HTTP::Exception::200'; throws_ok sub { HTTP::Exception->throw }, qr/HTTP::Exception->throw needs a HTTP-Statuscode to throw/; throws_ok sub { HTTP::Exception->throw(1) }, qr/Unknown HTTP-Statuscode:/; eval { HTTP::Exception->throw }; my $e0 = HTTP::Exception->caught; ok (!defined $e0, 'HTTP::Exception is not caught when no Errorcode is given'); eval { HTTP::Exception->throw(1) }; my $e00 = HTTP::Exception->caught; ok (!defined $e00, 'HTTP::Exception is not caught when wrong Errorcode is given'); my $e2 = HTTP::Exception->new(200); __PACKAGE__->_run_tests_for_exception_object($e2); delete $exception_class_classes{'HTTP::Exception'}; # got a special treatment ################################################################################ # HTTP::Exception::... Tests for my $exception_name (keys %exception_class_classes) { # testing whether throw works throws_ok sub { $exception_name->throw }, $exception_name; # testing whether new works my $e = $exception_name->new; isa_ok $e, $exception_name; __PACKAGE__->_run_tests_for_exception_object($e); # testing whether catching via HTTP::Exception works eval { $exception_name->throw() }; my $e1 = HTTP::Exception->caught; isa_ok $e1, $exception_name; __PACKAGE__->_run_tests_for_exception_object($e1); # testing catch via HTTP::Exception::NXX classes # maybe using another tests' result is not so good, but anyways my $error_code_range = $e1->code; $error_code_range =~ s/\d{2}$/XX/; eval { $exception_name->throw() }; my $e2 = "HTTP::Exception::$error_code_range"->caught; __PACKAGE__->_run_tests_for_exception_object($e2); # testing whether catching via HTTP::Exception::... works eval { $exception_name->throw() }; my $e3 = $exception_name->caught; isa_ok $e3, $exception_name; __PACKAGE__->_run_tests_for_exception_object($e3); } ################################################################################ # tests sub sub _run_tests_for_exception_object { my $class = shift; my $e = shift; like $e->code, qr/\d+/, 'code is a number ('. $e->code .')'; is $e->status_message, HTTP::Status::status_message($e->code), 'status_message is same as HTTP::Status'; is $e->as_string, HTTP::Status::status_message($e->code), 'to_string as well'; is (($e->Fields)[0], 'status_message', 'field status_message found'); can_ok $e, qw(code status_message as_string); ok !$e->can('_make_exceptions'), '_make_exceptions is not imported from Loader'; SKIP: { # yes, ugly, I know skip q(can't reliably determine expected Errorcode), 2 unless (ref($e) =~ /(\d+)$/); is $e->code, $1, 'Errorcode in Classname and expected HTTP-Errorcode match'; }; } done_testing;06-is_methods.t100755001750001750 232512277252372 16303 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use HTTP::Exception; use HTTP::Status; # this is more or less testing, whether the is_ subs work # since inheritance should work, i don't bother testing the statusname-classes my @tests = (100,200,300,400,500); for my $statuscode (@tests) { my $e = HTTP::Exception->new($statuscode); is $e->is_info, !!HTTP::Status::is_info($statuscode), "$statuscode is ". ($e->is_info ? '' : 'not ') .'an info'; is $e->is_success, !!HTTP::Status::is_success($statuscode), "$statuscode is ". ($e->is_success ? '' : 'not ') .'a success'; is $e->is_redirect, !!HTTP::Status::is_redirect($statuscode), "$statuscode is ". ($e->is_redirect ? '' : 'not ') .'a redirect'; is $e->is_error, !!HTTP::Status::is_error($statuscode), "$statuscode is ". ($e->is_error ? '' : 'not ') .'an error'; is $e->is_client_error, !!HTTP::Status::is_client_error($statuscode), "$statuscode is ". ($e->is_client_error ? '' : 'not ') .'a clienterror'; is $e->is_server_error, !!HTTP::Status::is_server_error ($statuscode), "$statuscode is ". ($e->is_server_error ? '' : 'not ') .'a servererror'; } done_testing;10-fields_1xx.t100755001750001750 17412277252372 16166 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use HTTP::Exception; plan skip_all => 'no fields for HTTP::Exception::1XX yet'; done_testing;11-fields_2xx.t100755001750001750 17412277252372 16170 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use HTTP::Exception; plan skip_all => 'no fields for HTTP::Exception::2XX yet'; done_testing;12-fields_3xx.t100755001750001750 261512277252372 16214 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use HTTP::Exception; my @tests = (301 .. 304); # only as example my @fields = qw(location); # has only one field for now ################################################################################ for my $status_code (@tests) { # setting fieldnames one by one for my $field_name (@fields) { my $field_value = rand; my $e = HTTP::Exception->new($status_code, $field_name => $field_value); _check_exception( $e, "$status_code / $field_name set with new", $field_name => $field_value ); my $e2 = HTTP::Exception->new($status_code); $e2->location($field_value); _check_exception( $e, "$status_code / $field_name set with accessor", $field_name => $field_value ); } # setting all fields at once my %field_mapping; @field_mapping{@fields} = ((rand()) x scalar @fields); my $e = HTTP::Exception->new($status_code, %field_mapping); _check_exception( $e, "all fields set at once", %field_mapping ); } ################################################################################ sub _check_exception { my $e = shift; my $message = shift; my %fields = @_; for my $field_name (keys %fields) { is $e->$field_name, $fields{$field_name}, $message; } } done_testing;13-fields_4xx.t100755001750001750 17412277252372 16174 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use HTTP::Exception; plan skip_all => 'no fields for HTTP::Exception::4XX yet'; done_testing;14-fields_5xx.t100755001750001750 17412277252372 16176 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use HTTP::Exception; plan skip_all => 'no fields for HTTP::Exception::5XX yet'; done_testing;31-load_mixed.t100755001750001750 31212277252372 16222 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use lib 't/lib'; use Test::HTTP::Exception::Ranges; use HTTP::Exception qw(REDIRECTION ERROR); Test::HTTP::Exception::Ranges::test_range_ok(qw~3XX 4XX 5XX~); done_testing;04-subclassing.t100755001750001750 214012277252372 16453 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::Exception; use Test::More; use HTTP::Exception; { package My::HTTP::Exception; use base 'HTTP::Exception::200'; sub code { 999 } sub my_info { 'Interesting Info' } sub status_message { 'Interesting Message' } } throws_ok sub { My::HTTP::Exception->throw; }, 'My::HTTP::Exception' ; ok defined My::HTTP::Exception->caught, 'custom HTTP::Exception caught'; ok defined HTTP::Exception::200->caught, 'custom HTTP::Exception caught with HTTP::Exception::200'; ok defined HTTP::Exception::OK->caught, 'custom HTTP::Exception caught with HTTP::Exception::OK'; ok !defined HTTP::Exception::404->caught, 'custom HTTP::Exception not caught with wrong HTTP::Exception::OK'; my $e = HTTP::Exception->caught; ok defined $e, 'custom HTTP::Exception caught with HTTP::Exception'; is $e->code, 999, 'code overridden'; is $e->my_info, 'Interesting Info', 'additional sub exists'; is $e->status_message, 'Interesting Message', 'Status Message changed'; is $e->as_string, 'Interesting Message', 'as_string changed'; done_testing;28-load_errors.t100755001750001750 27212277252372 16443 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use lib 't/lib'; use Test::HTTP::Exception::Ranges; use HTTP::Exception qw(ERROR); Test::HTTP::Exception::Ranges::test_range_ok(qw~5XX 4XX~); done_testing;02-combinations.t100755001750001750 232712277252372 16630 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use HTTP::Exception; ################################################################################ # wasn't sure whether $@ survives a subcall, but it seems it does sub _run_tests_for_exception { my $e = HTTP::Exception->caught; ok defined $e , 'HTTP::Exception caught' ; is $e->code, 200 , 'HTTP::Exception has right code'; ok defined HTTP::Exception::2XX->caught , '2XX caught' ; ok defined HTTP::Exception::200->caught , '200 caught' ; ok defined HTTP::Exception::OK->caught , 'OK caught' ; ok !(defined HTTP::Exception::4XX->caught) , '4XX not caught' ; ok !(defined HTTP::Exception::NOT_FOUND->caught), 'NOT_FOUND not caught' ; ok !(defined HTTP::Exception::404->caught) , '404 not caught' ; ok defined Exception::Class->caught , 'Exception::Class caught' ; } ################################################################################ eval { HTTP::Exception::200->throw }; _run_tests_for_exception; eval { HTTP::Exception::OK->throw }; _run_tests_for_exception; eval { HTTP::Exception->throw(200) }; _run_tests_for_exception; done_testing;30-implicit_all.t100755001750001750 27312277252372 16564 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use lib 't/lib'; use Test::HTTP::Exception::Ranges; use HTTP::Exception; Test::HTTP::Exception::Ranges::test_range_ok(100, 200, 300, 400, 500); done_testing;32-load_warnings.t100755001750001750 25312277252372 16751 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use warnings; use Test::More tests => 1; use Test::NoWarnings; # "emulating" warnings under mod_perl eval "use HTTP::Exception"; eval "use HTTP::Exception"; HTTP000755001750001750 012277252372 14452 5ustar00tmutmu000000000000HTTP-Exception-0.04006/libException.pm100755001750001750 2460212277252372 17135 0ustar00tmutmu000000000000HTTP-Exception-0.04006/lib/HTTPpackage HTTP::Exception; $HTTP::Exception::VERSION = '0.04006'; use strict; use HTTP::Status; use Scalar::Util qw(blessed); ################################################################################ sub import { my ($class) = shift; require HTTP::Exception::Loader; HTTP::Exception::Loader->import(@_); } # act as a kind of factory here sub new { my $class = shift; my $error_code = shift; die ('HTTP::Exception->throw needs a HTTP-Statuscode to throw') unless ($error_code); die ("Unknown HTTP-Statuscode: $error_code") unless (HTTP::Status::status_message ($error_code)); "HTTP::Exception::$error_code"->new(@_); } # makes HTTP::Exception->caught possible instead of HTTP::Exception::Base->caught sub caught { my $self = shift; my $e = $@; return $e if (blessed $e && $e->isa('HTTP::Exception::Base')); $self->SUPER::caught(@_); } 1; =head1 NAME HTTP::Exception - throw HTTP-Errors as (Exception::Class-) Exceptions =head1 VERSION version 0.04006 =begin readme =head1 INSTALLATION To install this module, run the following commands: perl Build.PL ./Build ./Build test ./Build install =end readme =head1 SYNOPSIS HTTP::Exception lets you throw HTTP-Errors as Exceptions. use HTTP::Exception; # throw a 404 Exception HTTP::Exception->throw(404); # later in your framework eval { ... }; if (my $e = HTTP::Exception->caught) { # do some errorhandling stuff print $e->code; # 404 print $e->status_message; # Not Found } You can also throw HTTP::Exception-subclasses like this. # same 404 Exception eval { HTTP::Exception::404->throw(); }; eval { HTTP::Exception::NOT_FOUND->throw(); }; And catch them accordingly. # same 404 Exception eval { HTTP::Exception::404->throw(); }; if (my $e = HTTP::Exception::405->caught) { do stuff } # won't catch if (my $e = HTTP::Exception::404->caught) { do stuff } # will catch if (my $e = HTTP::Exception::NOT_FOUND->caught) { do stuff } # will catch if (my $e = HTTP::Exception::4XX->caught) { do stuff } # will catch all 4XX Exceptions if (my $e = HTTP::Exception->caught) { do stuff } # will catch every HTTP::Exception if (my $e = Exception::Class->caught) { do stuff } # catch'em all You can create Exceptions and not throw them, because maybe you want to set some fields manually. See L and L for more info. # is not thrown, ie doesn't die, only created my $e = HTTP::Exception->new(404); # usual stuff works $e->code; # 404 $e->status_message # Not Found # set status_message to something else $e->status_message('Nothing Here') # fails, because code is only an accessor, see section ACCESSORS below # $e->code(403); # and finally throw our prepared exception $e->throw; =head1 DESCRIPTION Every HTTP::Exception is a L - Class. So the same mechanisms apply as with L-classes. In fact have a look at L' docs for more general information on exceptions and L for information on what methods a caught exception also has. HTTP::Exception is only a factory for HTTP::Exception::XXX (where X is a number) subclasses. That means that HTTP::Exception->new(404) returns a HTTP::Exception::404 object, which in turn is a HTTP::Exception::Base - Object. Don't bother checking a caught HTTP::Exception::...-class with "isa" as it might not contain what you would expect. Use the code- or status_message-attributes and the is_ -methods instead. The subclasses are created at compile-time, ie the first time you make "use HTTP::Exception". See paragraph below for the naming scheme of those subclasses. Subclassing the subclasses works as expected. =head1 NAMING SCHEME =head2 HTTP::Exception::XXX X is a Number and XXX is a valid HTTP-Statuscode. All HTTP-Statuscodes are supported. See chapter L =head2 HTTP::Exception::STATUS_MESSAGE STATUS_MESSAGE is the same name as a L Constant B the HTTP_ at the beginning. So see L for more details. =head1 IMPORTING SPECIFIC ERROR RANGES It is possible to load only specific ranges of errors. For example use HTTP::Exception qw(5XX); HTTP::Exception::500->throw; # works HTTP::Exception::400->throw; # won't work anymore will only create HTTP::Exception::500 till HTTP::Exception::510. In theory this should save some memory, but I don't have any numbers, that back up this claim. You can load multiple ranges use HTTP::Exception qw(3XX 4XX 5XX); And there are aliases for ranges use HTTP::Exception qw(CLIENT_ERROR) The following aliases exist and load the specified ranges: REDIRECTION => 3XX CLIENT_ERROR => 4XX SERVER_ERROR => 5XX ERROR => 4XX 5XX ALL => 1XX 2XX 3XX 4XX 5XX And of course, you can load multiple aliased ranges use HTTP::Exception qw(REDIRECTION ERROR) ALL is the same as not specifying any specific range. # the same use HTTP::Exception qw(ALL); use HTTP::Exception; =head1 ACCESSORS (READONLY) =head2 code A valid HTTP-Statuscode. See L for information on what codes exist. =head2 is_info Return TRUE if C<$self->code> is an I status code (1xx). This class of status code indicates a provisional response which can't have any content. =head2 is_success Return TRUE if C<$self->code> is a I status code (2xx). =head2 is_redirect Return TRUE if C<$self->code> is a I status code (3xx). This class if status code indicates that further action needs to be taken by the user agent in order to fulfill the request. =head2 is_error Return TRUE if C<$self->code> is an I status code (4xx or 5xx). The function return TRUE for both client error or a server error status codes. =head2 is_client_error Return TRUE if C<$self->code> is an I status code (4xx). This class of status code is intended for cases in which the client seems to have erred. =head2 is_server_error Return TRUE if C<$self->code> is an I status code (5xx). This class of status codes is intended for cases in which the server is aware that it has erred or is incapable of performing the request. I, so check back there and alert me of changes.> =head1 FIELDS Fields are the same as ACCESSORS except they can be set. Either you set them during Exception creation (->new) or Exception throwing (->throw). HTTP::Exception->new(200, status_message => "Everything's fine"); HTTP::Exception::200->new(status_message => "Everything's fine"); HTTP::Exception::OK->new(status_message => "Everything's fine"); HTTP::Exception->throw(200, status_message => "Everything's fine"); HTTP::Exception::200->throw(status_message => "Everything's fine"); HTTP::Exception::OK->throw(status_message => "Everything's fine"); Catch them in your Webframework like this eval { ... } if (my $e = HTTP::Exception->caught) { print $e->code; # 200 print $e->status_message # "Everything's fine" instead of the usual ok } =head2 status_message B The HTTP-Statusmessage as provided by L A Message, that represents the Execptions' Status for Humans. =head1 PLACK HTTP::Exception can be used with L. But HTTP::Exception does not depend on L, you can use it anywhere else. It just plays nicely with L. =head1 COMPLETENESS For the sake of completeness, HTTP::Exception provides exceptions for non-error-http-statuscodes. This means you can do HTTP::Exception->throw(200); which throws an Exception of type OK. Maybe useless, but complete. A more realworld-example would be a redirection # all are exactly the same HTTP::Exception->throw(301, location => 'google.com'); HTTP::Exception::301->throw(location => 'google.com'); HTTP::Exception::MOVED_PERMANENTLY->throw(location => 'google.com'); =head1 CAVEATS The HTTP::Exception-Subclass-Creation relies on L. It's possible that the Subclasses change, when HTTP::Status' constants are changed. New Subclasses are created automatically, when constants are added to HTTP::Status. That means in turn, that Subclasses disappear, when constants are removed from L. Some constants were added to L' in February 2012. As a result HTTP::Exception broke. But that was the result of uncareful coding on my side. I think, that breaking changes are now quite unlikely. =head1 AUTHOR Thomas Mueller, C<< >> =head1 SEE ALSO =head2 L, L Consult Exception::Class' documentation for the Exception-Mechanism and Exception::Class::Base' docs for a list of methods our caught Exception is also capable of. =head2 L Constants, Statuscodes and Statusmessages =head2 L, especially L Have a look at Plack, because it rules in general. In the first place, this Module was written as the companion for L, but since it doesn't depend on Plack, you can use it anywhere else, too. =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc HTTP::Exception You can also look for information at: =over 4 =item * RT: CPAN's request tracker L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * Search CPAN L =back =head1 LICENSE AND COPYRIGHT Copyright 2010 Thomas Mueller. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. =cut 07-status_messages.t100755001750001750 607112277252372 17362 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use HTTP::Exception; # double checking synonym for status_message and message my $e = HTTP::Exception->new(404, status_message => 'Nothing here'); is $e->status_message, 'Nothing here', 'status message with H::E + new '; is $e->message, 'Nothing here', 'message with H::E + new '; my $e1 = HTTP::Exception->new(404, message => 'Nothing here'); is $e1->status_message, 'Nothing here', 'status message with H::E + new '; is $e1->message, 'Nothing here', 'message with H::E + new '; my $e2 = HTTP::Exception::404->new(status_message => 'Nothing here'); is $e2->status_message, 'Nothing here', 'status message with H::E::404 + new'; is $e2->message, 'Nothing here', 'message with H::E::404 + new'; my $e21 = HTTP::Exception::404->new(message => 'Nothing here'); is $e21->status_message, 'Nothing here', 'status message with H::E::404 + new'; is $e21->message, 'Nothing here', 'message with H::E::404 + new'; my $e3 = HTTP::Exception::NOT_FOUND->new(status_message => 'Nothing here'); is $e3->status_message, 'Nothing here', 'status message with H::E::NOT_FOUND + new'; is $e3->message, 'Nothing here', 'message with H::E::NOT_FOUND + new'; my $e31 = HTTP::Exception::NOT_FOUND->new(message => 'Nothing here'); is $e31->status_message, 'Nothing here', 'status message with H::E::NOT_FOUND + new'; is $e31->message, 'Nothing here', 'message with H::E::NOT_FOUND + new'; my $e4 = HTTP::Exception::404->new(); $e4->status_message('Nothing here too'); is $e4->status_message, 'Nothing here too', 'status_message set after ->new'; is $e4->message, 'Nothing here too', 'message set after ->new'; $e4->message('Nothing here'); is $e4->status_message, 'Nothing here', 'status_message set after ->new'; is $e4->message, 'Nothing here', 'message set after ->new'; my @tests = ( sub { $e4->throw; }, sub { HTTP::Exception->throw(404, status_message => 'Nothing here'); }, sub { HTTP::Exception::404->throw(status_message => 'Nothing here'); }, sub { HTTP::Exception::NOT_FOUND->throw(status_message => 'Nothing here'); }, sub { HTTP::Exception->throw(404, message => 'Nothing here'); }, sub { HTTP::Exception::404->throw(message => 'Nothing here'); }, sub { HTTP::Exception::NOT_FOUND->throw(message => 'Nothing here'); }, ); for my $test (@tests) { eval { $test->() }; my $e5 = HTTP::Exception->caught; my $e6 = HTTP::Exception::4XX->caught; my $e7 = HTTP::Exception::404->caught; my $e8 = HTTP::Exception::NOT_FOUND->caught; my $e9 = Exception::Class->caught; for my $accessor (qw~status_message message~) { is $e5->$accessor, 'Nothing here', "$accessor with H::E"; is $e6->$accessor, 'Nothing here', "$accessor with H::E::4XX"; is $e7->$accessor, 'Nothing here', "$accessor with H::E::404"; is $e8->$accessor, 'Nothing here', "$accessor with H::E::NOT_FOUND"; is $e9->$accessor, 'Nothing here', "$accessor with Exception::Class"; } } done_testing;29-load_redirection.t100755001750001750 27412277252372 17441 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use lib 't/lib'; use Test::HTTP::Exception::Ranges; use HTTP::Exception qw(REDIRECTION); Test::HTTP::Exception::Ranges::test_range_ok(qw~3XX~); done_testing;release000755001750001750 012277252372 15200 5ustar00tmutmu000000000000HTTP-Exception-0.04006/xtpod-syntax.t100755001750001750 22012277252372 17610 0ustar00tmutmu000000000000HTTP-Exception-0.04006/xt/release#!perl # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use Test::More; use Test::Pod 1.41; all_pod_files_ok(); 26-load_server_error.t100755001750001750 27512277252372 17647 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use lib 't/lib'; use Test::HTTP::Exception::Ranges; use HTTP::Exception qw(SERVER_ERROR); Test::HTTP::Exception::Ranges::test_range_ok(qw~5XX~); done_testing;27-load_client_error.t100755001750001750 27512277252372 17620 0ustar00tmutmu000000000000HTTP-Exception-0.04006/tuse strict; use Test::More; use lib 't/lib'; use Test::HTTP::Exception::Ranges; use HTTP::Exception qw(CLIENT_ERROR); Test::HTTP::Exception::Ranges::test_range_ok(qw~4XX~); done_testing;Exception000755001750001750 012277252372 16410 5ustar00tmutmu000000000000HTTP-Exception-0.04006/lib/HTTP1XX.pm100755001750001750 363412277252372 17537 0ustar00tmutmu000000000000HTTP-Exception-0.04006/lib/HTTP/Exceptionpackage HTTP::Exception::1XX; $HTTP::Exception::1XX::VERSION = '0.04006'; use strict; use base 'HTTP::Exception::Base'; sub is_info () { 1 } sub is_success () { '' } sub is_redirect () { '' } sub is_error () { '' } sub is_client_error () { '' } sub is_server_error () { '' } 1; =head1 NAME HTTP::Exception::1XX - Base Class for 1XX (info) Exceptions =head1 VERSION version 0.04006 =head1 SYNOPSIS nothing here yet =head1 DESCRIPTION This package is the base class for all 1XX (info) Exceptions. This makes adding features for a range of exceptions easier. DON'T USE THIS PACKAGE DIRECTLY. 'use HTTP::Exception' does this for you. =head1 ADDITIONAL FIELDS Fields, that 1XX-Exceptions provide over HTTP::Exceptions. =head1 AUTHOR Thomas Mueller, C<< >> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc HTTP::Exception::Base You can also look for information at: =over 4 =item * RT: CPAN's request tracker L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * Search CPAN L =back =head1 LICENSE AND COPYRIGHT Copyright 2010 Thomas Mueller. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. =cut 2XX.pm100755001750001750 364112277252372 17536 0ustar00tmutmu000000000000HTTP-Exception-0.04006/lib/HTTP/Exceptionpackage HTTP::Exception::2XX; $HTTP::Exception::2XX::VERSION = '0.04006'; use strict; use base 'HTTP::Exception::Base'; sub is_info () { '' } sub is_success () { 1 } sub is_redirect () { '' } sub is_error () { '' } sub is_client_error () { '' } sub is_server_error () { '' } 1; =head1 NAME HTTP::Exception::2XX - Base Class for 2XX (success) Exceptions =head1 VERSION version 0.04006 =head1 SYNOPSIS nothing here yet =head1 DESCRIPTION This package is the base class for all 2XX (success) Exceptions. This makes adding features for a range of exceptions easier. DON'T USE THIS PACKAGE DIRECTLY. 'use HTTP::Exception' does this for you. =head1 ADDITIONAL FIELDS Fields, that 2XX-Exceptions provide over HTTP::Exceptions. =head1 AUTHOR Thomas Mueller, C<< >> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc HTTP::Exception::Base You can also look for information at: =over 4 =item * RT: CPAN's request tracker L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * Search CPAN L =back =head1 LICENSE AND COPYRIGHT Copyright 2010 Thomas Mueller. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. =cut 3XX.pm100755001750001750 523712277252372 17542 0ustar00tmutmu000000000000HTTP-Exception-0.04006/lib/HTTP/Exceptionpackage HTTP::Exception::3XX; $HTTP::Exception::3XX::VERSION = '0.04006'; use strict; use base 'HTTP::Exception::Base'; sub is_info () { '' } sub is_success () { '' } sub is_redirect () { 1 } sub is_error () { '' } sub is_client_error () { '' } sub is_server_error () { '' } sub location { $_[0]->{location} = $_[1] if (@_ > 1); return $_[0]->{location}; } sub Fields { my $self = shift; my @fields = $self->SUPER::Fields(); # TODO: default-value or required, maybe alter new push @fields, qw(location); # additional Fields return @fields; } 1; =head1 NAME HTTP::Exception::3XX - Base Class for 3XX (redirect) Exceptions =head1 VERSION version 0.04006 =head1 SYNOPSIS use HTTP::Exception; # all are exactly the same HTTP::Exception->throw(301, location => 'google.com'); HTTP::Exception::301->throw(location => 'google.com'); HTTP::Exception::MOVED_PERMANENTLY->throw(location => 'google.com'); # and in your favourite Webframework eval { ... } if (my $e = HTTP::Exception::301->caught) { my $self->req->redirect($e->location); } =head1 DESCRIPTION This package is the base class for all 3XX (redirect) Exceptions. This makes adding features for a range of exceptions easier. DON'T USE THIS PACKAGE DIRECTLY. 'use HTTP::Exception' does this for you. =head1 ADDITIONAL FIELDS Fields, that 3XX-Exceptions provide over HTTP::Exceptions. =head2 location Indicates, where the browser is being redirected to. =head1 AUTHOR Thomas Mueller, C<< >> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc HTTP::Exception::Base You can also look for information at: =over 4 =item * RT: CPAN's request tracker L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * Search CPAN L =back =head1 LICENSE AND COPYRIGHT Copyright 2010 Thomas Mueller. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. =cut 4XX.pm100755001750001750 365412277252372 17544 0ustar00tmutmu000000000000HTTP-Exception-0.04006/lib/HTTP/Exceptionpackage HTTP::Exception::4XX; $HTTP::Exception::4XX::VERSION = '0.04006'; use strict; use base 'HTTP::Exception::Base'; sub is_info () { '' } sub is_success () { '' } sub is_redirect () { '' } sub is_error () { 1 } sub is_client_error () { 1 } sub is_server_error () { '' } 1; =head1 NAME HTTP::Exception::4XX - Base Class for 4XX (client error) Exceptions =head1 VERSION version 0.04006 =head1 SYNOPSIS nothing here yet =head1 DESCRIPTION This package is the base class for all 4XX (client error) Exceptions. This makes adding features for a range of exceptions easier. DON'T USE THIS PACKAGE DIRECTLY. 'use HTTP::Exception' does this for you. =head1 ADDITIONAL FIELDS Fields, that 4XX-Exceptions provide over HTTP::Exceptions. =head1 AUTHOR Thomas Mueller, C<< >> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc HTTP::Exception::Base You can also look for information at: =over 4 =item * RT: CPAN's request tracker L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * Search CPAN L =back =head1 LICENSE AND COPYRIGHT Copyright 2010 Thomas Mueller. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. =cut 5XX.pm100755001750001750 365412277252372 17545 0ustar00tmutmu000000000000HTTP-Exception-0.04006/lib/HTTP/Exceptionpackage HTTP::Exception::5XX; $HTTP::Exception::5XX::VERSION = '0.04006'; use strict; use base 'HTTP::Exception::Base'; sub is_info () { '' } sub is_success () { '' } sub is_redirect () { '' } sub is_error () { 1 } sub is_client_error () { '' } sub is_server_error () { 1 } 1; =head1 NAME HTTP::Exception::5XX - Base Class for 5XX (server error) Exceptions =head1 VERSION version 0.04006 =head1 SYNOPSIS nothing here yet =head1 DESCRIPTION This package is the base class for all 5XX (server error) Exceptions. This makes adding features for a range of exceptions easier. DON'T USE THIS PACKAGE DIRECTLY. 'use HTTP::Exception' does this for you. =head1 ADDITIONAL FIELDS Fields, that 5XX-Exceptions provide over HTTP::Exceptions. =head1 AUTHOR Thomas Mueller, C<< >> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc HTTP::Exception::Base You can also look for information at: =over 4 =item * RT: CPAN's request tracker L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * Search CPAN L =back =head1 LICENSE AND COPYRIGHT Copyright 2010 Thomas Mueller. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. =cut pod-coverage.t100755001750001750 33412277252372 20063 0ustar00tmutmu000000000000HTTP-Exception-0.04006/xt/release#!perl # 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' }); Base.pm100755001750001750 607312277252372 17771 0ustar00tmutmu000000000000HTTP-Exception-0.04006/lib/HTTP/Exceptionpackage HTTP::Exception::Base; $HTTP::Exception::Base::VERSION = '0.04006'; use strict; use base 'Exception::Class::Base'; ################################################################################ # roll our own new, because of message # error, message and status_message are synonyms sub new { my $proto = shift; my $class = ref $proto || $proto; my %params = @_; $params{status_message} = delete $params{message} if (exists $params{message}); $class->SUPER::new(%params); } ################################################################################ # used by Exception::Class for as_string sub full_message { shift->status_message } ################################################################################ # TODO default-value/required fields, maybe moose? but maybe a moose is too heavy # but on the other hand, handmade accessors suck sub status_message { $_[0]->{status_message} = $_[1] if (@_ > 1); return $_[0]->{status_message} ||= $_[0]->_status_message; } *message = \&status_message; *error = \&status_message; ################################################################################ # though Exception::Class::Base does have fields, the Fields-Accessor returns () # so no shift->SUPER::Fields is required sub Fields { qw(status_message) } 1; =head1 NAME HTTP::Exception::Base - Base Class for exception classes created by HTTP::Exception =head1 VERSION version 0.04006 =head1 DESCRIPTION This Class is a Base class for exception classes created by HTTP::Exception. It inherits from L. Please refer to the Documentation of L for methods and accessors a HTTP::Exception inherits. You won't use this Class directly, so refer to L and L. The methods and attributes this Class provides over Exception::Class::Base are described there. =head1 AUTHOR Thomas Mueller, C<< >> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc HTTP::Exception::Base You can also look for information at: =over 4 =item * RT: CPAN's request tracker L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * Search CPAN L =back =head1 LICENSE AND COPYRIGHT Copyright 2010 Thomas Mueller. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. =cut Loader.pm100755001750001750 1273212277252372 20344 0ustar00tmutmu000000000000HTTP-Exception-0.04006/lib/HTTP/Exceptionpackage HTTP::Exception::Loader; $HTTP::Exception::Loader::VERSION = '0.04006'; use strict; use warnings; use HTTP::Exception::Base; use HTTP::Exception::1XX; use HTTP::Exception::2XX; use HTTP::Exception::3XX; use HTTP::Exception::4XX; use HTTP::Exception::5XX; use HTTP::Status; ################################################################################ # little bit messy, but solid # - first create packages for Exception::Class, so it can create them on its own # - then extend those packages by putting methods into the same namespace sub _make_exceptions { my %tags = @_; my (@http_statuses, @exception_classes); { no strict 'refs'; @http_statuses = grep { /^HTTP_/ } (keys %{"HTTP::Status::"}); } my $code = ''; for my $http_status (@http_statuses) { my $statuscode = HTTP::Status->$http_status; my $http_status_message = HTTP::Status::status_message($statuscode); my $statuscode_range = $statuscode; # remove HTTP_ for exception classname $http_status =~ s/^HTTP_//; # replace the last 2 digits with XX for basename creation $statuscode_range =~ s/\d{2}$/XX/; # poor mans escaping, because of HTTP: 418 / I'm a teapot :\ $http_status_message =~ s/'/\\'/g; # only create requested classes next unless (exists $tags{$statuscode_range}); my $package_name_code = 'HTTP::Exception::'.$statuscode; my $package_name_base = 'HTTP::Exception::'.$statuscode_range; my $package_name_message = 'HTTP::Exception::'.$http_status; # create a Package like HTTP::Exception::404, # but also a Package HTTP::Exception::NOT_FOUND, # which inherits from HTTP::Exception::404 # HTTP::Exception::404 inherits from HTTP::Exception::4XX push @exception_classes, $package_name_code => {isa => $package_name_base}, $package_name_message => {isa => $package_name_code}; # TODO check whether evaled subs with a ()-prototype are compiled to constants $code .= qq~ package $package_name_code; sub code () { $statuscode } sub _status_message () { '$http_status_message' } package $package_name_message; use Scalar::Util qw(blessed); sub caught { my \$self = shift; my \$e = \$@; return \$e if (blessed \$e && \$e->isa('$package_name_code')); \$self->SUPER::caught(\@_); } ~; } # RT https://rt.cpan.org/Ticket/Display.html?id=79021 # silence warnings about "subroutine redefined" in a mod_perl environment { no warnings 'redefine'; eval $code; } return @exception_classes; } ################################################################################ sub import { my ($class, @tags) = @_; my %tags; if (@tags) { my %known_tags = ( '1XX' => ['1XX'], '2XX' => ['2XX'], '3XX' => ['3XX'], '4XX' => ['4XX'], '5XX' => ['5XX'], 'REDIRECTION' => ['3XX'], 'CLIENT_ERROR' => ['4XX'], 'SERVER_ERROR' => ['5XX'], 'ERROR' => ['4XX', '5XX'], 'ALL' => [qw~1XX 2XX 3XX 4XX 5XX~], ); for my $import_tag (@tags) { next unless ($known_tags{$import_tag}); $tags{$_} = undef for (@{ $known_tags{$import_tag} }); } } else { @tags{qw~1XX 2XX 3XX 4XX 5XX~} = (); } require Exception::Class; Exception::Class->import( 'HTTP::Exception' => { isa => 'HTTP::Exception::Base' }, _make_exceptions(%tags) ); } 1; =head1 NAME HTTP::Exception::Loader - Creates HTTP::Exception subclasses =head1 VERSION version 0.04006 =head1 DESCRIPTION This Class Creates all L subclasses. DON'T USE THIS PACKAGE DIRECTLY. 'use HTTP::Exception' does this for you. This Package does its job as soon as you call 'use HTTP::Exception'. Please refer to the Documentation of L. The Naming Scheme of all subclasses created, as well as the caveats can be found there. =head1 AUTHOR Thomas Mueller, C<< >> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc HTTP::Exception::Base You can also look for information at: =over 4 =item * RT: CPAN's request tracker L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * Search CPAN L =back =head1 LICENSE AND COPYRIGHT Copyright 2010 Thomas Mueller. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. =cut Exception000755001750001750 012277252372 17572 5ustar00tmutmu000000000000HTTP-Exception-0.04006/t/lib/Test/HTTPRanges.pm100755001750001750 151412277252372 21513 0ustar00tmutmu000000000000HTTP-Exception-0.04006/t/lib/Test/HTTP/Exceptionpackage Test::HTTP::Exception::Ranges; use strict; use Test::More; ################################################################################ sub test_range_ok { my @ranges = @_; s/XX$/00/ for (@ranges); my %instantiable; @instantiable{@ranges} = (); for my $status_code (100, 200, 300, 400, 500) { my $e; eval { $e = "HTTP::Exception::$status_code"->new; }; if (exists $instantiable{$status_code}) { ok defined $e, "$status_code is instantiable"; } else { ok !defined $e, "$status_code is not instantiable"; } } } ################################################################################ sub simple_test_range_ok { my @ranges = @_; require HTTP::Exception; HTTP::Exception->import(@ranges); test_range_ok(@ranges); } 1;