Showing 3 changed files with 66 additions and 2 deletions
+4 -1
Changes
... ...
@@ -1,5 +1,8 @@
1
+0.1613
2
+  added experimental register_method() method
3
+  added experimental methods attribute
1 4
 0.1612
2
-  add tests
5
+  added tests
3 6
   updated document
4 7
   removed DBIx::Custom::SQLite last_insert_rawid() mehtod(not backword compatible)
5 8
   removed DBIx::Custom::MySQL last_insert_id() method(not backword compatible)
+49 -1
lib/DBIx/Custom.pm
... ...
@@ -474,13 +474,39 @@ sub _check_filter {
474 474
     }
475 475
 }
476 476
 
477
+__PACKAGE__->attr('methods' => sub { {} });
478
+
479
+sub register_method {
480
+    my $self = shift;
481
+    
482
+    # Register method
483
+    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
484
+    $self->methods({%{$self->methods}, %$methods});
485
+    
486
+    return $self;
487
+}
488
+
489
+our $AUTOLOAD;
490
+sub AUTOLOAD {
491
+    my $self = shift;
492
+    my $method = $AUTOLOAD;
493
+    $method =~ s/.*:://;
494
+   
495
+   return if $method eq 'DESTROY';
496
+   
497
+   croak qq{Method "$method" is not registered"}
498
+     unless $self->methods->{$method};
499
+   
500
+   return $self->methods->{$method}->($self, @_);
501
+}
502
+
477 503
 =head1 NAME
478 504
 
479 505
 DBIx::Custom - DBI interface, having hash parameter binding and filtering system
480 506
 
481 507
 =cut
482 508
 
483
-our $VERSION = '0.1612';
509
+our $VERSION = '0.1613';
484 510
 
485 511
 =head1 STABILITY
486 512
 
... ...
@@ -1213,6 +1239,13 @@ Default to 1.
1213 1239
 This check maybe damege performance.
1214 1240
 If you require performance, set C<filter_check> attribute to 0.
1215 1241
 
1242
+=head2 C<(experimental) methods>
1243
+
1244
+    my $methods = $dbi->methods;
1245
+    $dbi        = $dbi->methods(\%methods);
1246
+
1247
+Additional methods.
1248
+
1216 1249
 =head1 METHODS
1217 1250
 
1218 1251
 L<DBIx::Custom> inherits all methods from L<Object::Simple>
... ...
@@ -1475,6 +1508,21 @@ B<Example:>
1475 1508
         }
1476 1509
     );
1477 1510
 
1511
+=head2 C<(experimental) register_method>
1512
+
1513
+    $dbi->register_method(
1514
+        begin_work => sub { shift->dbh->begin_work },
1515
+        commit     => sub { shift->dbh->commit },
1516
+        rollback   => sub { shift->dbh->rollback}
1517
+    );
1518
+
1519
+Register methods to the object. You can call these methods
1520
+from the object.
1521
+
1522
+    $dbi->begin_work;
1523
+    $dbi->commit;
1524
+    $dbi->rollback;
1525
+
1478 1526
 =head1 BUGS
1479 1527
 
1480 1528
 Please tell me bugs if found.
+13
t/dbix-custom-core-sqlite.t
... ...
@@ -21,6 +21,8 @@ sub test {
21 21
     $test = shift;
22 22
 }
23 23
 
24
+use DBIx::Custom::SQLite;
25
+
24 26
 # Constant varialbes for test
25 27
 my $CREATE_TABLE = {
26 28
     0 => 'create table table1 (key1 char(255), key2 char(255));',
... ...
@@ -554,3 +556,14 @@ ok($@, "$test: execute fail");
554 556
 eval{$dbi->create_query('select * from table1 where {0 key1}')};
555 557
 like($@, qr/\Q.t /, "$test : caller spec");
556 558
 
559
+
560
+test 'register_method';
561
+$dbi = DBIx::Custom::SQLite->new;
562
+$dbi->register_method(
563
+    one => sub { 1 },
564
+);
565
+$dbi->register_method({
566
+    two => sub { 2 }
567
+});
568
+is($dbi->one, 1, "$test : hash");
569
+is($dbi->two, 2, "$test : hash reference");