... | ... |
@@ -12,66 +12,40 @@ use DBIx::Custom::SQL::Template; |
12 | 12 |
|
13 | 13 |
|
14 | 14 |
### Accessors |
15 |
-sub user : ClassObjectAttr { initialize => {clone => 'scalar'} } |
|
16 |
-sub password : ClassObjectAttr { initialize => {clone => 'scalar'} } |
|
17 |
-sub data_source : ClassObjectAttr { initialize => {clone => 'scalar'} } |
|
18 |
- |
|
19 |
-sub options : ClassObjectAttr { |
|
20 |
- type => 'hash', |
|
21 |
- initialize => {clone => 'hash', default => sub { {} }} |
|
22 |
-} |
|
23 |
- |
|
24 |
-sub database : ClassObjectAttr { initialize => {clone => 'scalar'} } |
|
25 |
-sub host : ClassObjectAttr { initialize => {clone => 'scalar'} } |
|
26 |
-sub port : ClassObjectAttr { initialize => {clone => 'scalar'} } |
|
15 |
+sub dbh : Attr {} |
|
27 | 16 |
|
28 |
-sub bind_filter : ClassObjectAttr { initialize => {clone => 'scalar'} } |
|
29 |
-sub fetch_filter : ClassObjectAttr { initialize => {clone => 'scalar'} } |
|
17 |
+sub _query_caches : ClassAttr { type => 'hash', build => sub {{}} } |
|
18 |
+sub _query_cache_keys : ClassAttr { type => 'array', build => sub {[]} } |
|
19 |
+sub query_cache_max : ClassAttr { build => 50 } |
|
30 | 20 |
|
31 |
-sub no_bind_filters : ClassObjectAttr { |
|
32 |
- type => 'array', |
|
33 |
- initialize => {clone => 'array', default => sub { [] }} |
|
34 |
-} |
|
21 |
+sub user : HybridAttr { clone => 'scalar' } |
|
22 |
+sub password : HybridAttr { clone => 'scalar' } |
|
23 |
+sub data_source : HybridAttr { clone => 'scalar' } |
|
24 |
+sub database : HybridAttr { clone => 'scalar' } |
|
25 |
+sub host : HybridAttr { clone => 'scalar' } |
|
26 |
+sub port : HybridAttr { clone => 'scalar' } |
|
27 |
+sub bind_filter : HybridAttr { clone => 'scalar' } |
|
28 |
+sub fetch_filter : HybridAttr { clone => 'scalar' } |
|
35 | 29 |
|
36 |
-sub no_fetch_filters : ClassObjectAttr { |
|
37 |
- type => 'array', |
|
38 |
- initialize => {clone => 'array', default => sub { [] }} |
|
39 |
-} |
|
30 |
+sub no_bind_filters : HybridAttr { type => 'array', build => sub {[]}, |
|
31 |
+ clone => 'array' } |
|
40 | 32 |
|
41 |
-sub filters : ClassObjectAttr { |
|
42 |
- type => 'hash', |
|
43 |
- deref => 1, |
|
44 |
- initialize => { |
|
45 |
- clone => 'hash', |
|
46 |
- default => sub { {} } |
|
47 |
- } |
|
48 |
-} |
|
33 |
+sub no_fetch_filters : HybridAttr { type => 'array', build => sub { [] }, |
|
34 |
+ clone => 'array' } |
|
49 | 35 |
|
50 |
-sub formats : ClassObjectAttr { |
|
51 |
- type => 'hash', |
|
52 |
- deref => 1, |
|
53 |
- initialize => { |
|
54 |
- clone => 'hash', |
|
55 |
- default => sub { {} } |
|
56 |
- } |
|
57 |
-} |
|
36 |
+sub options : HybridAttr { type => 'hash', build => sub {{}}, clone => 'hash' } |
|
58 | 37 |
|
59 |
-sub result_class : ClassObjectAttr { |
|
60 |
- initialize => { |
|
61 |
- clone => 'scalar', |
|
62 |
- default => 'DBIx::Custom::Result' |
|
63 |
- } |
|
64 |
-} |
|
38 |
+sub filters : HybridAttr { type => 'hash', build => sub {{}}, |
|
39 |
+ clone => 'hash', deref => 1 } |
|
65 | 40 |
|
66 |
-sub sql_tmpl : ClassObjectAttr { |
|
67 |
- initialize => { |
|
68 |
- clone => sub {$_[0] ? $_[0]->clone : undef}, |
|
69 |
- default => sub {DBIx::Custom::SQL::Template->new} |
|
70 |
- } |
|
71 |
-} |
|
41 |
+sub formats : HybridAttr { type => 'hash', build => sub { {} }, |
|
42 |
+ clone => 'hash', deref => 1 } |
|
72 | 43 |
|
73 |
-sub dbh : Attr {} |
|
44 |
+sub result_class : HybridAttr { build => 'DBIx::Custom::Result', |
|
45 |
+ clone => 'scalar' } |
|
74 | 46 |
|
47 |
+sub sql_tmpl : HybridAttr { build => sub {DBIx::Custom::SQL::Template->new}, |
|
48 |
+ clone => sub {$_[0] ? $_[0]->clone : undef} } |
|
75 | 49 |
|
76 | 50 |
### Methods |
77 | 51 |
|
... | ... |
@@ -732,14 +706,6 @@ sub select { |
732 | 706 |
return $result; |
733 | 707 |
} |
734 | 708 |
|
735 |
-sub _query_caches : ClassAttr { type => 'hash', |
|
736 |
- auto_build => sub {shift->_query_caches({}) } } |
|
737 |
- |
|
738 |
-sub _query_cache_keys : ClassAttr { type => 'array', |
|
739 |
- auto_build => sub {shift->_query_cache_keys([])} } |
|
740 |
- |
|
741 |
-sub query_cache_max : ClassAttr { auto_build => sub {shift->query_cache_max(50)} } |
|
742 |
- |
|
743 | 709 |
sub _add_query_cache { |
744 | 710 |
my ($class, $template, $query) = @_; |
745 | 711 |
my $query_cache_keys = $class->_query_cache_keys; |
... | ... |
@@ -1,5 +1,5 @@ |
1 | 1 |
package DBIx::Custom::SQL::Template; |
2 |
-use Object::Simple; |
|
2 |
+use Object::Simple; Object::Simple->build_class; |
|
3 | 3 |
|
4 | 4 |
use strict; |
5 | 5 |
use warnings; |
... | ... |
@@ -7,23 +7,21 @@ use Carp 'croak'; |
7 | 7 |
|
8 | 8 |
use DBIx::Custom::Query; |
9 | 9 |
|
10 |
-# Accessor is created by Object::Simple. |
|
11 |
- |
|
12 |
-### Class-Object accessors |
|
13 |
- |
|
14 |
-# Tag start |
|
15 |
-sub tag_start : ClassObjectAttr { |
|
16 |
- initialize => {default => '{', clone => 'scalar'} |
|
17 |
-} |
|
18 |
- |
|
19 |
-# Tag end |
|
20 |
-sub tag_end : ClassObjectAttr { |
|
21 |
- initialize => {default => '}', clone => 'scalar'} |
|
22 |
-} |
|
23 |
- |
|
24 |
-# Tag syntax |
|
25 |
-sub tag_syntax : ClassObjectAttr { |
|
26 |
- initialize => {default => <<'EOS', clone => 'scalar'}} |
|
10 |
+__PACKAGE__->add_tag_processor( |
|
11 |
+ '?' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
12 |
+ '=' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
13 |
+ '<>' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
14 |
+ '>' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
15 |
+ '<' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
16 |
+ '>=' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
17 |
+ '<=' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
18 |
+ 'like' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
19 |
+ 'in' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_in_tag, |
|
20 |
+ 'insert' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_insert_tag, |
|
21 |
+ 'update' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_update_tag |
|
22 |
+); |
|
23 |
+ |
|
24 |
+__PACKAGE__->tag_syntax(<< 'EOS'); |
|
27 | 25 |
[tag] [expand] |
28 | 26 |
{? name} ? |
29 | 27 |
{= name} name = ? |
... | ... |
@@ -41,27 +39,16 @@ sub tag_syntax : ClassObjectAttr { |
41 | 39 |
{update key1 key2} set key1 = ?, key2 = ? |
42 | 40 |
EOS |
43 | 41 |
|
44 |
-# Tag processors |
|
45 |
-sub tag_processors : ClassObjectAttr { |
|
46 |
- type => 'hash', |
|
47 |
- deref => 1, |
|
48 |
- initialize => { |
|
49 |
- clone => 'hash', |
|
50 |
- default => sub {{ |
|
51 |
- '?' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
52 |
- '=' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
53 |
- '<>' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
54 |
- '>' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
55 |
- '<' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
56 |
- '>=' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
57 |
- '<=' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
58 |
- 'like' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_basic_tag, |
|
59 |
- 'in' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_in_tag, |
|
60 |
- 'insert' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_insert_tag, |
|
61 |
- 'update' => \&DBIx::Custom::SQL::Template::TagProcessors::expand_update_tag |
|
62 |
- }} |
|
63 |
- } |
|
64 |
-} |
|
42 |
+# Accessor is created by Object::Simple. |
|
43 |
+ |
|
44 |
+### Class-Object accessors |
|
45 |
+ |
|
46 |
+ |
|
47 |
+sub tag_start : HybridAttr { build => '{', clone => 'scalar' } |
|
48 |
+sub tag_end : HybridAttr { build => '}', clone => 'scalar' } |
|
49 |
+sub tag_syntax : HybridAttr { clone => 'scalar' } |
|
50 |
+sub tag_processors : HybridAttr { type => 'hash', build => sub {{}}, |
|
51 |
+ clone => 'hash', deref => 1 } |
|
65 | 52 |
|
66 | 53 |
# Add Tag processor |
67 | 54 |
sub add_tag_processor { |
... | ... |
@@ -234,7 +221,7 @@ sub _placeholder_count { |
234 | 221 |
return $count; |
235 | 222 |
} |
236 | 223 |
|
237 |
-Object::Simple->build_class; |
|
224 |
+1; |
|
238 | 225 |
|
239 | 226 |
|
240 | 227 |
package DBIx::Custom::SQL::Template::TagProcessors; |