Showing 2 changed files with 49 additions and 3 deletions
+39 -2
lib/DBI/Custom.pm
... ...
@@ -58,6 +58,7 @@ sub filters : Attr { type => 'hash', deref => 1, auto_build => sub { shift->filt
58 58
 sub add_filter { shift->filters(@_) }
59 59
 
60 60
 sub dbh          : Attr { auto_build => sub { shift->connect } }
61
+sub sql_template : Attr { auto_build => sub { shift->sql_template(DBI::Custom::SQLTemplate->new) } }
61 62
 
62 63
 our %VALID_CONNECT_INFO = map {$_ => 1} qw/data_source user password options/;
63 64
 
... ...
@@ -66,7 +67,8 @@ sub connect {
66 67
     my $connect_info = $self->connect_info;
67 68
     
68 69
     foreach my $key (keys %{$self->connect_info}) {
69
-        
70
+        croak("connect_info '$key' is invald")
71
+          unless $VALID_CONNECT_INFO{$key};
70 72
     }
71 73
     
72 74
     my $dbh = DBI->connect(
... ...
@@ -84,15 +86,44 @@ sub connect {
84 86
     $self->dbh($dbh);
85 87
 }
86 88
 
89
+sub create_sql {
90
+    my $self = shift;
91
+    
92
+    my ($sql, @bind) = $self->sql_template->create_sql(@_);
93
+    
94
+    return ($sql, @bind);
95
+}
96
+
87 97
 sub query {
98
+    my $self = shift;
99
+    my ($sql, @bind) = $self->creqte_sql(@_);
100
+    $self->prepare($sql);
101
+    $self->execute(@bind);
102
+}
103
+
104
+sub query_raw_sql {
105
+    my ($self, $sql, @bind) = @_;
106
+    $self->prepare($sql);
107
+    $self->execute(@bind);
108
+}
109
+
110
+Object::Simple->build_class;
111
+
112
+package DBI::Custom::SQLTemplate;
113
+use Object::Simple;
114
+
115
+sub create_sql {
88 116
     
89 117
 }
90 118
 
119
+
120
+
121
+
91 122
 Object::Simple->build_class;
92 123
 
93 124
 =head1 NAME
94 125
 
95
-DBI::Custom - The great new DBI::Custom!
126
+DBI::Custom - Customizable simple DBI
96 127
 
97 128
 =head1 VERSION
98 129
 
... ...
@@ -130,6 +161,12 @@ Version 0.0101
130 161
 
131 162
 =head2 query
132 163
 
164
+=head2 create_sql
165
+
166
+=head2 query_raw_sql
167
+
168
+=head2 sql_template
169
+
133 170
 =head1 AUTHOR
134 171
 
135 172
 Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >>
+10 -1
t/01-core.t
... ...
@@ -159,8 +159,17 @@ our ($U, $P, $D) = connect_info();
159 159
     
160 160
     ok(blessed $dbi->dbh);
161 161
     can_ok($dbi->dbh, qw/prepare/);
162
+}
163
+
164
+{
165
+    my $dbi = DBI::Custom->new(
166
+        connect_info => {
167
+            no_exist => 1,
168
+        }
169
+    );
170
+    eval{$dbi->connect};
162 171
     
163
-    
172
+    like($@, qr/connect_info 'no_exist' is invald/, 'no exist');
164 173
 }
165 174
 
166 175
 sub connect_info {