annotate Lib/IMPL/lang.pm @ 244:a02b110da931

refactoring fixed binding to CGI query parameters with multiple values
author sergey
date Mon, 22 Oct 2012 04:09:27 +0400
parents f48a1a9f4fa2
children 56364d0c4b4f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
164
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
1 package IMPL::lang;
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
2 use strict;
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
3 use warnings;
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
4
165
76515373dac0 Added Class::Template,
wizard
parents: 164
diff changeset
5 use parent qw(Exporter);
164
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
6 use IMPL::_core::version;
173
aaab45153411 minor bugfixes
sourcer
parents: 169
diff changeset
7 use IMPL::clone qw(clone);
164
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
8
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
9 require IMPL::Class::PropertyInfo;
164
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
10
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
11 our @EXPORT = qw(&is);
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
12 our %EXPORT_TAGS = (
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
13 base => [
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
14 qw(
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
15 &is
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
16 &clone
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
17 )
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
18 ],
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
19
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
20 declare => [
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
21 qw(
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
22 &public
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
23 &protected
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
24 &private
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
25 &virtual
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
26 &property
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
27 &static
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
28 &property
213
sergey
parents: 210
diff changeset
29 &ACCESS_PUBLIC
sergey
parents: 210
diff changeset
30 &ACCESS_PROTECTED
sergey
parents: 210
diff changeset
31 &ACCESS_PRIVATE
sergey
parents: 210
diff changeset
32 &PROP_GET
sergey
parents: 210
diff changeset
33 &PROP_SET
sergey
parents: 210
diff changeset
34 &PROP_OWNERSET
sergey
parents: 210
diff changeset
35 &PROP_LIST
sergey
parents: 210
diff changeset
36 &PROP_ALL
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 213
diff changeset
37 &PROP_RO
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 213
diff changeset
38 &PROP_RW
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
39 )
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
40 ],
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
41 compare => [
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
42 qw(
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
43 &equals
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
44 &equals_s
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
45 &hashCompare
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
46 )
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
47 ],
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
48 hash => [
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
49 qw(
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
50 &hashApply
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
51 &hashMerge
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
52 &hashDiff
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
53 &hashCompare
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
54 &hashParse
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
55 &hashSave
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
56 )
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
57 ]
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
58 );
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
59
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
60 our @EXPORT_OK = keys %{ { map (($_,1) , map (@{$_}, values %EXPORT_TAGS) ) } };
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
61
230
6d8092d8ce1b *reworked IMPL::Security
sergey
parents: 213
diff changeset
62 use IMPL::Const qw(:all);
164
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
63
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
64 sub is($$) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
65 eval { $_[0]->isa( $_[1] ) };
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
66 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
67
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
68 sub virtual($) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
69 $_[0]->Virtual(1);
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
70 $_[0];
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
71 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
72
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
73 sub public($) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
74 $_[0]->Access(ACCESS_PUBLIC);
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
75 $_[0]->Implement;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
76 $_[0];
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
77 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
78
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
79 sub private($) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
80 $_[0]->Access(ACCESS_PRIVATE);
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
81 $_[0]->Implement;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
82 $_[0];
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
83 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
84
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
85 sub protected($) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
86 $_[0]->Access(ACCESS_PROTECTED);
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
87 $_[0]->Implement;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
88 $_[0];
164
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
89 }
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
90
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
91 sub property($$;$) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
92 my ( $propName, $mutators, $attributes ) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
93 my $Info = new IMPL::Class::PropertyInfo(
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
94 {
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
95 Name => $propName,
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
96 Mutators => $mutators,
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
97 Class => scalar(caller),
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
98 Attributes => $attributes
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
99 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
100 );
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
101 return $Info;
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
102 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
103
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
104 sub static($$) {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
105 my ( $name, $value ) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
106 my $class = caller;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
107 $class->static_accessor( $name, $value );
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
108 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
109
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
110 sub equals {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
111 if (defined $_[0]) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
112 return 0 if (not defined $_[1]);
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
113
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
114 return $_[0] == $_[1];
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
115 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
116 return 0 if defined $_[1];
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
117
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
118 return 1;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
119 }
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
120 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
121
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
122 sub equals_s {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
123 if (defined $_[0]) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
124 return 0 if (not defined $_[1]);
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
125
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
126 return $_[0] eq $_[1];
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
127 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
128 return 0 if defined $_[1];
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
129
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
130 return 1;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
131 }
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
132 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
133
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
134 sub hashDiff {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
135 my ($src,$dst) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
136
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
137 $dst = $dst ? { %$dst } : {} ;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
138 $src ||= {};
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
139
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
140 my %result;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
141
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
142 foreach my $key ( keys %$src ) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
143 if (exists $dst->{$key}) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
144 $result{"+$key"} = $dst->{$key} unless equals_s($dst->{$key}, $src->{$key});
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
145 delete $dst->{$key};
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
146 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
147 $result{"-$key"} = 1;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
148 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
149 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
150
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
151 $result{"+$_"} = $dst->{$_} foreach keys %$dst;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
152
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
153 return \%result;
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
154 }
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
155
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
156 sub hashMerge {
210
6adaeb86945d added IMPL::Web::AutoLocator
sergey
parents: 194
diff changeset
157 return hashApply( { %{$_[0] || {}} }, $_[1] );
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
158 }
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
159
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
160 sub hashApply {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
161 my ($target,$diff) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
162
241
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 230
diff changeset
163 return $target unless ref $diff eq 'HASH';
f48a1a9f4fa2 +Added ViewResult to allow implementation of the view environment.
sergey
parents: 230
diff changeset
164
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
165 while ( my ($key,$value) = each %$diff) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
166 $key =~ /^(\+|-)?(.*)$/;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
167 my $op = $1 || '+';
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
168 $key = $2;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
169
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
170 if ($op eq '-') {
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
171 delete $target->{$key};
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
172 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
173 $target->{$key} = $value;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
174 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
175 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
176
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
177 return $target;
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
178 }
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
179
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
180 sub hashCompare {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
181 my ($l,$r,$cmp) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
182
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
183 $cmp ||= \&equals_s;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
184
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
185 return 0 unless scalar keys %$l == scalar keys %$r;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
186 &$cmp($l->{$_},$r->{$_}) || return 0 foreach keys %$l;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
187
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
188 return 1;
168
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
189 }
6148f89bb7bf IMPL::SQL::Schema::Traits::Diff alfa version
sourcer
parents: 167
diff changeset
190
174
d920d2b70230 minor changes
sergey
parents: 173
diff changeset
191 sub hashParse {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
192 my ($s,$p,$d) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
193
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
194 $p = $p ? qr/$p/ : qr/\n+/;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
195 $d = $d ? qr/$d/ : qr/\s*=\s*/;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
196
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
197 return {
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
198 map split($d,$_,2), split($p,$s)
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
199 };
174
d920d2b70230 minor changes
sergey
parents: 173
diff changeset
200 }
d920d2b70230 minor changes
sergey
parents: 173
diff changeset
201
d920d2b70230 minor changes
sergey
parents: 173
diff changeset
202 sub hashSave {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
203 my ($hash,$p,$d) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
204
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
205 return "" unless ref $hash eq 'HASH';
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
206
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
207 $p ||= "\n";
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
208 $d ||= " = ";
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
209
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
210 return
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
211 join(
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
212 $p,
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
213 map(
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
214 join(
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
215 $d,
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
216 $_,
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
217 $hash->{$_}
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
218 ),
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
219 keys %$hash
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
220 )
4d0e1962161c Replaced tabs with spaces
cin
parents: 181
diff changeset
221 );
174
d920d2b70230 minor changes
sergey
parents: 173
diff changeset
222 }
d920d2b70230 minor changes
sergey
parents: 173
diff changeset
223
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
224 1;