Revision 717 (by ahitrov, 2018/09/06 14:00:48) |
default methods for memcached
|
package money::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->{contenido_notab} = 1;
$self->{tab_name} = 'money';
$self->{project_name} = '@PROJECT_NAME@';
$self->{default_expire} = '@DEFAULT_EXPIRE@' || 300;
$self->{default_object_expire} = '@DEFAULT_OBJECT_EXPIRE@' || 600;
# зашитая конфигурация плагина
$self->{db_type} = 'none'; ### For REAL database use 'remote'
$self->{db_keepalive} = 0;
$self->{db_host} = '';
$self->{db_name} = '';
$self->{db_user} = '';
$self->{db_password} = '';
$self->{db_port} = '';
$self->{store_method} = 'toast';
$self->{cascade} = 1;
$self->{db_prepare} = 0;
$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_money|';
$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->{dreamkas_app_id} = '@DREAMKAS_ID@';
$self->{dreamkas_app_secret} = '@DREAMKAS_SECRET@';
$self->{dreamkas_token} = '@DREAMKAS_TOKEN@';
$self->{dreamkas_currency_code} = '@DREAMKAS_CURRENCY_CODE@';
$self->{dreamkas_tax_mode} = '@DREAMKAS_TAX_MODE@' || 'DEFAULT';
$self->{dreamkas_tax_nds} = '@DREAMKAS_TAX_NDS@' || 'NDS_NO_TAX';
$self->{dreamkas_device_id} = int('@DREAMKAS_DEVICE_ID@' || 0);
$self->{dreamkas_test_mode} = int('@DREAMKAS_TEST_MODE@' || 0);
$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_enable_compress
memcached_backend
memcached_servers
memcached_busy_lock
memcached_delayed
memcached_namespace
memcached_select_timeout
binary_directory
data_directory
images_directory
preview
);
}
sub AUTOLOAD {
my $self = shift;
my $attribute = $AUTOLOAD;
$attribute =~ s/.*:://;
return unless $attribute =~ /[^A-Z]/; # Отключаем методы типа DESTROY
if (!exists $self->{attributes}->{$attribute}) {
warn "Contenido Error (money::State): Вызов метода, для которого не существует обрабатываемого свойства: ->$attribute()\n";
return;
}
$self->{$attribute} = shift @_ if $#_>=0;
$self->{$attribute};
}
1;