Codebase list libdancer2-plugin-ajax-perl / 645444b
Update upstream source from tag 'upstream/0.400000' Update to upstream version '0.400000' with Debian dir 6ec6b4bf6f52811405cf04fb0f74ef975370de9c Florian Schlichting 5 years ago
13 changed file(s) with 78 addition(s) and 35 deletion(s). Raw diff Collapse all Expand all
00 Revision history for Dancer2-Plugin-Ajax
1
2 0.400000 2018-11-12 21:52:07-05:00 America/New_York
3
4 * GH #7: Pass $self to ajax route handlers to allow access to ->app and other
5 methods (Julien Fiegehenn)
16
27 0.300000 2016-10-28 10:38:01-05:00 America/Chicago
38
0 # This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.007.
0 # This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.012.
11 Changes
22 LICENSE
33 MANIFEST
33 "Dancer Core Developers"
44 ],
55 "dynamic_config" : 0,
6 "generated_by" : "Dist::Zilla version 6.007, CPAN::Meta::Converter version 2.150005",
6 "generated_by" : "Dist::Zilla version 6.012, CPAN::Meta::Converter version 2.150010",
77 "license" : [
88 "perl_5"
99 ],
4848 "IPC::Open3" : "0",
4949 "Plack::Test" : "0",
5050 "Test::More" : "0.92",
51 "blib" : "1.01",
5251 "perl" : "5.006"
5352 }
5453 }
5655 "provides" : {
5756 "Dancer2::Plugin::Ajax" : {
5857 "file" : "lib/Dancer2/Plugin/Ajax.pm",
59 "version" : "0.300000"
58 "version" : "0.400000"
6059 }
6160 },
6261 "release_status" : "stable",
7372 "x_IRC" : "irc://irc.perl.org/#dancer",
7473 "x_WebIRC" : "https://chat.mibbit.com/#dancer@irc.perl.org"
7574 },
76 "version" : "0.300000",
77 "x_serialization_backend" : "Cpanel::JSON::XS version 3.0217"
75 "version" : "0.400000",
76 "x_generated_by_perl" : "v5.28.0",
77 "x_serialization_backend" : "Cpanel::JSON::XS version 4.07"
7878 }
7979
1010 IPC::Open3: '0'
1111 Plack::Test: '0'
1212 Test::More: '0.92'
13 blib: '1.01'
1413 perl: '5.006'
1514 configure_requires:
1615 ExtUtils::MakeMaker: '0'
1716 dynamic_config: 0
18 generated_by: 'Dist::Zilla version 6.007, CPAN::Meta::Converter version 2.150005'
17 generated_by: 'Dist::Zilla version 6.012, CPAN::Meta::Converter version 2.150010'
1918 license: perl
2019 meta-spec:
2120 url: http://module-build.sourceforge.net/META-spec-v1.4.html
2423 provides:
2524 Dancer2::Plugin::Ajax:
2625 file: lib/Dancer2/Plugin/Ajax.pm
27 version: '0.300000'
26 version: '0.400000'
2827 requires:
2928 Dancer2: '0.200000'
3029 Dancer2::Core::Types: '0'
3736 bugtracker: https://github.com/PerlDancer/Dancer2-Plugin-Ajax/issues
3837 homepage: https://github.com/PerlDancer/Dancer2-Plugin-Ajax
3938 repository: https://github.com/PerlDancer/Dancer2-Plugin-Ajax.git
40 version: '0.300000'
41 x_serialization_backend: 'YAML::Tiny version 1.69'
39 version: '0.400000'
40 x_generated_by_perl: v5.28.0
41 x_serialization_backend: 'YAML::Tiny version 1.73'
0 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.007.
0 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.012.
11 use strict;
22 use warnings;
33
3030 "IO::Handle" => 0,
3131 "IPC::Open3" => 0,
3232 "Plack::Test" => 0,
33 "Test::More" => "0.92",
34 "blib" => "1.01"
33 "Test::More" => "0.92"
3534 },
36 "VERSION" => "0.300000",
35 "VERSION" => "0.400000",
3736 "test" => {
3837 "TESTS" => "t/*.t"
3938 }
5150 "IPC::Open3" => 0,
5251 "Plack::Test" => 0,
5352 "Test::More" => "0.92",
54 "blib" => "1.01",
5553 "strict" => 0,
5654 "warnings" => 0
5755 );
00 package Dancer2::Plugin::Ajax;
11 # ABSTRACT: a plugin for adding Ajax route handlers
2 $Dancer2::Plugin::Ajax::VERSION = '0.300000';
2 $Dancer2::Plugin::Ajax::VERSION = '0.400000';
33 use strict;
44 use warnings;
55 use Dancer2::Core::Types 'Str';
4242 # disable layout
4343 my $layout = $plugin->app->config->{'layout'};
4444 $plugin->app->config->{'layout'} = undef;
45 my $response = $code->();
45 my $response = $code->(@_);
4646 $plugin->app->config->{'layout'} = $layout;
4747 return $response;
4848 };
7070
7171 =head1 VERSION
7272
73 version 0.300000
73 version 0.400000
7474
7575 =head1 SYNOPSIS
7676
8181
8282 # For GET / POST
8383 ajax '/check_for_update' => sub {
84 my $self = shift;
85
8486 # ... some Ajax code
8587 };
8688
8789 # For all valid HTTP methods
8890 ajax ['get', 'post', ... ] => '/check_for_more' => sub {
91 my $self = shift;
92
8993 # ... some Ajax code
9094 };
9195
9397
9498 =head1 DESCRIPTION
9599
96 The C<ajax> keyword which is exported by this plugin allow you to define a route
100 The C<ajax> keyword which is exported by this plugin allows you to define a route
97101 handler optimized for Ajax queries.
98102
99103 The route handler code will be compiled to behave like the following:
114118
115119 =back
116120
121 The route handler gets the Dancer C<$self> object passed in, just like any other Dancer2 route handler.
122 You can use this to inspect the request data.
123
124 ajax '/check_for_update' => sub {
125 my $self = shift;
126
127 my $method = $self->app->request->method;
128 # ...
129 }
130
117131 =head1 CONFIGURATION
118132
119 By default the plugin will use a content-type of 'text/xml' but this can be overridden
120 with plugin setting 'content_type'.
133 By default the plugin will use a content-type of 'text/xml', but this can be overridden
134 with the plugin setting C<content_type>.
121135
122 Here is example to use JSON:
136 Here is an example to use JSON:
123137
124138 plugins:
125139 Ajax:
11 use strict;
22 use warnings;
33
4 # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.054
4 # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.058
55
66 use Test::More;
77
1515
1616 # no fake home requested
1717
18 my $inc_switch = -d 'blib' ? '-Mblib' : '-Ilib';
18 my @switches = (
19 -d 'blib' ? '-Mblib' : '-Ilib',
20 );
1921
2022 use File::Spec;
2123 use IPC::Open3;
2931 # see L<perlfaq8/How can I capture STDERR from an external command?>
3032 my $stderr = IO::Handle->new;
3133
32 my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-e', "require q[$lib]");
34 diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} }
35 $^X, @switches, '-e', "require q[$lib]"))
36 if $ENV{PERL_COMPILE_TEST_DEBUG};
37
38 my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]");
3339 binmode $stderr, ':crlf' if $^O eq 'MSWin32';
3440 my @_warnings = <$stderr>;
3541 waitpid($pid, 0);
3642 is($?, 0, "$lib loaded ok");
3743
3844 shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
39 and not eval { require blib; blib->VERSION('1.01') };
45 and not eval { +require blib; blib->VERSION('1.01') };
4046
4147 if (@_warnings)
4248 {
3333 'IPC::Open3' => '0',
3434 'Plack::Test' => '0',
3535 'Test::More' => '0.92',
36 'blib' => '1.01',
3736 'perl' => '5.006'
3837 }
3938 }
22 use strict;
33 use warnings;
44
5 # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.025
5 # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.027
66
77 use Test::More tests => 1;
88
6767 );
6868
6969 # Add static prereqs to the included modules list
70 my $static_prereqs = do 't/00-report-prereqs.dd';
70 my $static_prereqs = do './t/00-report-prereqs.dd';
7171
7272 # Merge all prereqs (either with ::Prereqs or a hashref)
7373 my $full_prereqs = _merge_prereqs(
7777
7878 # Add dynamic prereqs to the included modules list (if we can)
7979 my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml';
80 my $cpan_meta_error;
8081 if ( $source && $HAS_CPAN_META
8182 && (my $meta = eval { CPAN::Meta->load_file($source) } )
8283 ) {
8384 $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs);
8485 }
8586 else {
87 $cpan_meta_error = $@; # capture error from CPAN::Meta->load_file($source)
8688 $source = 'static metadata';
8789 }
8890
168170 diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports;
169171 }
170172
173 if ( $cpan_meta_error || @dep_errors ) {
174 diag "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n";
175 }
176
177 if ( $cpan_meta_error ) {
178 my ($orig_source) = grep { -f } 'MYMETA.json', 'MYMETA.yml';
179 diag "\nCPAN::Meta->load_file('$orig_source') failed with: $cpan_meta_error\n";
180 }
181
171182 if ( @dep_errors ) {
172183 diag join("\n",
173 "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n",
174 "The following REQUIRED prerequisites were not satisfied:\n",
184 "\nThe following REQUIRED prerequisites were not satisfied:\n",
175185 @dep_errors,
176186 "\n"
177187 );
2424
2525 ajax ['put', 'delete', 'get'] => "/more/test" => sub {
2626 "{some: 'json'}";
27 };
28
29 ajax '/subargs' => sub {
30 return $_[0]->app->request->to_string;
2731 };
2832 }
2933
96100 is $res->content_type, 'text/html', 'content type on non-XMLHttpRequest not munged';
97101 };
98102
103 like(
104 $test->request( GET '/subargs', 'X-Requested-With' => 'XMLHttpRequest' )
105 ->content,
106 qr{/subargs},
107 'GH #7: ajax routes have access to $self',
108 );
109
99110 done_testing;
00
11 BEGIN {
22 unless ($ENV{AUTHOR_TESTING}) {
3 print "1..0 # SKIP these tests are for testing by the author\n";
3 print qq{1..0 # SKIP these tests are for testing by the author\n};
44 exit
55 }
66 }
11
22 BEGIN {
33 unless ($ENV{AUTHOR_TESTING}) {
4 print "1..0 # SKIP these tests are for testing by the author\n";
4 print qq{1..0 # SKIP these tests are for testing by the author\n};
55 exit
66 }
77 }
11
22 BEGIN {
33 unless ($ENV{RELEASE_TESTING}) {
4 print "1..0 # SKIP these tests are for release candidate testing\n";
4 print qq{1..0 # SKIP these tests are for release candidate testing\n};
55 exit
66 }
77 }