Update upstream source from tag 'upstream/0.400000'
Update to upstream version '0.400000'
with Debian dir 6ec6b4bf6f52811405cf04fb0f74ef975370de9c
Florian Schlichting
5 years ago
0 | 0 | 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) | |
1 | 6 | |
2 | 7 | 0.300000 2016-10-28 10:38:01-05:00 America/Chicago |
3 | 8 |
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. | |
1 | 1 | Changes |
2 | 2 | LICENSE |
3 | 3 | MANIFEST |
3 | 3 | "Dancer Core Developers" |
4 | 4 | ], |
5 | 5 | "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", | |
7 | 7 | "license" : [ |
8 | 8 | "perl_5" |
9 | 9 | ], |
48 | 48 | "IPC::Open3" : "0", |
49 | 49 | "Plack::Test" : "0", |
50 | 50 | "Test::More" : "0.92", |
51 | "blib" : "1.01", | |
52 | 51 | "perl" : "5.006" |
53 | 52 | } |
54 | 53 | } |
56 | 55 | "provides" : { |
57 | 56 | "Dancer2::Plugin::Ajax" : { |
58 | 57 | "file" : "lib/Dancer2/Plugin/Ajax.pm", |
59 | "version" : "0.300000" | |
58 | "version" : "0.400000" | |
60 | 59 | } |
61 | 60 | }, |
62 | 61 | "release_status" : "stable", |
73 | 72 | "x_IRC" : "irc://irc.perl.org/#dancer", |
74 | 73 | "x_WebIRC" : "https://chat.mibbit.com/#dancer@irc.perl.org" |
75 | 74 | }, |
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" | |
78 | 78 | } |
79 | 79 |
10 | 10 | IPC::Open3: '0' |
11 | 11 | Plack::Test: '0' |
12 | 12 | Test::More: '0.92' |
13 | blib: '1.01' | |
14 | 13 | perl: '5.006' |
15 | 14 | configure_requires: |
16 | 15 | ExtUtils::MakeMaker: '0' |
17 | 16 | 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' | |
19 | 18 | license: perl |
20 | 19 | meta-spec: |
21 | 20 | url: http://module-build.sourceforge.net/META-spec-v1.4.html |
24 | 23 | provides: |
25 | 24 | Dancer2::Plugin::Ajax: |
26 | 25 | file: lib/Dancer2/Plugin/Ajax.pm |
27 | version: '0.300000' | |
26 | version: '0.400000' | |
28 | 27 | requires: |
29 | 28 | Dancer2: '0.200000' |
30 | 29 | Dancer2::Core::Types: '0' |
37 | 36 | bugtracker: https://github.com/PerlDancer/Dancer2-Plugin-Ajax/issues |
38 | 37 | homepage: https://github.com/PerlDancer/Dancer2-Plugin-Ajax |
39 | 38 | 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. | |
1 | 1 | use strict; |
2 | 2 | use warnings; |
3 | 3 | |
30 | 30 | "IO::Handle" => 0, |
31 | 31 | "IPC::Open3" => 0, |
32 | 32 | "Plack::Test" => 0, |
33 | "Test::More" => "0.92", | |
34 | "blib" => "1.01" | |
33 | "Test::More" => "0.92" | |
35 | 34 | }, |
36 | "VERSION" => "0.300000", | |
35 | "VERSION" => "0.400000", | |
37 | 36 | "test" => { |
38 | 37 | "TESTS" => "t/*.t" |
39 | 38 | } |
51 | 50 | "IPC::Open3" => 0, |
52 | 51 | "Plack::Test" => 0, |
53 | 52 | "Test::More" => "0.92", |
54 | "blib" => "1.01", | |
55 | 53 | "strict" => 0, |
56 | 54 | "warnings" => 0 |
57 | 55 | ); |
0 | 0 | package Dancer2::Plugin::Ajax; |
1 | 1 | # ABSTRACT: a plugin for adding Ajax route handlers |
2 | $Dancer2::Plugin::Ajax::VERSION = '0.300000'; | |
2 | $Dancer2::Plugin::Ajax::VERSION = '0.400000'; | |
3 | 3 | use strict; |
4 | 4 | use warnings; |
5 | 5 | use Dancer2::Core::Types 'Str'; |
42 | 42 | # disable layout |
43 | 43 | my $layout = $plugin->app->config->{'layout'}; |
44 | 44 | $plugin->app->config->{'layout'} = undef; |
45 | my $response = $code->(); | |
45 | my $response = $code->(@_); | |
46 | 46 | $plugin->app->config->{'layout'} = $layout; |
47 | 47 | return $response; |
48 | 48 | }; |
70 | 70 | |
71 | 71 | =head1 VERSION |
72 | 72 | |
73 | version 0.300000 | |
73 | version 0.400000 | |
74 | 74 | |
75 | 75 | =head1 SYNOPSIS |
76 | 76 | |
81 | 81 | |
82 | 82 | # For GET / POST |
83 | 83 | ajax '/check_for_update' => sub { |
84 | my $self = shift; | |
85 | ||
84 | 86 | # ... some Ajax code |
85 | 87 | }; |
86 | 88 | |
87 | 89 | # For all valid HTTP methods |
88 | 90 | ajax ['get', 'post', ... ] => '/check_for_more' => sub { |
91 | my $self = shift; | |
92 | ||
89 | 93 | # ... some Ajax code |
90 | 94 | }; |
91 | 95 | |
93 | 97 | |
94 | 98 | =head1 DESCRIPTION |
95 | 99 | |
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 | |
97 | 101 | handler optimized for Ajax queries. |
98 | 102 | |
99 | 103 | The route handler code will be compiled to behave like the following: |
114 | 118 | |
115 | 119 | =back |
116 | 120 | |
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 | ||
117 | 131 | =head1 CONFIGURATION |
118 | 132 | |
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>. | |
121 | 135 | |
122 | Here is example to use JSON: | |
136 | Here is an example to use JSON: | |
123 | 137 | |
124 | 138 | plugins: |
125 | 139 | Ajax: |
1 | 1 | use strict; |
2 | 2 | use warnings; |
3 | 3 | |
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 | |
5 | 5 | |
6 | 6 | use Test::More; |
7 | 7 | |
15 | 15 | |
16 | 16 | # no fake home requested |
17 | 17 | |
18 | my $inc_switch = -d 'blib' ? '-Mblib' : '-Ilib'; | |
18 | my @switches = ( | |
19 | -d 'blib' ? '-Mblib' : '-Ilib', | |
20 | ); | |
19 | 21 | |
20 | 22 | use File::Spec; |
21 | 23 | use IPC::Open3; |
29 | 31 | # see L<perlfaq8/How can I capture STDERR from an external command?> |
30 | 32 | my $stderr = IO::Handle->new; |
31 | 33 | |
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]"); | |
33 | 39 | binmode $stderr, ':crlf' if $^O eq 'MSWin32'; |
34 | 40 | my @_warnings = <$stderr>; |
35 | 41 | waitpid($pid, 0); |
36 | 42 | is($?, 0, "$lib loaded ok"); |
37 | 43 | |
38 | 44 | 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') }; | |
40 | 46 | |
41 | 47 | if (@_warnings) |
42 | 48 | { |
33 | 33 | 'IPC::Open3' => '0', |
34 | 34 | 'Plack::Test' => '0', |
35 | 35 | 'Test::More' => '0.92', |
36 | 'blib' => '1.01', | |
37 | 36 | 'perl' => '5.006' |
38 | 37 | } |
39 | 38 | } |
2 | 2 | use strict; |
3 | 3 | use warnings; |
4 | 4 | |
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 | |
6 | 6 | |
7 | 7 | use Test::More tests => 1; |
8 | 8 | |
67 | 67 | ); |
68 | 68 | |
69 | 69 | # 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'; | |
71 | 71 | |
72 | 72 | # Merge all prereqs (either with ::Prereqs or a hashref) |
73 | 73 | my $full_prereqs = _merge_prereqs( |
77 | 77 | |
78 | 78 | # Add dynamic prereqs to the included modules list (if we can) |
79 | 79 | my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; |
80 | my $cpan_meta_error; | |
80 | 81 | if ( $source && $HAS_CPAN_META |
81 | 82 | && (my $meta = eval { CPAN::Meta->load_file($source) } ) |
82 | 83 | ) { |
83 | 84 | $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs); |
84 | 85 | } |
85 | 86 | else { |
87 | $cpan_meta_error = $@; # capture error from CPAN::Meta->load_file($source) | |
86 | 88 | $source = 'static metadata'; |
87 | 89 | } |
88 | 90 | |
168 | 170 | diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports; |
169 | 171 | } |
170 | 172 | |
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 | ||
171 | 182 | if ( @dep_errors ) { |
172 | 183 | 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", | |
175 | 185 | @dep_errors, |
176 | 186 | "\n" |
177 | 187 | ); |
24 | 24 | |
25 | 25 | ajax ['put', 'delete', 'get'] => "/more/test" => sub { |
26 | 26 | "{some: 'json'}"; |
27 | }; | |
28 | ||
29 | ajax '/subargs' => sub { | |
30 | return $_[0]->app->request->to_string; | |
27 | 31 | }; |
28 | 32 | } |
29 | 33 | |
96 | 100 | is $res->content_type, 'text/html', 'content type on non-XMLHttpRequest not munged'; |
97 | 101 | }; |
98 | 102 | |
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 | ||
99 | 110 | done_testing; |
0 | 0 | |
1 | 1 | BEGIN { |
2 | 2 | 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}; | |
4 | 4 | exit |
5 | 5 | } |
6 | 6 | } |