-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Artur Khabibullin
committed
May 5, 2021
1 parent
c2f5cbd
commit 73102b3
Showing
9 changed files
with
94 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!perl | ||
#PODNAME: Raisin::Encoder::Form | ||
#ABSTRACT: Form deserialization plugin for Raisin. | ||
|
||
use strict; | ||
use warnings; | ||
|
||
package Raisin::Encoder::Form; | ||
|
||
use Encode qw(decode_utf8); | ||
|
||
sub detectable_by { [qw(application/x-www-form-urlencoded multipart/form-data)] } | ||
sub content_type { 'text/plain; charset=utf-8' } | ||
|
||
sub serialize { | ||
Raisin::log(error => 'Raisin:Encoder::Form doesn\'t support serialization'); | ||
die; | ||
} | ||
|
||
sub deserialize { $_[1]->body_parameters } | ||
|
||
1; | ||
|
||
__END__ | ||
=head1 DESCRIPTION | ||
Provides C<deserialize> method to decode HTML form data requests. | ||
=cut |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use HTTP::Message::PSGI; | ||
use HTTP::Request::Common; | ||
use Plack::Request; | ||
use Test::More; | ||
|
||
use Raisin::Encoder::Form; | ||
|
||
subtest 'detectable_by' => sub { | ||
my @ct = Raisin::Encoder::Form->detectable_by; | ||
is_deeply $ct[0], [qw(application/x-www-form-urlencoded multipart/form-data)]; | ||
}; | ||
|
||
subtest 'deserialize' => sub { | ||
my @CASES = ( | ||
# form-urlencoded | ||
{ | ||
env => POST('http://www.perl.org/survey.cgi', Content => [ name => 'Bruce Wayne' ])->to_psgi, | ||
expected => { name => 'Bruce Wayne' }, | ||
}, | ||
# form-data | ||
{ | ||
env => POST('http://www.perl.org/survey.cgi', Content_Type => 'form-data', Content => [ name => 'Bruce Wayne' ])->to_psgi, | ||
expected => { name => 'Bruce Wayne' }, | ||
} | ||
); | ||
for my $c (@CASES) { | ||
my $req = Plack::Request->new( $c->{env} ); | ||
my $data = Raisin::Encoder::Form->deserialize($req); | ||
|
||
is_deeply $data, $c->{expected}; | ||
} | ||
}; | ||
|
||
done_testing; |