Revision 774 (by ahitrov, 2019/04/22 15:18:57) Search through go-based JSON proxy

package sphinx::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->{debug} =		(lc('@DEBUG@') eq 'yes');
	$self->{project} =		'@PROJECT@';
	$self->{contenido_notab} =	1;
	$self->{tab_name} =		'sphinx';

	# зашитая конфигурация плагина
	$self->{db_type} =		'proxy';	### For REAL database use 'remote'
	$self->{db_keepalive} =		0;
	$self->{db_host} =		'@SPHINX_HOST@';
	$self->{db_name} =		'';
	$self->{db_user} =		'';
	$self->{db_password} =		'';
	$self->{db_port} =		'@SPHINX_PORT@';
	$self->{store_method} =		'toast';
	$self->{cascade} =		1;
	$self->{db_prepare} =		0;

	$self->{memcached_enable} =	lc( '@MEMCACHED_ENABLE@' ) eq 'yes' ? 1 : 0;
	$self->{memcached_enable_compress} = 1;
	$self->{memcached_backend} =	'@MEMCACHED_BACKEND@';
	$self->{memcached_servers} =	[qw(@MEMCACHED_SERVERS@)];
	$self->{memcached_busy_lock} =	60;
	$self->{memcached_delayed} =	lc('@MEMCACHED_DELAYED@') eq 'yes' ? 1 : 0;

	$self->{serialize_with} =	'json';		### or 'dumper'

	# not implemented really (core compatibility)
	$self->{binary_directory} =	'/nonexistent';
	$self->{data_directory} =	'/nonexistent';
	$self->{images_directory} =	'/nonexistent';
	$self->{preview} =		'0';

	$self->{table_name} =		'@SPHINX_TABLE@';
	$self->{table_name_stemmed} =	'@SPHINX_TABLE_STEMMED@';

	$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(
                debug
                project
		tab_name

		db_type
		db_keepalive
		db_host
		db_port
		db_name
		db_user
		db_password
		store_method
		cascade
		db_prepare
		db_client_encoding

		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

		binary_directory
		data_directory
		images_directory
		preview

		table_name
		table_name_stemmed
	);
}

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

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

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

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

1;