Commit | Line | Data |
---|---|---|
ea2e61bf | 1 | package DBIx::Class::DB; |
2 | ||
1edd1722 | 3 | use base qw/DBIx::Class/; |
8b445e33 | 4 | use DBIx::Class::Storage::DBI; |
11b78bd6 | 5 | use DBIx::Class::ClassResolver::PassThrough; |
604d9f38 | 6 | use DBI; |
ea2e61bf | 7 | |
34d52be2 | 8 | =head1 NAME |
9 | ||
8b445e33 | 10 | DBIx::Class::DB - Simple DBIx::Class Database connection by class inheritance |
34d52be2 | 11 | |
12 | =head1 SYNOPSIS | |
13 | ||
8b445e33 | 14 | package MyDB; |
15 | ||
16 | use base qw/DBIx::Class/; | |
503536d5 | 17 | __PACKAGE__->load_components('DB'); |
8b445e33 | 18 | |
19 | __PACKAGE__->connection('dbi:...', 'user', 'pass', \%attrs); | |
20 | ||
21 | package MyDB::MyTable; | |
22 | ||
23 | use base qw/MyDB/; | |
503536d5 | 24 | __PACKAGE__->load_components('Core'); |
4a9d7cae | 25 | |
26 | ... | |
8b445e33 | 27 | |
34d52be2 | 28 | =head1 DESCRIPTION |
29 | ||
8b445e33 | 30 | This class provides a simple way of specifying a database connection. |
34d52be2 | 31 | |
32 | =head1 METHODS | |
33 | ||
34 | =over 4 | |
35 | ||
076652e8 | 36 | |
37 | =item storage | |
38 | ||
39 | Which storage backend to be used. Defaults to L<DBIx::Class::Storage::DBI> | |
40 | ||
41 | =item class_resolver | |
42 | ||
43 | Which class to use for resolving a class. Defaults to | |
44 | L<DBIx::Class::ClassResolver::Passthrough>, which returns whatever you throw | |
45 | at it. See resolve_class below. | |
46 | ||
34d52be2 | 47 | =cut |
48 | ||
8b445e33 | 49 | __PACKAGE__->mk_classdata('storage'); |
11b78bd6 | 50 | __PACKAGE__->mk_classdata('class_resolver' => |
51 | 'DBIx::Class::ClassResolver::PassThrough'); | |
8fe001e1 | 52 | |
39fe0e65 | 53 | =item connection |
54 | ||
55 | __PACKAGE__->connection($dsn, $user, $pass, $attrs); | |
56 | ||
57 | Specifies the arguments that will be passed to DBI->connect(...) to | |
58 | instantiate the class dbh when required. | |
59 | ||
60 | =cut | |
61 | ||
8fe001e1 | 62 | sub connection { |
63 | my ($class, @info) = @_; | |
8b445e33 | 64 | my $storage = DBIx::Class::Storage::DBI->new; |
65 | $storage->connect_info(\@info); | |
66 | $class->storage($storage); | |
ea2e61bf | 67 | } |
68 | ||
39fe0e65 | 69 | =item dbi_commit |
70 | ||
71 | $class->dbi_commit; | |
72 | ||
73 | Issues a commit again the current dbh | |
74 | ||
75 | =cut | |
76 | ||
8b445e33 | 77 | sub dbi_commit { $_[0]->storage->commit; } |
a29644e1 | 78 | |
39fe0e65 | 79 | =item dbi_rollback |
80 | ||
81 | $class->dbi_rollback; | |
82 | ||
83 | Issues a rollback again the current dbh | |
84 | ||
85 | =cut | |
86 | ||
8b445e33 | 87 | sub dbi_rollback { $_[0]->storage->rollback; } |
88 | ||
11b78bd6 | 89 | sub resolve_class { return shift->class_resolver->class(@_); } |
90 | ||
ea2e61bf | 91 | 1; |
34d52be2 | 92 | |
93 | =back | |
94 | ||
95 | =head1 AUTHORS | |
96 | ||
daec44b8 | 97 | Matt S. Trout <mst@shadowcatsystems.co.uk> |
34d52be2 | 98 | |
99 | =head1 LICENSE | |
100 | ||
101 | You may distribute this code under the same terms as Perl itself. | |
102 | ||
103 | =cut | |
104 |