Codebase list libexception-class-dbi-perl / cabe8ae
Always return the same code ref for the same class. David Wheeler 17 years ago
3 changed file(s) with 16 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
00 Revision history for Perl extension Exception::Class::DBI.
11
22 0.94
3 - The handler() method now always returns the same code referernce
4 each time it's called for a given subclass. This behavior prevents
5 the DBI connect_cached() method from caching a new database handle
6 every time it's called, which could otherwise be pretty annoying.
37
48 0.93 2006-06-10T02:09:14
59 - Reformatted some of the code and documentation so that it's
3939 }
4040 );
4141
42 my %handlers;
4243 sub handler {
4344 my $pkg = shift;
45 return $handlers{$pkg} if $handlers{$pkg};
4446
4547 # Support subclasses.
4648 my %class_for = map {
5860 }
5961 } qw(H DRH DBH STH Unknown);
6062
61 return sub {
63 return $handlers{$pkg} = sub {
6264 my ($err, $dbh, $retval) = @_;
6365
6466 # No handle, no choice.
00 #!/usr/bin/perl -w
11
22 use strict;
3 use Test::More tests => 9;
3 use Test::More tests => 12;
44 BEGIN { use_ok('Exception::Class::DBI') }
55
66 SUBCLASSES: {
2424 }
2525
2626 use DBI;
27
28 # Make sure that the same handler is used every time.
29 is +MyApp::Ex::DBI->handler, MyApp::Ex::DBI->handler,
30 'The handler code ref should always be the same for the subclass';
31 is +Exception::Class::DBI->handler, Exception::Class::DBI->handler,
32 'The base class handler should always be the same code ref';
33 isnt +MyApp::Ex::DBI->handler, Exception::Class::DBI->handler,
34 'The subclass handler should be different from the base class handler';
2735
2836 ok my $dbh = DBI->connect('dbi:ExampleP:dummy', '', '', {
2937 PrintError => 0,