Line # Revision Author
1 3 ahitrov@rambler.ru package Contenido::Request;
2
3 # ----------------------------------------------------------------------------
4 # Contenido::Request - �����, ������� ����� ����������� ��� �������
5 # ������� � ������� ��������������. � ���� �� ������������� ��� ������
6 # � ������� ������� (� ��� ����� � ���������� ���������� URI mapping,
7 # �� ���� �������� ���������� ���������, ������� ������ ������������
8 # ���� ������). ������ ����� ���� ����� ����������� ��� �������
9 # ������� �� ����, ��� HTML::Mason ������� ����������.
10 # ----------------------------------------------------------------------------
11
12 use strict;
13 use warnings;
14 use locale;
15
16 use vars qw($VERSION $AUTOLOAD);
17 $VERSION = '1.0';
18
19 use Data::Dumper;
20 use Contenido::Globals;
21
22 sub new
23 {
24 my ($proto,$state) = @_;
25 $log->error("������������ ����� ������������ ������� �������. � ���������� ��� ������� ������ Contenido::State") unless ref $state;
26
27 my $class = ref($proto) || $proto;
28 my $self = {};
29 bless($self, $class);
30
31 # �������� ��, ��� ��� ����������...
32 $self->{data} = {};
33 $self->{_cache_} = {};
34 $self->{timer_start} = time();
35
36 foreach my $a ( qw(timer_start timer_finish) )
37 {
38 $self->{attributes}->{ $a } = 'SCALAR';
39 }
40
41 return $self;
42 }
43
44
45 sub set_properties
46 {
47 my ($self, %P) = @_;
48 foreach my $p (keys(%P))
49 {
50 $self->{data}->{$p} = $P{$p};
51 $self->{attributes}->{ $p } = 'DATA';
52 };
53
54 return 1;
55 }
56
57 sub get_args {
58 my $self = shift;
59
60 if (exists $self->{request_args}) {
61 return wantarray ? %{$self->{request_args}} : $self->{request_args};
62 }
63
64
65 my $apr = $self->r();
66 my $args = {};
67 if ($apr) {
68 foreach my $key ( $apr->param ) {
69 my @values = $apr->param($key);
70 $args->{$key} = @values == 1 ? $values[0] : \@values;
71 }
72 }
73
74 $self->{request_args} = $args;
75 return wantarray ? %{ $self->{request_args} } : $self->{request_args};
76 }
77
78
79 sub is_post {
80 my $self = shift;
81 return $self->r()->method() =~ /^post/i ? 1 : undef;
82 }
83
84
85 # ----------------------------------------------------------------------------
86 # ��� ����� AUTOLOAD. ����� ������� ��� ���������/������ �����...
87 # ������ 0.2/���������������� ������
88 # ----------------------------------------------------------------------------
89
90 sub AUTOLOAD
91 {
92 my $self = shift;
93 my $attribute = $AUTOLOAD;
94
95 $attribute =~ s/.*:://;
96 return undef unless $attribute =~ /[^A-Z]/; # ��������� ������ ���� DESTROY
97
98 unless ( exists $self->{attributes}->{$attribute} ) {
99 $log->error("����� ������, ��� �������� �� ���������� ��������������� ��������: ->$attribute()");
100 return undef;
101 }
102
103 if ($self->{attributes}->{$attribute} eq 'DATA')
104 {
105 $self->{data}->{ $attribute } = shift @_ if (scalar(@_) > 0);
106 return $self->{data}->{ $attribute };
107 } else {
108 $self->{ $attribute } = shift @_ if (scalar(@_) > 0);
109 return $self->{ $attribute };
110 }
111 }
112
113
114 1;