pax_global_header00006660000000000000000000000064123141532630014512gustar00rootroot0000000000000052 comment=3aef98e23d0db7cfdaf3251eab3d41c658c22884 perl-Amon2-Lite-0.12/000075500000000000000000000000001231415326300142415ustar00rootroot00000000000000perl-Amon2-Lite-0.12/.gitignore000064400000000000000000000003101231415326300162230ustar00rootroot00000000000000Makefile inc/ .c ppport.h *.sw[po] *.bak *.old Build _build/ xshelper.h tags pm_to_blib blib/ META.yml MYMETA.* META.yml README /Amon2-Lite-* /.build /_build_params /Build !Build/ !META.json !LICENSE perl-Amon2-Lite-0.12/Build.PL000064400000000000000000000035131231415326300155370ustar00rootroot00000000000000# ========================================================================= # THIS FILE IS AUTOMATICALLY GENERATED BY MINILLA. # DO NOT EDIT DIRECTLY. # ========================================================================= use 5.008_001; use strict; use warnings; use utf8; use Module::Build; use File::Basename; use File::Spec; use CPAN::Meta; use CPAN::Meta::Prereqs; my %args = ( license => 'perl', dynamic_config => 0, configure_requires => { 'Module::Build' => 0.38, }, name => 'Amon2-Lite', module_name => 'Amon2::Lite', allow_pureperl => 0, script_files => [glob('script/*'), glob('bin/*')], c_source => [qw()], PL_files => {}, test_files => ((-d '.git' || $ENV{RELEASE_TESTING}) && -d 'xt') ? 't/ xt/' : 't/', recursive_test_files => 1, ); if (-d 'share') { $args{share_dir} = 'share'; } my $builder = Module::Build->subclass( class => 'MyBuilder', code => q{ sub ACTION_distmeta { die "Do not run distmeta. Install Minilla and `minil install` instead.\n"; } sub ACTION_installdeps { die "Do not run installdeps. Run `cpanm --installdeps .` instead.\n"; } } )->new(%args); $builder->create_build_script(); my $mbmeta = CPAN::Meta->load_file('MYMETA.json'); my $meta = CPAN::Meta->load_file('META.json'); my $prereqs_hash = CPAN::Meta::Prereqs->new( $meta->prereqs )->with_merged_prereqs( CPAN::Meta::Prereqs->new($mbmeta->prereqs) )->as_string_hash; my $mymeta = CPAN::Meta->new( { %{$meta->as_struct}, prereqs => $prereqs_hash } ); print "Merging cpanfile prereqs to MYMETA.yml\n"; $mymeta->save('MYMETA.yml', { version => 1.4 }); print "Merging cpanfile prereqs to MYMETA.json\n"; $mymeta->save('MYMETA.json', { version => 2 }); perl-Amon2-Lite-0.12/Changes000064400000000000000000000034161231415326300155400ustar00rootroot00000000000000Revision history for Perl extension Amon2::Lite {{$NEXT}} 0.12 2014-03-25T01:06:43Z - Fix default DB name to expand environment name (moznion) - Fixed testing issues (Kosuke Asami) 0.11 2013-10-08T23:29:10Z - Amon2::Lite with Text::Xslate 2.0010- gets Perl 5.18+ issue. Just updated deps. ref. http://blog.64p.org/entry/2013/10/08/093236 (tokuhirom) - Tiny fix for Amon2 5.00 compatibility. (tokuhirom) 0.10 2013-08-14T01:14:41Z - minil migrate (tokuhirom) 0.09 - Allows "get '/'" and "post '/'" in same router. (Reported by mattn++) 0.08 [bug fix] commit 60372b2ac2af6d6a2b0683626e1bf7650e7b5b60 Author: Syohei YOSHIDA Date: Thu Jul 12 00:27:23 2012 +0900 fix typo lib/Amon2/Setup/Flavor/Lite.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 0.07 [BUG FIX] - 'any' was broken at 0.06 0.06 * e26e2d3 better coding style * 936a1e4 better static file handling * cbe3fca puts x-nantoka headers by default * b857d56 simplified code * 8e20caa added enable_session method * added enable_middleware method * Return 405 Method Not Allowed if it's not allowed(Old impl returns 404) * 52a9094 docs about session 0.05 [SETUP FLAVOR] * c4b5db2 ignore .gitignore files * d6e0163 better html skelton * eac6045 setup bootstrap and jquery by default. [DOC ENHANCEMENTS] * a27cd94 link to example code 0.04 - added 'handle_static' option. - remove some deps. 0.03 - added 'template_options' method. (suggested by gfx) 0.02 - fixed incompatibility with latest Amon2::Lite. Amon2::Lite should not be use Bridge::Star. 0.01 Mon Nov 14 09:24:15 2011 - original version perl-Amon2-Lite-0.12/LICENSE000064400000000000000000000440621231415326300152540ustar00rootroot00000000000000This software is copyright (c) 2012 by Tokuhiro Matsuno Etokuhirom AAJKLFJEF@ GMAIL COME. 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 Tokuhiro Matsuno Etokuhirom AAJKLFJEF@ GMAIL COME. 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 Tokuhiro Matsuno Etokuhirom AAJKLFJEF@ GMAIL COME. 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 perl-Amon2-Lite-0.12/META.json000064400000000000000000000052041231415326300156630ustar00rootroot00000000000000{ "abstract" : "Sinatra-ish framework on Amon2!", "author" : [ "Tokuhiro Matsuno " ], "dynamic_config" : 0, "generated_by" : "Minilla/v0.12.0, CPAN::Meta::Converter version 2.133380", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Amon2-Lite", "no_index" : { "directory" : [ "t", "xt", "inc", "share", "eg", "examples", "author", "builder" ] }, "prereqs" : { "configure" : { "requires" : { "CPAN::Meta" : "0", "CPAN::Meta::Prereqs" : "0", "Module::Build" : "0.38" } }, "develop" : { "requires" : { "Test::CPAN::Meta" : "0", "Test::MinimumVersion" : "0.10108", "Test::Pod" : "1.41", "Test::Spellunker" : "v0.2.7" } }, "runtime" : { "requires" : { "Amon2" : "3.25", "Amon2::Config::Simple" : "0", "Amon2::Setup::Flavor" : "0", "Amon2::Web" : "0", "Data::Section::Simple" : "0.03", "Plack::App::File" : "0", "Plack::Middleware::Session" : "0", "Plack::Session::State::Cookie" : "0", "Router::Simple" : "0.13", "Text::Xslate" : "2.0010", "Text::Xslate::Bridge::TT2Like" : "0.00010", "parent" : "0", "perl" : "5.008008" } }, "test" : { "requires" : { "App::Prove" : "0", "File::Temp" : "0", "HTTP::Message::PSGI" : "0", "HTTP::Request::Common" : "0", "HTTP::Response" : "0", "Plack::Test" : "0", "Plack::Util" : "0", "Test::More" : "0.98", "Test::Requires" : "0", "Test::WWW::Mechanize" : "0", "Tiffany" : "0" } } }, "release_status" : "unstable", "resources" : { "bugtracker" : { "web" : "https://github.com/tokuhirom/Amon2-Lite/issues" }, "homepage" : "https://github.com/tokuhirom/Amon2-Lite", "repository" : { "type" : "git", "url" : "git://github.com/tokuhirom/Amon2-Lite.git", "web" : "https://github.com/tokuhirom/Amon2-Lite" } }, "version" : "0.12", "x_contributors" : [ "Syohei YOSHIDA ", "Kosuke Asami ", "moznion ", "Tokuhiro Matsuno " ] } perl-Amon2-Lite-0.12/README.md000064400000000000000000000075701231415326300155310ustar00rootroot00000000000000# NAME Amon2::Lite - Sinatra-ish framework on Amon2! # SYNOPSIS use Amon2::Lite; get '/' => sub { my ($c) = @_; return $c->render('index.tt'); }; __PACKAGE__->to_app(); __DATA__ @@ index.tt Hello # DESCRIPTION This is a Sinatra-ish wrapper for Amon2. __THIS MODULE IS BETA STATE. API MAY CHANGE WITHOUT NOTICE__. # FUNCTIONS - `any(\@methods, $path, \&code)` - `any($path, \&code)` Register new route for router. - `get($path, $code->($c))` Register new route for router. - `post($path, $code->($c))` Register new route for router. - `__PACKAGE__->load_plugin($name, \%opts)` Load a plugin to the context object. - \[EXPERIMENTAL\] `__PACKAGE__->enable_session(%args)` This method enables [Plack::Middleware::Session](https://metacpan.org/pod/Plack::Middleware::Session). `%args` would be pass to enabled to `Plack::Middleware::Session->new`. The default state class is [Plack::Session::State::Cookie](https://metacpan.org/pod/Plack::Session::State::Cookie), and store class is [Plack::Session::Store::File](https://metacpan.org/pod/Plack::Session::Store::File). This option enables a response filter, that adds ` Cache-Control: private ` header. - \[EXPERIMENTAL\] `__PACKAGE__->enable_middleware($klass, %args)` __PACKAGE__->enable_middleware('Plack::Middleware::XFramework', framework => 'Amon2::Lite'); Enable the Plack middlewares. - `__PACKAGE__->to_app(%args)` Create new PSGI application instance. There is a options. - `no_x_content_type_options : default false` __PACKAGE__->to_app(no_x_content_type_options => 1); Amon2::Lite puts `X-Content-Type-Options` header by default for security reason. You can disable this feature by this option. - `no_x_frame_options` __PACKAGE__->to_app(no_x_frame_options => 1); Amon2::Lite puts `X-Frame-Options: DENY` header by default for security reason. You can disable this feature by this option. # FAQ - How can I configure the options for Xslate? You can provide a constructor arguments by configuration. Write following lines on your app.psgi. __PACKAGE__->template_options( syntax => 'Kolon', ); - How can I use other template engines instead of Text::Xslate? You can use any template engine with Amon2::Lite. You can overwrite create\_view method same as normal Amon2. This is a example to use [Text::MicroTemplate::File](https://metacpan.org/pod/Text::MicroTemplate::File). use Tiffany::Text::MicroTemplate::File; sub create_view { Tiffany::Text::MicroTemplate::File->new(+{ include_path => ['./tmpl/'] }) } - How can I handle static files? If you pass the 'handle\_static' option to 'to\_app' method, Amon2::Lite handles /static/ path to ./static/ directory. use Amon2::Lite; __PACKAGE__->to_app(handle_static => 1); - Where is a example codes? There is a tiny TinyURL example: [https://github.com/tokuhirom/MyTinyURL/blob/master/app.psgi](https://github.com/tokuhirom/MyTinyURL/blob/master/app.psgi). - How can I use session? You can enable session by `__PACKAGE__->enable_session()`. And you can access the session object by `$c->session` accessor. use Amon2::Lite; get '/' => sub { my $c = shift; my $cnt = $c->session->get('cnt') || 1; $c->session->set('cnt' => $cnt+1); return $c->create_response(200, [], [$cnt]); }; __PACKAGE__->enable_session(); # __PACKAGE__->to_app(); # AUTHOR Tokuhiro Matsuno # SEE ALSO # LICENSE Copyright (C) Tokuhiro Matsuno This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl-Amon2-Lite-0.12/cpanfile000064400000000000000000000015141231415326300157460ustar00rootroot00000000000000requires 'perl', '5.008008'; requires 'Amon2', '3.25'; requires 'Amon2::Config::Simple'; requires 'Amon2::Setup::Flavor'; requires 'Amon2::Web'; requires 'Data::Section::Simple', '0.03'; requires 'parent'; requires 'Plack::App::File'; requires 'Plack::Middleware::Session'; requires 'Plack::Session::State::Cookie'; requires 'Router::Simple', '0.13'; requires 'Text::Xslate', '2.0010'; # 2.0010+ gets Perl 5.18+ compatibility requires 'Text::Xslate::Bridge::TT2Like', '0.00010'; on test => sub { requires 'Test::More', '0.98'; requires 'Test::Requires'; requires 'App::Prove'; requires 'File::Temp'; requires 'HTTP::Message::PSGI'; requires 'HTTP::Request::Common'; requires 'HTTP::Response'; requires 'Plack::Test'; requires 'Plack::Util'; requires 'Test::WWW::Mechanize'; requires 'Tiffany'; }; perl-Amon2-Lite-0.12/lib/000075500000000000000000000000001231415326300150075ustar00rootroot00000000000000perl-Amon2-Lite-0.12/lib/Amon2/000075500000000000000000000000001231415326300157635ustar00rootroot00000000000000perl-Amon2-Lite-0.12/lib/Amon2/Lite.pm000064400000000000000000000247761231415326300172360ustar00rootroot00000000000000package Amon2::Lite; use strict; use warnings; use 5.008008; our $VERSION = '0.12'; use parent qw/Amon2 Amon2::Web/; use Router::Simple 0.04; use Text::Xslate; use Text::Xslate::Bridge::TT2Like; use File::Spec; use File::Basename qw(dirname); use Data::Section::Simple (); use Amon2::Config::Simple; my $COUNTER; sub import { my $class = shift; no strict 'refs'; my $router = Router::Simple->new(); my $caller = caller(0); my $base_class = 'Amon2::Lite::_child_' . $COUNTER++; { no warnings; unshift @{"$base_class\::ISA"}, qw/Amon2 Amon2::Web/; unshift @{"$caller\::ISA"}, $base_class; } *{"$caller\::to_app"} = sub { my ($class, %opts) = @_; my $app = $class->Amon2::Web::to_app(); if (delete $opts{handle_static}) { my $vpath = Data::Section::Simple->new($caller)->get_data_section(); require Plack::App::File; my $orig_app = $app; my $app_file_1; my $app_file_2; my $root1 = File::Spec->catdir( dirname((caller(0))[1]), 'static' ); my $root2 = File::Spec->catdir( dirname((caller(0))[1]) ); $app = sub { my $env = shift; if ((my $content = $vpath->{$env->{PATH_INFO}}) && $env->{PATH_INFO} =~ m{^/}) { my $ct = Plack::MIME->mime_type($env->{PATH_INFO}); return [200, ['Content-Type' => $ct, 'Content-Length' => length($content)], [$content]]; } elsif ($env->{PATH_INFO} =~ qr{^(?:/robots\.txt|/favicon\.ico)$}) { $app_file_1 ||= Plack::App::File->new({ root => $root1 }); return $app_file_1->call($env); } elsif ($env->{PATH_INFO} =~ m{^/static/}) { $app_file_2 ||= Plack::App::File->new({ root => $root2 }); return $app_file_2->call($env); } else { return $orig_app->($env); } }; } if (my @middlewares = @{"${caller}::_MIDDLEWARES"}) { for my $middleware (@middlewares) { my ($klass, $args) = @$middleware; $klass = Plack::Util::load_class($klass, 'Plack::Middleware'); $app = $klass->wrap($app, %$args); } } unless ($opts{no_x_content_type_options}) { $class->add_trigger(AFTER_DISPATCH => sub { my ($c, $res) = @_; $res->header( 'X-Content-Type-Options' => 'nosniff' ); }); } unless ($opts{no_x_frame_options}) { $class->add_trigger(AFTER_DISPATCH => sub { my ($c, $res) = @_; $res->header( 'X-Frame-Options' => 'DENY' ); }); } return $app; }; *{"${base_class}::enable_middleware"} = sub { my ($class, $klass, %args) = @_; push @{"${caller}::_MIDDLEWARES"}, [$klass, \%args]; }; *{"${base_class}::enable_session"} = sub { my ($class, %args) = @_; $args{state} ||= do { require Plack::Session::State::Cookie; Plack::Session::State::Cookie->new(httponly => 1); # for security }; require Plack::Middleware::Session; $class->enable_middleware('Plack::Middleware::Session', %args); $class->add_trigger(AFTER_DISPATCH => sub { my ($c, $res) = @_; $res->header('Cache-Control' => 'private'); }); }; *{"$caller\::router"} = sub { $router }; # any [qw/get post delete/] => '/bye' => sub { ... }; # any '/bye' => sub { ... }; *{"$caller\::any"} = sub ($$;$) { my $pkg = caller(0); if (@_==3) { my ($methods, $pattern, $code) = @_; $router->connect( $pattern, {code => $code, method => [ map { uc $_ } @$methods ]}, {method => [map { uc $_ } @$methods]}, ); } else { my ($pattern, $code) = @_; $router->connect( $pattern, {code => $code}, ); } }; *{"$caller\::get"} = sub { $router->connect($_[0], {code => $_[1], method => ['GET', 'HEAD']}, {method => 'GET'}); }; *{"$caller\::post"} = sub { $router->connect($_[0], {code => $_[1], method => ['POST']}, {method => ['POST']}); }; *{"${base_class}\::dispatch"} = sub { my ($c) = @_; if (my $p = $router->match($c->request->env)) { return $p->{code}->( $c, $p ); } else { if ($router->method_not_allowed) { my $content = '405 Method Not Allowed'; return $c->create_response( 405, [ 'Content-Type' => 'text/plain; charset=utf-8', 'Content-Length' => length($content), ], [$content] ); } else { return $c->res_404(); } } }; my $tmpl_dir = File::Spec->catdir(dirname((caller(0))[1]), 'tmpl'); *{"${base_class}::create_view"} = sub { $base_class->template_options(); }; *{"${base_class}::template_options"} = sub { my ($class, %options) = @_; # using lazy loading to read __DATA__ section. my $vpath = Data::Section::Simple->new($caller)->get_data_section(); my %params = ( 'syntax' => 'TTerse', 'module' => [ 'Text::Xslate::Bridge::TT2Like' ], 'path' => [ $vpath, $tmpl_dir ], 'function' => { c => sub { Amon2->context() }, uri_with => sub { Amon2->context()->req->uri_with(@_) }, uri_for => sub { Amon2->context()->uri_for(@_) }, }, ); my $merge = sub { my ($stuff) = @_; for (qw(module path)) { if ($stuff->{$_}) { unshift @{$params{$_}}, @{delete $stuff->{$_}}; } } for (qw(function)) { if ($stuff->{$_}) { $params{$_} = +{ %{$params{$_}}, %{delete $stuff->{$_}} }; } } while (my ($k, $v) = each %$stuff) { $params{$k} = $v; } }; if (my $config = $caller->config->{'Text::Xslate'}) { $merge->($config); } if (%options) { $merge->(\%options); } my $xslate = Text::Xslate->new(%params); no warnings 'redefine'; *{"${caller}::create_view"} = sub { $xslate }; $xslate; }; if (-d File::Spec->catdir($caller->base_dir, 'config')) { *{"${base_class}::load_config"} = sub { Amon2::Config::Simple->load(shift) }; } else { *{"${base_class}::load_config"} = sub { +{ } }; } } 1; __END__ =for stopwords TinyURL =encoding utf8 =head1 NAME Amon2::Lite - Sinatra-ish framework on Amon2! =head1 SYNOPSIS use Amon2::Lite; get '/' => sub { my ($c) = @_; return $c->render('index.tt'); }; __PACKAGE__->to_app(); __DATA__ @@ index.tt Hello =head1 DESCRIPTION This is a Sinatra-ish wrapper for Amon2. B. =head1 FUNCTIONS =over 4 =item C<< any(\@methods, $path, \&code) >> =item C<< any($path, \&code) >> Register new route for router. =item C<< get($path, $code->($c)) >> Register new route for router. =item C<< post($path, $code->($c)) >> Register new route for router. =item C<< __PACKAGE__->load_plugin($name, \%opts) >> Load a plugin to the context object. =item [EXPERIMENTAL] C<< __PACKAGE__->enable_session(%args) >> This method enables L. C<< %args >> would be pass to enabled to C<< Plack::Middleware::Session->new >>. The default state class is L, and store class is L. This option enables a response filter, that adds C< Cache-Control: private > header. =item [EXPERIMENTAL] C<< __PACKAGE__->enable_middleware($klass, %args) >> __PACKAGE__->enable_middleware('Plack::Middleware::XFramework', framework => 'Amon2::Lite'); Enable the Plack middlewares. =item C<< __PACKAGE__->to_app(%args) >> Create new PSGI application instance. There is a options. =over 4 =item C<< no_x_content_type_options : default false >> __PACKAGE__->to_app(no_x_content_type_options => 1); Amon2::Lite puts C<< X-Content-Type-Options >> header by default for security reason. You can disable this feature by this option. =item C<< no_x_frame_options >> __PACKAGE__->to_app(no_x_frame_options => 1); Amon2::Lite puts C<< X-Frame-Options: DENY >> header by default for security reason. You can disable this feature by this option. =back =back =head1 FAQ =over 4 =item How can I configure the options for Xslate? You can provide a constructor arguments by configuration. Write following lines on your app.psgi. __PACKAGE__->template_options( syntax => 'Kolon', ); =item How can I use other template engines instead of Text::Xslate? You can use any template engine with Amon2::Lite. You can overwrite create_view method same as normal Amon2. This is a example to use L. use Tiffany::Text::MicroTemplate::File; sub create_view { Tiffany::Text::MicroTemplate::File->new(+{ include_path => ['./tmpl/'] }) } =item How can I handle static files? If you pass the 'handle_static' option to 'to_app' method, Amon2::Lite handles /static/ path to ./static/ directory. use Amon2::Lite; __PACKAGE__->to_app(handle_static => 1); =item Where is a example codes? There is a tiny TinyURL example: L. =item How can I use session? You can enable session by C<< __PACKAGE__->enable_session() >>. And you can access the session object by C<< $c->session >> accessor. use Amon2::Lite; get '/' => sub { my $c = shift; my $cnt = $c->session->get('cnt') || 1; $c->session->set('cnt' => $cnt+1); return $c->create_response(200, [], [$cnt]); }; __PACKAGE__->enable_session(); # __PACKAGE__->to_app(); =back =head1 AUTHOR Tokuhiro Matsuno Etokuhirom AAJKLFJEF@ GMAIL COME =head1 SEE ALSO =head1 LICENSE Copyright (C) Tokuhiro Matsuno This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut perl-Amon2-Lite-0.12/lib/Amon2/Setup/000075500000000000000000000000001231415326300170635ustar00rootroot00000000000000perl-Amon2-Lite-0.12/lib/Amon2/Setup/Flavor/000075500000000000000000000000001231415326300203145ustar00rootroot00000000000000perl-Amon2-Lite-0.12/lib/Amon2/Setup/Flavor/Lite.pm000064400000000000000000000110211231415326300215420ustar00rootroot00000000000000use strict; use warnings; use utf8; package Amon2::Setup::Flavor::Lite; use parent qw(Amon2::Setup::Flavor); sub run { my ($self) = @_; require Amon2::Lite; require Amon2; $self->{amon2_version} = $Amon2::VERSION; $self->{amon2_lite_version} = $Amon2::Lite::VERSION; $self->write_file('app.psgi', <<'...'); use strict; use warnings; use utf8; use File::Spec; use File::Basename; use lib File::Spec->catdir(dirname(__FILE__), 'extlib', 'lib', 'perl5'); use lib File::Spec->catdir(dirname(__FILE__), 'lib'); use Amon2::Lite; our $VERSION = '0.12'; # put your configuration here sub load_config { my $c = shift; my $mode = $c->mode_name || 'development'; +{ 'DBI' => [ "dbi:SQLite:dbname=$mode.db", '', '', ], } } get '/' => sub { my $c = shift; return $c->render('index.tt'); }; # load plugins __PACKAGE__->load_plugin('Web::CSRFDefender' => { post_only => 1, }); # __PACKAGE__->load_plugin('DBI'); # __PACKAGE__->load_plugin('Web::FillInFormLite'); # __PACKAGE__->load_plugin('Web::JSON'); __PACKAGE__->enable_session(); __PACKAGE__->to_app(handle_static => 1); __DATA__ @@ index.tt <% $module %>

<% $module %>

This is a <% $module %>
@@ /static/js/main.js @@ /static/css/main.css footer { text-align: right; } ... $self->write_file('Makefile.PL', <<'...'); use ExtUtils::MakeMaker; WriteMakefile( NAME => '<% $module %>', AUTHOR => 'Some Person ', VERSION_FROM => 'app.psgi', PREREQ_PM => { 'Amon2' => '<% $amon2_version %>', 'Amon2::Lite' => '<% $amon2_lite_version %>', 'Text::Xslate' => '1.5006', 'Plack::Session' => '0.14', }, MIN_PERL_VERSION => '5.008001', (-d 'xt' and $ENV{AUTOMATED_TESTING} || $ENV{RELEASE_TESTING}) ? ( test => { TESTS => 't/*.t xt/*.t', }, ) : (), ); ... $self->write_file('t/Util.pm', <<'...'); package t::Util; BEGIN { unless ($ENV{PLACK_ENV}) { $ENV{PLACK_ENV} = 'test'; } } use parent qw/Exporter/; use Test::More 0.96; our @EXPORT = qw//; { # utf8 hack. binmode Test::More->builder->$_, ":utf8" for qw/output failure_output todo_output/; no warnings 'redefine'; my $code = \&Test::Builder::child; *Test::Builder::child = sub { my $builder = $code->(@_); binmode $builder->output, ":utf8"; binmode $builder->failure_output, ":utf8"; binmode $builder->todo_output, ":utf8"; return $builder; }; } 1; ... $self->write_file('t/01_root.t', <<'...'); use strict; use warnings; use utf8; use t::Util; use Plack::Test; use Plack::Util; use Test::More; my $app = Plack::Util::load_psgi 'app.psgi'; test_psgi app => $app, client => sub { my $cb = shift; my $req = HTTP::Request->new(GET => 'http://localhost/'); my $res = $cb->($req); is $res->code, 200; diag $res->content if $res->code != 200; }; done_testing; ... $self->write_file('xt/03_pod.t', <<'...'); use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); ... $self->write_file('.gitignore', <<'...'); Makefile inc/ MANIFEST *.bak *.old nytprof.out nytprof/ *.db blib/ pm_to_blib META.json META.yml MYMETA.json MYMETA.yml ... } 1; __END__ =head1 NAME Amon2::Setup::Flavor::Lite - Amon2::Lite flavor =head1 SYNOPSIS % amon2-setup.pl --flavor=Lite MyApp =head1 DESCRIPTION This is a flavor for project using Amon2::Lite. =head1 AUTHOR Tokuhiro Matsuno perl-Amon2-Lite-0.12/t/000075500000000000000000000000001231415326300145045ustar00rootroot00000000000000perl-Amon2-Lite-0.12/t/00_compile.t000064400000000000000000000001071231415326300166160ustar00rootroot00000000000000use strict; use Test::More tests => 1; BEGIN { use_ok 'Amon2::Lite' } perl-Amon2-Lite-0.12/t/100_static/000075500000000000000000000000001231415326300163535ustar00rootroot00000000000000perl-Amon2-Lite-0.12/t/100_static/01_simple.t000064400000000000000000000021401231415326300203260ustar00rootroot00000000000000use strict; use warnings; use utf8; use Test::More; use Plack::Test; use Test::Requires qw/HTTP::Request::Common/, 'Data::Section::Simple'; my $app = do { use Amon2::Lite; get '/' => sub { shift->create_response(200, ['Content-Length' => 2], ['OK']) }; __PACKAGE__->to_app( handle_static => 1, ); }; test_psgi($app, sub { my $cb = shift; { my $res = $cb->(GET '/'); is $res->code, 200; is $res->content, 'OK'; is $res->content_length, 2; } subtest '/static/foo' => sub { my $res = $cb->(GET '/static/foo'); is $res->code, 200; is $res->content, "bar\n"; is $res->content_length, 4; }; { my $res = $cb->(GET '/robots.txt'); is $res->code, 200; is $res->content, "DENY *\n"; is $res->content_length, 7; } { my $res = $cb->(GET '/static/foo.js'); like $res->content, qr/function/; is $res->content_length, 20; is $res->content_type, 'application/javascript'; } }); done_testing; __DATA__ @@ /static/foo.js $(function () { }); perl-Amon2-Lite-0.12/t/100_static/static/000075500000000000000000000000001231415326300176425ustar00rootroot00000000000000perl-Amon2-Lite-0.12/t/100_static/static/foo000064400000000000000000000000041231415326300203420ustar00rootroot00000000000000bar perl-Amon2-Lite-0.12/t/100_static/static/robots.txt000064400000000000000000000000071231415326300217100ustar00rootroot00000000000000DENY * perl-Amon2-Lite-0.12/t/300_setup/000075500000000000000000000000001231415326300162265ustar00rootroot00000000000000perl-Amon2-Lite-0.12/t/300_setup/04_lite.t000064400000000000000000000006571231415326300176630ustar00rootroot00000000000000use strict; use warnings; use utf8; use Test::More; use t::TestFlavor; use Test::Requires 'JSON', 'Plack::Middleware::ReverseProxy', 'Data::Section::Simple'; test_flavor(sub { ok(-f 'app.psgi', 'app.psgi exists'); ok((do 'app.psgi'), 'app.psgi is valid') or do { diag $@; diag do { open my $fh, '<', 'app.psgi' or die; local $/; <$fh>; }; }; }, 'Lite'); done_testing; perl-Amon2-Lite-0.12/t/400_lite/000075500000000000000000000000001231415326300160245ustar00rootroot00000000000000perl-Amon2-Lite-0.12/t/400_lite/01_simple.t000064400000000000000000000012531231415326300200030ustar00rootroot00000000000000use strict; use warnings; use utf8; use Test::More; use Plack::Test; use Test::Requires qw/HTTP::Request::Common/, 'Data::Section::Simple'; use Amon2::Lite; get '/' => sub { my ($c) = @_; return Amon2::Web::Response->new(200, [], 'OK'); }; get '/hello' => sub { my ($c) = @_; return $c->render('hello.tt', { name => $c->req->param('name')}); }; my $app = __PACKAGE__->to_app; test_psgi($app, sub { my $cb = shift; { my $res = $cb->(GET '/'); is $res->content, 'OK'; } { my $res = $cb->(GET '/hello?name=John'); is $res->content, "Hello, John\n"; } }); done_testing; __DATA__ @@ hello.tt Hello, [% name %] perl-Amon2-Lite-0.12/t/400_lite/02_plugin.psgi000064400000000000000000000002631231415326300205100ustar00rootroot00000000000000use strict; use warnings; use Amon2::Lite; __PACKAGE__->load_plugin('Web::JSON'); get '/' => sub { my $c = shift; $c->render_json({ok => 1}); }; __PACKAGE__->to_app(); perl-Amon2-Lite-0.12/t/400_lite/02_plugin.t000064400000000000000000000005701231415326300200120ustar00rootroot00000000000000use strict; use warnings; use utf8; use Test::More; use Test::Requires 'JSON', 'Data::Section::Simple'; use Plack::Util; use Plack::Test; use HTTP::Request::Common; my $app = Plack::Util::load_psgi('t/400_lite/02_plugin.psgi'); is(ref $app, 'CODE'); test_psgi $app, sub { my $cb = shift; my $res = $cb->(GET "/"); is $res->content, '{"ok":1}'; }; done_testing; perl-Amon2-Lite-0.12/t/400_lite/03_kolon.t000064400000000000000000000015421231415326300176370ustar00rootroot00000000000000use strict; use warnings; use utf8; use Test::More; use Plack::Test; use Test::Requires qw/HTTP::Request::Common/, 'Data::Section::Simple'; use FindBin; use File::Spec; use lib File::Spec->catdir($FindBin::Bin, '../../lib'); use Amon2::Lite; sub config { +{ 'Text::Xslate' => { syntax => 'Kolon' } } } get '/' => sub { my ($c) = @_; return Amon2::Web::Response->new(200, [], 'OK'); }; get '/hello' => sub { my ($c) = @_; return $c->render('hello.tt', { name => $c->req->param('name')}); }; my $app = __PACKAGE__->to_app; test_psgi($app, sub { my $cb = shift; { my $res = $cb->(GET '/'); is $res->content, 'OK'; } { my $res = $cb->(GET '/hello?name=John'); is $res->content, "Hello, John\n"; } }); done_testing; __DATA__ @@ hello.tt Hello, <: $name :> perl-Amon2-Lite-0.12/t/400_lite/03_kolon_simple.t000064400000000000000000000015621231415326300212120ustar00rootroot00000000000000use strict; use warnings; use utf8; use Test::More; use Plack::Test; use Test::Requires qw/HTTP::Request::Common/, 'Data::Section::Simple'; use FindBin; use File::Spec; use lib File::Spec->catdir($FindBin::Bin, '../../lib'); my $app = do { use Amon2::Lite; __PACKAGE__->template_options( syntax => 'Kolon', ); get '/' => sub { my ($c) = @_; return $c->create_response(200, [], 'OK'); }; get '/hello' => sub { my ($c) = @_; return $c->render('hello.tt', { name => $c->req->param('name')}); }; __PACKAGE__->to_app; }; test_psgi($app, sub { my $cb = shift; { my $res = $cb->(GET '/'); is $res->content, 'OK'; } { my $res = $cb->(GET '/hello?name=John'); is $res->content, "Hello, John\n"; } }); done_testing; __DATA__ @@ hello.tt Hello, <: $name :> perl-Amon2-Lite-0.12/t/400_lite/04_template_options.t000064400000000000000000000016671231415326300221140ustar00rootroot00000000000000use strict; use warnings; use Test::More; use Plack::Test; use Test::Requires qw/HTTP::Request::Common/, 'Data::Section::Simple'; use FindBin; use File::Spec; use lib File::Spec->catdir($FindBin::Bin, '../../lib'); my $app = do { use Amon2::Lite; __PACKAGE__->template_options( syntax => 'Kolon', module => ['Data::Dumper'], function => { pp => sub { 'pp' . shift }, }, ); get '/' => sub { my $c = shift; $c->render('hoge', { hoge => 'fuga' }); }; get '/dumper' => sub { my $c = shift; $c->render('dumper'); }; __PACKAGE__->to_app(); }; test_psgi($app, sub { my $cb = shift; { my $res = $cb->(GET '/'); is $res->content, "ppfuga\n\n"; } { my $res = $cb->(GET '/dumper'); like $res->content, qr{VAR1}; } }); done_testing; __DATA__ @@ hoge <: pp($hoge) :> @@ dumper <: Dumper(1) :> perl-Amon2-Lite-0.12/t/400_lite/04_tmt.t000064400000000000000000000014441231415326300173230ustar00rootroot00000000000000use strict; use warnings; use utf8; use Test::More; use Plack::Test; use Test::Requires qw/Text::MicroTemplate Tiffany::Text::MicroTemplate::File/, 'Data::Section::Simple'; use HTTP::Request::Common; use Amon2::Lite; sub create_view { Tiffany::Text::MicroTemplate::File->new(+{ include_path => ['./t/tmpl/'] }) } get '/' => sub { my ($c) = @_; return Amon2::Web::Response->new(200, [], 'OK'); }; get '/hello' => sub { my ($c) = @_; return $c->render('foo.mt', $c->req->param('name')); }; my $app = __PACKAGE__->to_app; test_psgi($app, sub { my $cb = shift; { my $res = $cb->(GET '/'); is $res->content, 'OK'; } { my $res = $cb->(GET '/hello?name=John'); is $res->content, "Hello, John!\n"; } }); done_testing; perl-Amon2-Lite-0.12/t/400_lite/05_enable_session.t000064400000000000000000000013071231415326300215070ustar00rootroot00000000000000use strict; use warnings; use utf8; use Test::More; use Test::Requires 'Test::WWW::Mechanize::PSGI'; my $app = do { package MyApp; use Amon2::Lite; get '/' => sub { my $c = shift; my $cnt = $c->session->get('cnt') || 0; $cnt++; $c->session->set(cnt => $cnt); return $c->create_response(200, [], [$cnt]); }; __PACKAGE__->enable_session(); __PACKAGE__->to_app(); }; { my $mech = Test::WWW::Mechanize::PSGI->new(app => $app); $mech->get_ok('http://localhost/'); $mech->content_is('1'); is($mech->response->header('Cache-Control'), 'private'); $mech->get_ok('http://localhost/'); $mech->content_is('2'); } done_testing; perl-Amon2-Lite-0.12/t/400_lite/06_enable_middleware.t000064400000000000000000000011141231415326300221360ustar00rootroot00000000000000use strict; use warnings; use utf8; use Test::More; use HTTP::Response; use Test::Requires 'Test::WWW::Mechanize::PSGI'; my $app = do { package MyApp; use Amon2::Lite; get '/' => sub { my $c = shift; return $c->create_response(200, [], ['OK']); }; __PACKAGE__->enable_middleware('Plack::Middleware::XFramework', framework => 'Amon2::Lite'); __PACKAGE__->to_app(); }; my $mech = Test::WWW::Mechanize::PSGI->new(app => $app); $mech->get_ok('http://localhost/'); is($mech->response->header('X-Framework'), 'Amon2::Lite', 'header'); done_testing; perl-Amon2-Lite-0.12/t/400_lite/07_http_method.t000064400000000000000000000023761231415326300210460ustar00rootroot00000000000000use strict; use warnings; use utf8; use Test::More; use Test::Requires 'Test::WWW::Mechanize::PSGI'; my $app = do { package MyApp; use Amon2::Lite; get '/g' => sub { shift->create_response(200, [], 'get_ok' ) }; post '/p' => sub { shift->create_response(200, [], 'post_ok') }; any '/a' => sub { shift->create_response(200, [], 'any_ok' ) }; any ['get'] => '/a2' => sub { shift->create_response(200, [], 'any_ok2' ) }; __PACKAGE__->to_app(); }; my $mech = Test::WWW::Mechanize::PSGI->new(app => $app); subtest 'normal case' => sub { $mech->get_ok('http://localhost/g'); $mech->content_is('get_ok'); $mech->post_ok('http://localhost/p'); $mech->content_is('post_ok'); }; subtest 'error case' => sub { $mech->post('http://localhost/g'); is($mech->response->code, 405); $mech->get('http://localhost/p'); is($mech->response->code, 405); }; subtest 'any' => sub { $mech->get_ok('http://localhost/a'); $mech->content_is('any_ok'); $mech->post_ok('http://localhost/a'); $mech->content_is('any_ok'); }; subtest 'any 2' => sub { $mech->get_ok('http://localhost/a2'); $mech->content_is('any_ok2'); $mech->post('http://localhost/a2'); is($mech->response->code, 405); }; done_testing; perl-Amon2-Lite-0.12/t/400_lite/08_x_nantoka.t000064400000000000000000000021601231415326300205010ustar00rootroot00000000000000use strict; use warnings; use utf8; use Test::More; use Test::Requires 'Test::WWW::Mechanize::PSGI'; subtest 'basic' => sub { my $app = do { package MyApp; use Amon2::Lite; get '/' => sub { shift->create_response(200, [], 'ok') }; __PACKAGE__->to_app(); }; my $mech = Test::WWW::Mechanize::PSGI->new(app => $app); $mech->get_ok('http://localhost/'); is($mech->response->header('X-Content-Type-Options'), 'nosniff'); is($mech->response->header('X-Frame-Options'), 'DENY'); note $mech->response->as_string; }; subtest 'disabled' => sub { my $app = do { package MyApp2; use Amon2::Lite; get '/' => sub { shift->create_response(200, [], 'ok') }; __PACKAGE__->to_app( no_x_content_type_options => 1, no_x_frame_options => 1, ); }; my $mech = Test::WWW::Mechanize::PSGI->new(app => $app); $mech->get_ok('http://localhost/'); ok(!$mech->response->header('X-Content-Type-Options')); ok(!$mech->response->header('X-Frame-Options')); note $mech->response->as_string; }; done_testing; perl-Amon2-Lite-0.12/t/400_lite/09_get_post.t000064400000000000000000000024471231415326300203540ustar00rootroot00000000000000use strict; use warnings; use utf8; use Test::More; use Test::Requires 'HTTP::Request::Common'; use HTTP::Message::PSGI; use HTTP::Response; use HTTP::Request::Common; { package sandbox; use Amon2::Lite; get '/' => sub { my $c = shift; $c->create_response(200, [], ['get']); }; post '/' => sub { my $c = shift; $c->create_response(200, [], ['post']); }; get '/get_only' => sub { my $c = shift; $c->create_response(200, [], ['get']); }; } my $app = sandbox->to_app; subtest 'GET /' => sub { my $res = res_from_psgi($app->(req_to_psgi( GET 'http://localhost/'))); is($res->code, 200); is($res->content, 'get'); }; subtest 'POST /' => sub { my $res = res_from_psgi($app->(req_to_psgi(POST 'http://localhost/'))); is($res->code, 200); is($res->content, 'post'); }; subtest 'GET /get_only' => sub { my $res = res_from_psgi($app->(req_to_psgi(GET 'http://localhost/get_only'))); is($res->code, 200); }; subtest 'POST /get_only' => sub { my $res = res_from_psgi($app->(req_to_psgi(POST 'http://localhost/get_only'))); is($res->code, 405); }; subtest 'GET /not_found' => sub { my $res = res_from_psgi($app->(req_to_psgi(POST 'http://localhost/not_found'))); is($res->code, 404); }; done_testing; perl-Amon2-Lite-0.12/t/TestFlavor.pm000064400000000000000000000017121231415326300171340ustar00rootroot00000000000000use strict; use warnings; use utf8; package t::TestFlavor; use parent qw(Exporter); our @EXPORT = qw(test_flavor); use File::Temp qw/tempdir/; use App::Prove; use File::Basename; use Cwd; use File::Spec; use Plack::Util; use Test::More; sub test_flavor { my ($code, $flavor_class) = @_; local $ENV{PLACK_ENV} = 'development'; $flavor_class = Plack::Util::load_class($flavor_class, 'Amon2::Setup::Flavor'); my $libpath = File::Spec->rel2abs(File::Spec->catfile(dirname(__FILE__), '..', 'lib')); unshift @INC, $libpath; my $dir = tempdir(CLEANUP => $ENV{DEBUG} ? 0 : 1); my $cwd = Cwd::getcwd(); chdir($dir); note $dir; { my $flavor = $flavor_class->new(module => 'My::App'); $flavor->run; $code->($flavor); # run prove my $app = App::Prove->new(); $app->process_args('--norc', '--exec', "$^X -Ilib -Mlib=$libpath", ); ok($app->run); } chdir($cwd); } 1; perl-Amon2-Lite-0.12/t/tmpl/000075500000000000000000000000001231415326300154605ustar00rootroot00000000000000perl-Amon2-Lite-0.12/t/tmpl/foo.mt000064400000000000000000000000251231415326300166020ustar00rootroot00000000000000Hello, ! perl-Amon2-Lite-0.12/xt/000075500000000000000000000000001231415326300146745ustar00rootroot00000000000000perl-Amon2-Lite-0.12/xt/02_perlcritic.t000064400000000000000000000024031231415326300175210ustar00rootroot00000000000000use strict; use warnings; use Test::More; eval { require Perl::Critic; Perl::Critic->VERSION(1.105); require Test::Perl::Critic; Test::Perl::Critic->VERSION(1.02); Test::Perl::Critic->import( -profile => \(join q{}, ) ); }; note $@ if $@; plan skip_all => "Perl::Critic 1.105+ or Test::Perl::Critic 1.02+ is not installed." if $@; all_critic_ok('lib', 'script', 'bin'); __END__ only=1 # ------------------------------------------------------------------------- # Not important. [BuiltinFunctions::ProhibitSleepViaSelect] [BuiltinFunctions::RequireGlobFunction] [ClassHierarchies::ProhibitOneArgBless] # ------------------------------------------------------------------------- # Bug detection [InputOutput::ProhibitBarewordFileHandles] [Modules::RequireFilenameMatchesPackage] [Subroutines::ProhibitNestedSubs] [Subroutines::ProhibitReturnSort] [TestingAndDebugging::RequireUseStrict] [Variables::ProhibitConditionalDeclarations] [Variables::RequireLexicalLoopIterators] [TestingAndDebugging::ProhibitNoStrict] allow=refs # ------------------------------------------------------------------------- # Security issue detection [InputOutput::RequireEncodingWithUTF8Layer] [Modules::ProhibitEvilModules] [InputOutput::ProhibitTwoArgOpen]