Line # Revision Author
1 194 ahitrov package session::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 255 ahitrov # configured
15 253 ahitrov $self->{project} = '@PROJECT@';
16 255 ahitrov $self->{debug} = (lc('@DEBUG@') eq 'yes');
17 $self->{project_name} = '@PROJECT_NAME@';
18 $self->{default_expire} = '@DEFAULT_EXPIRE@' || 300;
19 $self->{default_object_expire} ='@DEFAULT_OBJECT_EXPIRE@' || 600;
20 253 ahitrov
21 255 ahitrov # ������� ������������ �������
22 194 ahitrov $self->{db_type} = 'none';
23 $self->{storage} = '@SESSION_STORAGE@' || 'FILE'; ## ��������: FILE POSTGRES MEMCACHED
24 $self->{session_dir} = '@SESSIONS@';
25 $self->{session_directory} = '@SESSIONS@';
26
27 $self->{domain} = '@SESSION_DOMAIN@';
28 $self->{cookie} = 'lsid';
29 $self->{expires} = '@SESSION_EXPIRES@' || '';
30
31 $self->{lifetime} = '@SESSION_LIFETIME@';
32 $self->{lifetime} *= 3600;
33 $self->{checkout} = $self->{lifetime} - int ($self->{lifetime} / 2);
34
35 $self->{db_keepalive} = 0;
36 $self->{db_host} = '';
37 $self->{db_name} = '';
38 $self->{db_user} = '';
39 $self->{db_password} = '';
40 $self->{db_port} = '';
41
42 $self->{data_directory} = '';
43 $self->{images_directory} = '';
44 $self->{binary_directory} = '';
45 $self->{preview} = '';
46 $self->{store_method} = '';
47 $self->{cascade} = '';
48
49 253 ahitrov $self->{memcached_enable} = lc( '@MEMCACHED_ENABLE@' ) eq 'yes' ? 1 : 0;
50 $self->{memcached_backend} = '@MEMCACHED_BACKEND@';
51 $self->{memcached_select_timeout} = '@MEMCACHED_SELECT_TIMEOUT@' || 0.2;
52 $self->{memcached_servers} = [qw(@MEMCACHED_SERVERS@)];
53 $self->{memcached_enable_compress} = lc( '@MEMCACHED_ENABLE_COMPRESS@' ) eq 'yes' ? 1 : 0;
54 $self->{memcached_delayed} = lc('@MEMCACHED_DELAYED@') eq 'yes' ? 1 : 0;
55 $self->{memcached_set_mode} = lc('@MEMCACHED_SET_MODE@') eq 'add' ? 'add' : 'set';
56 $self->{memcached_busy_lock} = 60;
57 $self->{memcached_namespace} = lc( $self->{'project'} ).'|plugin_session|';
58
59 $self->{memcached_object_expire} = undef;
60
61 $self->{storage} = 'FILE' if $self->{storage} eq 'MEMCACHED' && !$self->{memcached_enable};
62
63 194 ahitrov $self->{facebook_app_id} = '@FACEBOOK_APP_ID@';
64 $self->{facebook_app_secret} = '@FACEBOOK_APP_SECRET@';
65 $self->{facebook_redirect_uri} = '@FACEBOOK_REDIRECT_URL@';
66 $self->{facebook_user_post_url} = '@FACEBOOK_USER_POST_URL@';
67
68 $self->{vk_app_id} = '@VK_APP_ID@';
69 $self->{vk_app_secret} = '@VK_APP_SECRET@';
70 $self->{vk_redirect_uri} = '@VK_REDIRECT_URL@';
71 $self->{vk_user_post_url} = '@VK_USER_POST_URL@';
72
73 243 ahitrov $self->{mailru_app_id} = '@MAILRU_APP_ID@';
74 $self->{mailru_app_secret} = '@MAILRU_APP_SECRET@';
75 $self->{mailru_redirect_uri} = '@MAILRU_REDIRECT_URL@';
76 $self->{mailru_user_post_url} = '@MAILRU_USER_POST_URL@';
77
78 281 ahitrov $self->{google_app_id} = '@GOOGLE_APP_ID@';
79 $self->{google_app_secret} = '@GOOGLE_APP_SECRET@';
80 $self->{google_redirect_uri} = '@GOOGLE_REDIRECT_URL@';
81 $self->{google_user_post_url} = '@GOOGLE_USER_POST_URL@';
82 $self->{google_scope} = '@GOOGLE_SCOPE@';
83
84 194 ahitrov $self->{connection_timeout} = '@CONNECTION_TIMEOUT@';
85
86 $self->_init_();
87 $self;
88 }
89
90 sub info {
91 my $self = shift;
92 return unless ref $self;
93
94 for (sort keys %{$self->{attributes}}) {
95 my $la = length $_;
96 warn "\t$_".("\t" x (2-int($la/8))).": $self->{$_}\n";
97 }
98 }
99
100 sub _init_ {
101 my $self = shift;
102
103 # ������� ������������ �������
104 $self->{attributes}->{$_} = 'SCALAR' for qw(
105 db_type
106 session_dir
107 session_directory
108 domain
109 cookie
110 expires
111 storage
112 lifetime
113 checkout
114 db_keepalive
115 db_host
116 db_port
117 db_name
118 db_user
119 db_password
120 253 ahitrov
121 memcached_enable
122 memcached_servers
123 memcached_select_timeout
124 memcached_backend
125 memcached_enable_compress
126 memcached_set_mode
127 memcached_object_expire
128 memcached_busy_lock
129 memcached_delayed
130 memcached_namespace
131
132 data_directory
133 images_directory
134 binary_directory
135 preview
136 debug
137 store_method
138 cascade
139 194 ahitrov );
140 }
141
142 sub AUTOLOAD {
143 my $self = shift;
144 my $attribute = $AUTOLOAD;
145
146 $attribute =~ s/.*:://;
147 return unless $attribute =~ /[^A-Z]/; # ��������� ������ ���� DESTROY
148
149 if (!exists $self->{attributes}->{$attribute}) {
150 warn "Contenido Error (session::State): ����� ������, ��� �������� �� ���������� ��������������� ��������: ->$attribute()\n";
151 return;
152 }
153
154 $self->{$attribute} = shift @_ if $#_>=0;
155 $self->{$attribute};
156 }
157
158 1;