annotate Lib/IMPL/Object/Autofill.pm @ 280:c6d0f889ef87

+IMPL::declare now supports meta attributes *bugfixes related to the typeof() operator
author cin
date Wed, 06 Feb 2013 02:15:48 +0400
parents 4ddb27ff4a0b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
1 package IMPL::Object::Autofill;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
2 use strict;
278
4ddb27ff4a0b core refactoring
cin
parents: 275
diff changeset
3
4ddb27ff4a0b core refactoring
cin
parents: 275
diff changeset
4 use IMPL::Const qw(:access);
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
5
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
6 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
7 my $this = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
8 no strict 'refs';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
9
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
10 my $fields = @_ == 1 ? $_[0] : {@_};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
11
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
12 $this->_fill(ref $this,$fields);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
13 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
14
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
15 sub _fill {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
16 my ($this,$class,$fields) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
17
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
18 $class->_autofill_method->($this,$fields);
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
19
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
20 no strict 'refs';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
21 $this->_fill($_,$fields) foreach grep $_->isa('IMPL::Object::Autofill'), @{"${class}::ISA"};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
22 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
23
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
24 sub DisableAutofill {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
25 my $self = shift;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
26
229
47f77e6409f7 heavily reworked the resource model of the web application:
sergey
parents: 206
diff changeset
27 no strict 'refs';
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
28 my $class = ref $self || $self;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
29
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
30 *{"${class}::_impl_object_autofill"} = sub {};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
31 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
32
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
33 sub _autofill_method {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
34 my ($class) = @_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
35
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
36 $class = ref $class if ref $class;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
37
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
38 # для автозаполнения нужен свой метод верхнего уровня
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
39 my $method;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
40 {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
41 no strict 'refs';
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
42 $method = ${$class.'::'}{_impl_object_autofill};
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
43 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
44
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
45 if ($method) {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
46 return $method;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
47 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
48 my $text = <<HEADER;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
49 package $class;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
50 sub _impl_object_autofill {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
51 my (\$this,\$fields) = \@_;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
52 HEADER
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
53
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
54
278
4ddb27ff4a0b core refactoring
cin
parents: 275
diff changeset
55 if ($class->can('GetMeta')) {
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
56 # meta supported
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
57 foreach my $prop_info (grep {
278
4ddb27ff4a0b core refactoring
cin
parents: 275
diff changeset
58 $_->setter && ($_->access & ACCESS_PUBLIC);
4ddb27ff4a0b core refactoring
cin
parents: 275
diff changeset
59 } $class->GetMeta('IMPL::Class::PropertyInfo')) {
275
6253872024a4 *refactoring IMPL::Class
cin
parents: 229
diff changeset
60 my $name = $prop_info->name;
278
4ddb27ff4a0b core refactoring
cin
parents: 275
diff changeset
61 if ($prop_info->isa('IMPL::Class::DirectPropertyInfo')) {
206
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 198
diff changeset
62 $text .= " \$this->$name(\$fields->{$name}) if exists \$fields->{$name};\n";
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
63 } else {
278
4ddb27ff4a0b core refactoring
cin
parents: 275
diff changeset
64 my $fld = $prop_info->fieldName;
4ddb27ff4a0b core refactoring
cin
parents: 275
diff changeset
65 if ($prop_info->isList) {
206
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 198
diff changeset
66 $text .= " \$this->{$fld} = IMPL::Object::List->new ( ref \$fields->{$name} ? \$fields->{$name} : [\$fields->{$name}] ) if exists \$fields->{$name};\n";
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
67 } else {
206
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 198
diff changeset
68 $text .= " \$this->{$fld} = \$fields->{$name} if exists \$fields->{$name};\n";
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
69 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
70 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
71 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
72 } else {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
73 # meta not supported
206
c8fe3f84feba +IMPL::Web::Handlers::ViewSelector
sergey
parents: 198
diff changeset
74 #$text .= " ".'$this->$_($fields->{$_}) foreach keys %$fields;'."\n";
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
75 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
76 $text .= "}\n\\&_impl_object_autofill;";
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
77 return eval $text;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
78 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
79 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
80
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
81 1;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
82
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
83 __END__
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
84
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
85 =pod
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 180
diff changeset
86
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 180
diff changeset
87 =head1 NAME
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 180
diff changeset
88
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 180
diff changeset
89 C<IMPL::Object::Autofill> - автозаполнение объектов
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 180
diff changeset
90
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
91 =head1 SYNOPSIS
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 180
diff changeset
92
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 180
diff changeset
93 =begin code
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 180
diff changeset
94
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
95 package MyClass;
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 180
diff changeset
96 use IMPL::declare {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 180
diff changeset
97 base => {
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 180
diff changeset
98 'IMPL::Object' => undef,
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 180
diff changeset
99 'IMPL::Object::Autofill' => '@_'
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 180
diff changeset
100 }
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 180
diff changeset
101 };
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
102
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
103 BEGIN {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
104 private property PrivateData => prop_all;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
105 public property PublicData => prop_get;
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
106 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
107
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
108 sub CTOR {
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
109 my $this = shift;
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 180
diff changeset
110
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
111 print $this->PrivateData,"\n";
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
112 print $this->PublicData,"\n";
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
113 }
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
114
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
115 my $obj = new MyClass(PrivateData => 'private', PublicData => 'public', Other => 'some data');
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
116
198
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 180
diff changeset
117 #will print
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 180
diff changeset
118 #private
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 180
diff changeset
119 #public
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 180
diff changeset
120
2ffe6f661605 Implemented IMPL::Web::Handler::RestController
cin
parents: 180
diff changeset
121 =end code
49
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
122
16ada169ca75 migrating to the Eclipse IDE
wizard@linux-odin.local
parents: 0
diff changeset
123 =cut