Revision 3 (by ahitrov@rambler.ru, 2010/03/24 15:19:32) |
The CORE
|
package Contenido::Request;
# ----------------------------------------------------------------------------
# Contenido::Request - �����, ������� ����� ����������� ��� �������
# ������� � ������� ��������������. � ���� �� ������������� ��� ������
# � ������� ������� (� ��� ����� � ���������� ���������� URI mapping,
# �� ���� �������� ���������� ���������, ������� ������ ������������
# ���� ������). ������ ����� ���� ����� ����������� ��� �������
# ������� �� ����, ��� HTML::Mason ������� ����������.
# ----------------------------------------------------------------------------
use strict;
use warnings;
use locale;
use vars qw($VERSION $AUTOLOAD);
$VERSION = '1.0';
use Data::Dumper;
use Contenido::Globals;
sub new
{
my ($proto,$state) = @_;
$log->error("������������ ����� ������������ ������� �������. � ���������� ��� ������� ������ Contenido::State") unless ref $state;
my $class = ref($proto) || $proto;
my $self = {};
bless($self, $class);
# �������� ��, ��� ��� ����������...
$self->{data} = {};
$self->{_cache_} = {};
$self->{timer_start} = time();
foreach my $a ( qw(timer_start timer_finish) )
{
$self->{attributes}->{ $a } = 'SCALAR';
}
return $self;
}
sub set_properties
{
my ($self, %P) = @_;
foreach my $p (keys(%P))
{
$self->{data}->{$p} = $P{$p};
$self->{attributes}->{ $p } = 'DATA';
};
return 1;
}
sub get_args {
my $self = shift;
if (exists $self->{request_args}) {
return wantarray ? %{$self->{request_args}} : $self->{request_args};
}
my $apr = $self->r();
my $args = {};
if ($apr) {
foreach my $key ( $apr->param ) {
my @values = $apr->param($key);
$args->{$key} = @values == 1 ? $values[0] : \@values;
}
}
$self->{request_args} = $args;
return wantarray ? %{ $self->{request_args} } : $self->{request_args};
}
sub is_post {
my $self = shift;
return $self->r()->method() =~ /^post/i ? 1 : undef;
}
# ----------------------------------------------------------------------------
# ��� ����� AUTOLOAD. ����� ������� ��� ���������/������ �����...
# ������ 0.2/���������������� ������
# ----------------------------------------------------------------------------
sub AUTOLOAD
{
my $self = shift;
my $attribute = $AUTOLOAD;
$attribute =~ s/.*:://;
return undef unless $attribute =~ /[^A-Z]/; # ��������� ������ ���� DESTROY
unless ( exists $self->{attributes}->{$attribute} ) {
$log->error("����� ������, ��� �������� �� ���������� ��������������� ��������: ->$attribute()");
return undef;
}
if ($self->{attributes}->{$attribute} eq 'DATA')
{
$self->{data}->{ $attribute } = shift @_ if (scalar(@_) > 0);
return $self->{data}->{ $attribute };
} else {
$self->{ $attribute } = shift @_ if (scalar(@_) > 0);
return $self->{ $attribute };
}
}
1;