use multi_param() if available to avoid the new warning
[bse.git] / site / cgi-bin / modules / BSE / CGI.pm
CommitLineData
3f9c8a96
TC
1package BSE::CGI;
2use strict;
3use Encode;
4
bbf3d175 5our $VERSION = "1.002";
cb7fd78d 6
3f9c8a96
TC
7sub new {
8 my ($class, $q, $charset) = @_;
9
bbf3d175 10 my $param = $q->can("multi_param") ? "multi_param" : "param";
3f9c8a96
TC
11 my $self = bless
12 {
13 cgi => $q,
14 charset => $charset,
bbf3d175 15 param => $param,
3f9c8a96
TC
16 }, $class;
17
18 return $self;
19}
20
21sub param {
22 my ($self, @args) = @_;
23
bbf3d175
TC
24 my $param = $self->{param};
25 my @result = $self->{cgi}->$param(@args)
3f9c8a96
TC
26 or return;
27 for my $value (@result) {
b3d836c6
TC
28 $value = decode($self->{charset}, $value)
29 unless ref $value;
3f9c8a96
TC
30 }
31
32 return wantarray && @result > 1 ? @result : $result[0];
33}
34
bbf3d175
TC
35sub multi_param {
36 my ($self, @args) = @_;
37
38 my $param = $self->{param};
39 my @result = $self->{cgi}->$param(@args)
40 or return;
41 for my $value (@result) {
42 $value = decode($self->{charset}, $value)
43 unless ref $value;
44 }
45
46 return wantarray ? @result : $result[0];
47}
48
3f9c8a96
TC
49sub upload {
50 my ($self, @args) = @_;
51
52 return $self->{cgi}->upload(@args);
53}
54
55sub uploadInfo {
56 my ($self, @args) = @_;
57
58 return $self->{cgi}->uploadInfo(@args);
59}
60
611;
62
63=head1 NAME
64
65BSE::CGI - CGI.pm wrapper that does character set conversions to perl's internal encoding
66
67=head1 SYNOPSIS
68
69 my $cgi1 = CGI->new;
70 my $cgi = BSE::CGI->new($cgi1, $charset);
71
72=head1 DESCRIPTION
73
74Only provides param(), upload() and uploadInfo().
75
76=cut