├── .gitignore ├── t ├── 00_compile.t └── test.t ├── .shipit ├── Changes ├── xt ├── synopsis.t ├── pod.t ├── perlcritic.t └── podspell.t ├── MANIFEST.SKIP ├── Makefile.PL ├── MANIFEST ├── README └── lib └── AnyEvent └── DBI └── Abstract.pm /.gitignore: -------------------------------------------------------------------------------- 1 | META.yml 2 | Makefile 3 | inc/ 4 | pm_to_blib 5 | *~ 6 | -------------------------------------------------------------------------------- /t/00_compile.t: -------------------------------------------------------------------------------- 1 | use strict; 2 | use Test::More tests => 1; 3 | 4 | BEGIN { use_ok 'AnyEvent::DBI::Abstract' } 5 | -------------------------------------------------------------------------------- /.shipit: -------------------------------------------------------------------------------- 1 | steps = FindVersion, ChangeVersion, CheckChangeLog, DistTest, Commit, Tag, MakeDist, UploadCPAN 2 | git.push_to = origin 3 | -------------------------------------------------------------------------------- /Changes: -------------------------------------------------------------------------------- 1 | Revision history for Perl extension AnyEvent::DBI::Abstract 2 | 3 | 0.01 Sat Jan 2 22:55:53 2010 4 | - original version 5 | -------------------------------------------------------------------------------- /xt/synopsis.t: -------------------------------------------------------------------------------- 1 | use Test::More; 2 | eval "use Test::Synopsis"; 3 | plan skip_all => "Test::Synopsis required" if $@; 4 | all_synopsis_ok(); 5 | -------------------------------------------------------------------------------- /xt/pod.t: -------------------------------------------------------------------------------- 1 | use Test::More; 2 | eval "use Test::Pod 1.00"; 3 | plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; 4 | all_pod_files_ok(); 5 | -------------------------------------------------------------------------------- /xt/perlcritic.t: -------------------------------------------------------------------------------- 1 | use strict; 2 | use Test::More; 3 | eval q{ use Test::Perl::Critic }; 4 | plan skip_all => "Test::Perl::Critic is not installed." if $@; 5 | all_critic_ok("lib"); 6 | -------------------------------------------------------------------------------- /MANIFEST.SKIP: -------------------------------------------------------------------------------- 1 | \bRCS\b 2 | \bCVS\b 3 | \.svn/ 4 | \.git/ 5 | ^MANIFEST\. 6 | ^Makefile$ 7 | ~$ 8 | \.old$ 9 | ^blib/ 10 | ^pm_to_blib 11 | ^MakeMaker-\d 12 | \.gz$ 13 | \.cvsignore 14 | \.shipit 15 | -------------------------------------------------------------------------------- /xt/podspell.t: -------------------------------------------------------------------------------- 1 | use Test::More; 2 | eval q{ use Test::Spelling }; 3 | plan skip_all => "Test::Spelling is not installed." if $@; 4 | add_stopwords(); 5 | set_spell_cmd("aspell -l en list"); 6 | all_pod_files_spelling_ok('lib'); 7 | __DATA__ 8 | Tatsuhiko 9 | Miyagawa 10 | -------------------------------------------------------------------------------- /Makefile.PL: -------------------------------------------------------------------------------- 1 | use inc::Module::Install; 2 | name 'AnyEvent-DBI-Abstract'; 3 | all_from 'lib/AnyEvent/DBI/Abstract.pm'; 4 | readme_from 'lib/AnyEvent/DBI/Abstract.pm'; 5 | requires 'parent'; 6 | requires 'AnyEvent::DBI'; 7 | requires 'SQL::Abstract'; 8 | build_requires 'Test::More'; 9 | test_requires 'Test::Requires'; 10 | auto_include_deps; 11 | author_tests('xt'); 12 | auto_set_repository; 13 | WriteAll; 14 | -------------------------------------------------------------------------------- /MANIFEST: -------------------------------------------------------------------------------- 1 | .gitignore 2 | Changes 3 | inc/Module/Install.pm 4 | inc/Module/Install/AuthorTests.pm 5 | inc/Module/Install/Base.pm 6 | inc/Module/Install/Can.pm 7 | inc/Module/Install/Fetch.pm 8 | inc/Module/Install/Include.pm 9 | inc/Module/Install/Makefile.pm 10 | inc/Module/Install/Metadata.pm 11 | inc/Module/Install/ReadmeFromPod.pm 12 | inc/Module/Install/Repository.pm 13 | inc/Module/Install/Win32.pm 14 | inc/Module/Install/WriteAll.pm 15 | inc/Test/Builder/Module.pm 16 | inc/Test/Requires.pm 17 | lib/AnyEvent/DBI/Abstract.pm 18 | Makefile.PL 19 | MANIFEST This list of files 20 | META.yml 21 | README 22 | t/00_compile.t 23 | t/test.t 24 | xt/perlcritic.t 25 | xt/pod.t 26 | xt/podspell.t 27 | xt/synopsis.t 28 | -------------------------------------------------------------------------------- /t/test.t: -------------------------------------------------------------------------------- 1 | use Test::More; 2 | use Test::Requires qw(DBD::SQLite); 3 | use AnyEvent::DBI::Abstract; 4 | 5 | sub sync(&;&) { 6 | my $block = shift; 7 | my $cb = shift; 8 | my $cv = AnyEvent->condvar; 9 | $cv->cb(sub { $cb->($_[0]->recv) }) if $cb; 10 | $block->($cv); 11 | $cv->recv; 12 | } 13 | 14 | my $dbh = AnyEvent::DBI::Abstract->new("dbi:SQLite:dbname=t/test.db", "", ""); 15 | sync { $dbh->exec("create table foo (id integer, foo text)", @_) }; 16 | 17 | sync { $dbh->select("foo", @_) } sub { 18 | my($dbh, $rows, $rv) = @_; 19 | is_deeply $rows, []; 20 | }; 21 | 22 | sync { $dbh->insert("foo", { id => 1, foo => "value" }, @_) }; 23 | 24 | sync { $dbh->select("foo", @_) } sub { 25 | my($dbh, $rows, $rv) = @_; 26 | is_deeply $rows, [ [ 1, "value" ] ]; 27 | }; 28 | 29 | done_testing; 30 | 31 | END { unlink "t/test.db" } 32 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | NAME 2 | AnyEvent::DBI::Abstract - AnyEvent::DBI + SQL::Abstract 3 | 4 | SYNOPSIS 5 | use AnyEvent::DBI::Abstract; 6 | 7 | my $dbh = AnyEvent::DBI::Abstract->new($dsn, $user, $pass); 8 | 9 | $dbh->select($table, \@fields, \%where, \@order, sub { 10 | my($dbh, $rows, $rv) = @_; 11 | # ... 12 | }); 13 | 14 | $dbh->insert($table, \%fieldvals, sub { 15 | my($dbh, undef, $rv) = @_; 16 | # ... 17 | }); 18 | 19 | $dbh->update($table, \%fieldvals, \%where, sub { 20 | my($dbh, undef, $rv) = @_; 21 | # ... 22 | }); 23 | 24 | $dbh->delete($table, \%where, sub { 25 | my($dbh, undef, $rv) = @_; 26 | # ... 27 | }); 28 | 29 | DESCRIPTION 30 | AnyEvent::DBI::Abstract is a subclass of AnyEvent::DBI that has methods 31 | to wrap SQL::Abstract methods into "exec". See SQL::Abstract for the 32 | parameters to the methods and AnyEvent::DBI for the callback interface. 33 | 34 | AUTHOR 35 | Tatsuhiko Miyagawa 36 | 37 | LICENSE 38 | This library is free software; you can redistribute it and/or modify it 39 | under the same terms as Perl itself. 40 | 41 | SEE ALSO 42 | AnyEvent::DBI SQL::Abstract 43 | 44 | -------------------------------------------------------------------------------- /lib/AnyEvent/DBI/Abstract.pm: -------------------------------------------------------------------------------- 1 | package AnyEvent::DBI::Abstract; 2 | 3 | use strict; 4 | use 5.008_001; 5 | our $VERSION = '0.01'; 6 | 7 | use parent qw(AnyEvent::DBI); 8 | use Carp (); 9 | use SQL::Abstract; 10 | no strict 'refs'; 11 | 12 | sub abstract { 13 | my $self = shift; 14 | $self->{_DBI_abstract} ||= SQL::Abstract->new; 15 | } 16 | 17 | for my $method (qw( select insert update delete )) { 18 | *$method = sub { 19 | my($self, @args) = @_; 20 | my $cb = pop @args; 21 | my($stmt, @bind) = $self->abstract->$method(@args); 22 | $self->exec($stmt, @bind, $cb); 23 | }; 24 | } 25 | 26 | 1; 27 | __END__ 28 | 29 | =encoding utf-8 30 | 31 | =for stopwords 32 | 33 | =head1 NAME 34 | 35 | AnyEvent::DBI::Abstract - AnyEvent::DBI + SQL::Abstract 36 | 37 | =head1 SYNOPSIS 38 | 39 | use AnyEvent::DBI::Abstract; 40 | 41 | my $dbh = AnyEvent::DBI::Abstract->new($dsn, $user, $pass); 42 | 43 | $dbh->select($table, \@fields, \%where, \@order, sub { 44 | my($dbh, $rows, $rv) = @_; 45 | # ... 46 | }); 47 | 48 | $dbh->insert($table, \%fieldvals, sub { 49 | my($dbh, undef, $rv) = @_; 50 | # ... 51 | }); 52 | 53 | $dbh->update($table, \%fieldvals, \%where, sub { 54 | my($dbh, undef, $rv) = @_; 55 | # ... 56 | }); 57 | 58 | $dbh->delete($table, \%where, sub { 59 | my($dbh, undef, $rv) = @_; 60 | # ... 61 | }); 62 | 63 | =head1 DESCRIPTION 64 | 65 | AnyEvent::DBI::Abstract is a subclass of AnyEvent::DBI that has 66 | methods to wrap SQL::Abstract methods into C. See 67 | L for the parameters to the methods and 68 | L for the callback interface. 69 | 70 | =head1 AUTHOR 71 | 72 | Tatsuhiko Miyagawa Emiyagawa@bulknews.netE 73 | 74 | =head1 LICENSE 75 | 76 | This library is free software; you can redistribute it and/or modify 77 | it under the same terms as Perl itself. 78 | 79 | =head1 SEE ALSO 80 | 81 | L L 82 | 83 | =cut 84 | --------------------------------------------------------------------------------