annotate lib/IMPL/Web/CGIWrapper.pm @ 417:3ed0c58e9da3 ref20150831

working on di container, tests
author cin
date Mon, 02 Nov 2015 01:56:53 +0300
parents c6e90e02dd17
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
1 package IMPL::Web::CGIWrapper;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
2 use strict;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
3
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
4 use parent qw(CGI);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
5 use Encode;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
6
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
7 our $NO_DECODE = 0;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
8
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
9 sub param {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
10 my $this = shift;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
11
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
12 return $this->SUPER::param(@_) if $NO_DECODE;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
13
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
14 if (wantarray) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
15 my @result = $this->SUPER::param(@_);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
16
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
17 return map Encode::is_utf8($_)
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
18 ? $_
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
19 : Encode::decode( $this->charset, $_, Encode::LEAVE_SRC ), @result;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
20 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
21 else {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
22 my $result = $this->SUPER::param(@_);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
23
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
24 return Encode::is_utf8($result)
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
25 ? $result
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
26 : Encode::decode( $this->charset, $result, Encode::LEAVE_SRC );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
27 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
28
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
29 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
30
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
31 sub upload {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
32 my $this = shift;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
33
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
34 local $NO_DECODE = 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
35 my $oldCharset = $this->charset();
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
36 $this->charset('ISO-8859-1');
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
37
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
38 my $fh = $this->SUPER::upload(@_);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
39
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
40 $this->charset($oldCharset);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
41 return $fh;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
42 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
43
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
44 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
45
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
46 __END__
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
47
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
48 =pod
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
49
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
50 =head1 NAME
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
51
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
52 C<IMPL::Web::CGIWrapper> - обетрка вокруг стандартного объекта C<CGI>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
53
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
54 =head1 DESCRIPTION
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
55
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
56 Наследуется от C<CGI>, и переопределяет метод C<param> для декодирования
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
57 строковых параметров. В остальном функциональность аналогична стандартному
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
58 модулю C<CGI>.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
59
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
60 =head1 MEMBERS
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
61
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
62 =head2 C<$NO_DECODE>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
63
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
64 Глобальная переменная для отключения декодирования параметров.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
65
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
66 =begin code
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
67
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
68 {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
69 local $IMPL::Web::CGIWrapper::NO_DECODE = 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
70 my $raw = $q->param('binary');
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
71 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
72
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
73 =end code
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
74
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
75 =cut