| 1 | # | ||
| 2 | # WARNING WARNING WARNING | ||
| 3 | # | ||
| 4 | # DO NOT CHANGE ANYTHING IN THIS MODULE. OTHERWISE, A LOT OF API | ||
| 5 | # AND OTHER TESTS MAY BREAK. | ||
| 6 | # | ||
| 7 | # This module is here to test certain behaviors. If you need | ||
| 8 | # to test something else, add another test module. | ||
| 9 | # It's that simple. | ||
| 10 | # | ||
| 11 | |||
| 12 | # This does not need to be indexed by PAUSE | ||
| 13 | package | ||
| 14 | RPC::ExtDirect::Test::Pkg::JuiceBar; | ||
| 15 | |||
| 16 | use strict; | ||
| 17 | use warnings; | ||
| 18 | no warnings 'uninitialized'; | ||
| 19 | |||
| 20 | use base 'RPC::ExtDirect::Test::Pkg::Foo'; | ||
| 21 | |||
| 22 | use RPC::ExtDirect; | ||
| 23 | |||
| 24 | use Carp; | ||
| 25 | |||
| 26 | our $CHEAT = 0; | ||
| 27 | |||
| 28 | # This one croaks merrily | ||
| 29 | sub bar_foo : ExtDirect(4) { croak 'bar foo!' } | ||
| 30 | |||
| 31 | # Return number of passed arguments | ||
| 32 | sub bar_bar : ExtDirect(5) { shift; pop; return scalar @_; } | ||
| 33 | |||
| 34 | # This is a form handler | ||
| 35 | sub bar_baz : ExtDirect(formHandler) { | ||
| 36 | my ($class, %param) = @_; | ||
| 37 | |||
| 38 | # We don't use the env object here, but have to remove it | ||
| 39 | # so that it doesn't leak in the response | ||
| 40 | my $env = delete $param{_env}; | ||
| 41 | |||
| 42 | # Simulate uploaded file handling | ||
| 43 | my $uploads = $param{file_uploads}; | ||
| 44 | return \%param unless $uploads; | ||
| 45 | |||
| 46 | # Return 'uploads' data | ||
| 47 | my $response = "The following files were processed:\n"; | ||
| 48 | for my $upload ( @$uploads ) { | ||
| 49 | my $name = $upload->{basename}; | ||
| 50 | my $type = $upload->{type}; | ||
| 51 | my $size = $upload->{size}; | ||
| 52 | |||
| 53 | # | ||
| 54 | # CGI::Test somehow uploads files so that | ||
| 55 | # they are 2 bytes shorter than actual size | ||
| 56 | # This allows for the same test results to be | ||
| 57 | # applied across all gateways and test frameworks | ||
| 58 | # | ||
| 59 | # TODO Investigate why this is happening and fix | ||
| 60 | # | ||
| 61 | $size += 2 if $CHEAT; | ||
| 62 | |||
| 63 | my $ok = (defined $upload->{handle} && | ||
| 64 | $upload->{handle}->opened) ? "ok" : "not ok"; | ||
| 65 | |||
| 66 | $response .= "$name $type $size $ok\n"; | ||
| 67 | }; | ||
| 68 | |||
| 69 | delete $param{file_uploads}; | ||
| 70 | $param{upload_response} = $response; | ||
| 71 | |||
| 72 | return \%param; | ||
| 73 | } | ||
| 74 | |||
| 75 | 1; |