Revision 281 (by ahitrov, 2013/02/19 14:45:34) Session object implemented
package session::State;

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


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

	# configured
	$self->{project} = 		'@PROJECT@';
	$self->{debug} =		(lc('@DEBUG@') eq 'yes');
	$self->{project_name} =		'@PROJECT_NAME@';
	$self->{default_expire} =	'@DEFAULT_EXPIRE@' || 300;
	$self->{default_object_expire} ='@DEFAULT_OBJECT_EXPIRE@' || 600;

	# ������� ������������ �������
	$self->{db_type} =		'none';
	$self->{storage} =		'@SESSION_STORAGE@' || 'FILE'; ## ��������: FILE POSTGRES MEMCACHED
	$self->{session_dir} =		'@SESSIONS@';
	$self->{session_directory} =	'@SESSIONS@';

	$self->{domain}		= '@SESSION_DOMAIN@';
	$self->{cookie}		= 'lsid';
	$self->{expires}	= '@SESSION_EXPIRES@' || '';

	$self->{lifetime}	= '@SESSION_LIFETIME@';
	$self->{lifetime}	*= 3600;
	$self->{checkout}	= $self->{lifetime} - int ($self->{lifetime} / 2);

	$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->{store_method} =		'';
	$self->{cascade} =		'';

	$self->{memcached_enable} =		lc( '@MEMCACHED_ENABLE@' ) eq 'yes' ? 1 : 0;
	$self->{memcached_backend} =		'@MEMCACHED_BACKEND@';
	$self->{memcached_select_timeout} =	'@MEMCACHED_SELECT_TIMEOUT@' || 0.2;
	$self->{memcached_servers} =		[qw(@MEMCACHED_SERVERS@)];
	$self->{memcached_enable_compress} =	lc( '@MEMCACHED_ENABLE_COMPRESS@' ) eq 'yes' ? 1 : 0;
	$self->{memcached_delayed} =		lc('@MEMCACHED_DELAYED@') eq 'yes' ? 1 : 0;
	$self->{memcached_set_mode} =		lc('@MEMCACHED_SET_MODE@') eq 'add' ? 'add' : 'set';
	$self->{memcached_busy_lock} =		60;
	$self->{memcached_namespace} =		lc( $self->{'project'} ).'|plugin_session|';

	$self->{memcached_object_expire} =	undef;

	$self->{storage} = 'FILE'		if $self->{storage} eq 'MEMCACHED' && !$self->{memcached_enable};

	$self->{facebook_app_id} =		'@FACEBOOK_APP_ID@';
	$self->{facebook_app_secret} =		'@FACEBOOK_APP_SECRET@';
	$self->{facebook_redirect_uri} =	'@FACEBOOK_REDIRECT_URL@';
	$self->{facebook_user_post_url} =	'@FACEBOOK_USER_POST_URL@';

	$self->{vk_app_id} =			'@VK_APP_ID@';
	$self->{vk_app_secret} =		'@VK_APP_SECRET@';
	$self->{vk_redirect_uri} =		'@VK_REDIRECT_URL@';
	$self->{vk_user_post_url} =		'@VK_USER_POST_URL@';

	$self->{mailru_app_id} =		'@MAILRU_APP_ID@';
	$self->{mailru_app_secret} =		'@MAILRU_APP_SECRET@';
	$self->{mailru_redirect_uri} =		'@MAILRU_REDIRECT_URL@';
	$self->{mailru_user_post_url} =		'@MAILRU_USER_POST_URL@';

        $self->{google_app_id} =                '@GOOGLE_APP_ID@';
        $self->{google_app_secret} =            '@GOOGLE_APP_SECRET@';
        $self->{google_redirect_uri} =          '@GOOGLE_REDIRECT_URL@';
        $self->{google_user_post_url} =         '@GOOGLE_USER_POST_URL@';
        $self->{google_scope} =                 '@GOOGLE_SCOPE@';

	$self->{connection_timeout} =		'@CONNECTION_TIMEOUT@';

	$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(
		db_type
		session_dir
		session_directory
		domain
		cookie
		expires
		storage
		lifetime
		checkout
		db_keepalive
		db_host
		db_port
		db_name
		db_user
		db_password

		memcached_enable
		memcached_servers
		memcached_select_timeout
		memcached_backend
		memcached_enable_compress
		memcached_set_mode
		memcached_object_expire
		memcached_busy_lock
		memcached_delayed
		memcached_namespace

		data_directory
		images_directory
		binary_directory
		preview
		debug
		store_method
		cascade
	);
}

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

	$attribute =~ s/.*:://;
	return unless $attribute =~ /[^A-Z]/;  # ��������� ������ ���� DESTROY

	if (!exists $self->{attributes}->{$attribute}) {
		warn "Contenido Error (session::State): ����� ������, ��� �������� �� ���������� ��������������� ��������: ->$attribute()\n";
		return;
	}

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

1;