Line # Revision Author
1 198 ahitrov package webshop::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 # зашитая конфигурация плагина
15 $self->{db_type} = 'none';
16 $self->{db_keepalive} = 0;
17 # $self->{db_host} = '';
18 # $self->{db_name} = '';
19 # $self->{db_user} = '';
20 # $self->{db_password} = '';
21 # $self->{db_port} = '';
22 $self->{profile_document_class} = '@PROFILE_DOCUMENT_CLASS@' || 'users::UserProfile';
23 $self->{item_document_class} = '@ITEM_DOCUMENT_CLASS@' || 'webshop::Item';
24
25 $self->_init_();
26 $self;
27 }
28
29 sub info {
30 my $self = shift;
31 return unless ref $self;
32
33 for (sort keys %{$self->{attributes}}) {
34 my $la = length $_;
35 warn "\t$_".("\t" x (2-int($la/8))).": $self->{$_}\n";
36 }
37 }
38
39 sub _init_ {
40 my $self = shift;
41
42 # зашитая конфигурация плагина
43 $self->{attributes}->{$_} = 'SCALAR' for qw(
44 profile_document_class
45 item_document_class
46 db_type
47 db_keepalive
48 );
49 # db_keepalive
50 # db_host
51 # db_port
52 # db_name
53 # db_user
54 # db_password
55 }
56
57 sub AUTOLOAD {
58 my $self = shift;
59 my $attribute = $AUTOLOAD;
60
61 $attribute =~ s/.*:://;
62 return unless $attribute =~ /[^A-Z]/; # Отключаем методы типа DESTROY
63
64 if (!exists $self->{attributes}->{$attribute}) {
65 warn "Contenido Error (webshop::State): Вызов метода, для которого не существует обрабатываемого свойства: ->$attribute()\n";
66 return;
67 }
68
69 $self->{$attribute} = shift @_ if $#_>=0;
70 $self->{$attribute};
71 }
72
73 1;