Line # Revision Author
1 480 ahitrov package tag::State;
2
3 use strict;
4 use warnings 'all';
5 use vars qw($AUTOLOAD);
6
7
8 sub new {
9 my ($proto) = @_;
10 my $class = ref($proto) || $proto;
11 my $self = {};
12 bless $self, $class;
13
14 # configured
15 $self->{project} = '@PROJECT@';
16 $self->{debug} = (lc('@DEBUG@') eq 'yes');
17 $self->{contenido_notab} = 0;
18 $self->{tab_name} = 'Теги';
19 $self->{project_name} = '@PROJECT_NAME@';
20 $self->{default_expire} = '@DEFAULT_EXPIRE@' || 300;
21 $self->{default_object_expire} = '@DEFAULT_OBJECT_EXPIRE@' || 600;
22
23 # зашитая конфигурация плагина
24 $self->{db_type} = 'none'; ### For REAL database use 'remote'
25 $self->{db_keepalive} = 0;
26 $self->{db_host} = '';
27 $self->{db_name} = '';
28 $self->{db_user} = '';
29 $self->{db_password} = '';
30 $self->{db_port} = '';
31 $self->{store_method} = 'toast';
32 $self->{cascade} = 1;
33 $self->{db_prepare} = 0;
34
35 $self->{memcached_enable} = lc( '@MEMCACHED_ENABLE@' ) eq 'yes' ? 1 : 0;
36 $self->{memcached_backend} = '@MEMCACHED_BACKEND@';
37 $self->{memcached_select_timeout} = '@MEMCACHED_SELECT_TIMEOUT@' || 0.2;
38 $self->{memcached_servers} = [qw(@MEMCACHED_SERVERS@)];
39 $self->{memcached_enable_compress} = lc( '@MEMCACHED_ENABLE_COMPRESS@' ) eq 'yes' ? 1 : 0;
40 $self->{memcached_delayed} = lc('@MEMCACHED_DELAYED@') eq 'yes' ? 1 : 0;
41 $self->{memcached_set_mode} = lc('@MEMCACHED_SET_MODE@') eq 'add' ? 'add' : 'set';
42 $self->{memcached_busy_lock} = 60;
43 $self->{memcached_namespace} = lc( $self->{'project'} ).'|plugin_tag|';
44
45 $self->{serialize_with} = 'json'; ### or 'dumper'
46
47 # not implemented really (core compatibility)
48 $self->{data_directory} = '';
49 $self->{images_directory} = '';
50 $self->{binary_directory} = '';
51 $self->{preview} = '';
52
53 $self->{tag_destinations} = [qw(@TAG_DEST@)];
54
55 $self->_init_();
56 $self;
57 }
58
59 sub info {
60 my $self = shift;
61 return unless ref $self;
62
63 for (sort keys %{$self->{attributes}}) {
64 my $la = length $_;
65 warn "\t$_".("\t" x (2-int($la/8))).": $self->{$_}\n";
66 }
67 }
68
69 sub _init_ {
70 my $self = shift;
71
72 # зашитая конфигурация плагина
73 $self->{attributes}->{$_} = 'SCALAR' for qw(
74 debug
75 project
76 tab_name
77
78 db_type
79 db_keepalive
80 db_host
81 db_port
82 db_name
83 db_user
84 db_password
85 store_method
86 cascade
87 db_prepare
88 db_client_encoding
89
90 memcached_enable
91 memcached_servers
92 memcached_select_timeout
93 memcached_backend
94 memcached_enable_compress
95 memcached_set_mode
96 memcached_object_expire
97 memcached_busy_lock
98 memcached_delayed
99 memcached_namespace
100
101 binary_directory
102 data_directory
103 images_directory
104 preview
105
106 tag_destinations
107 );
108 }
109
110 sub AUTOLOAD {
111 my $self = shift;
112 my $attribute = $AUTOLOAD;
113
114 $attribute =~ s/.*:://;
115 return unless $attribute =~ /[^A-Z]/; # Отключаем методы типа DESTROY
116
117 if (!exists $self->{attributes}->{$attribute}) {
118 warn "Contenido Error (tag::State): Вызов метода, для которого не существует обрабатываемого свойства: ->$attribute()\n";
119 return;
120 }
121
122 $self->{$attribute} = shift @_ if $#_>=0;
123 $self->{$attribute};
124 }
125
126 1;