Revision 277 (by ahitrov, 2013/02/08 08:03:40) Default fields
package webshop::State;

use strict;
use warnings 'all';
use vars qw($AUTOLOAD);


sub new {
	my ($proto) = @_;
	my $class = ref($proto) || $proto;
	my $self = {};
	bless $self, $class;

	# зашитая конфигурация плагина
	$self->{db_type} =		'none';
	$self->{db_keepalive} =		0;
#	$self->{db_host} =		'';
#	$self->{db_name} =		'';
#	$self->{db_user} =		'';
#	$self->{db_password} =	'';
#	$self->{db_port} =		'';
	$self->{profile_document_class} =	'@PROFILE_DOCUMENT_CLASS@' || 'users::UserProfile';
	$self->{item_document_class} =		'@ITEM_DOCUMENT_CLASS@' ? [qw( @ITEM_DOCUMENT_CLASS@ )] : ['webshop::Item'];
	$self->{item_section_class} =		'@ITEM_SECTION_CLASS@' ? [qw( @ITEM_SECTION_CLASS@ )] : ['webshop::ItemSection'];

        $self->{db_keepalive} = 0;
        $self->{db_host} =              '';
        $self->{db_name} =              '';
        $self->{db_user} =              '';
        $self->{db_password} =  '';
        $self->{db_port} =              '';

	$self->{data_directory} =	'';
	$self->{images_directory} =	'';
	$self->{binary_directory} =	'';
	$self->{preview} =		'';
	$self->{debug} =		'';
	$self->{store_method} =		'';
	$self->{cascade} =		'';
	$self->{memcached_enable} =	'';

	$self->_init_();
	$self;	
}

sub info {
	my $self = shift;
	return unless ref $self;

	for (sort keys %{$self->{attributes}}) {
		my $la = length $_;
		warn "\t$_".("\t" x (2-int($la/8))).": $self->{$_}\n";
	}
}

sub _init_ {
	my $self = shift;

	# зашитая конфигурация плагина
	$self->{attributes}->{$_} = 'SCALAR' for qw(
		profile_document_class
		item_document_class
		db_type
                db_keepalive
                db_host
                db_port
                db_name
                db_user
                db_password
                data_directory images_directory binary_directory preview debug store_method cascade memcached_enable
	);
}

sub AUTOLOAD {
	my $self = shift;
	my $attribute = $AUTOLOAD;

	$attribute =~ s/.*:://;
	return unless $attribute =~ /[^A-Z]/;  # Отключаем методы типа DESTROY

	if (!exists $self->{attributes}->{$attribute}) {
		warn "Contenido Error (webshop::State): Вызов метода, для которого не существует обрабатываемого свойства: ->$attribute()\n";
		return;
	}

	$self->{$attribute} = shift @_ if $#_>=0;
	$self->{$attribute};
}

1;