| 1 | package Application::Pipeline::Services::DBI; | ||
| 2 | $VERSION = '0.1.1'; | ||
| 3 | |||
| 4 | #-- pragmas ---------------------------- | ||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | #-- modules ---------------------------- | ||
| 9 | use DBI; | ||
| 10 | |||
| 11 | =head1 Application::Pipeline::Services::DBI | ||
| 12 | |||
| 13 | This plugin for Application::Pipeline makes available a singleton database | ||
| 14 | handle. To access it from the application: | ||
| 15 | |||
| 16 | $pipeline->loadPlugin( 'DBI' ( dbi::connect parameters ) ); | ||
| 17 | |||
| 18 | $dbh = $pipeline->dbh; | ||
| 19 | |||
| 20 | =cut | ||
| 21 | |||
| 22 | #=============================================================================== | ||
| 23 | |||
| 24 | our $dbh = undef; | ||
| 25 | |||
| 26 | sub load { | ||
| 27 | my( $class, $pipeline, @args ) = @_; | ||
| 28 | $dbh ||= DBI->connect( @args ); | ||
| 29 | |||
| 30 | $pipeline->addServices( dbh => $dbh ); | ||
| 31 | $pipeline->addHandler( 'Teardown', sub{ $dbh->disconnect() }, 'LAST' ); | ||
| 32 | return $dbh; | ||
| 33 | } | ||
| 34 | |||
| 35 | #======== | ||
| 36 | 1; | ||
| 37 | |||
| 38 | =head2 Authors | ||
| 39 | |||
| 40 | Stephen Howard <stephen@thunkit.com> | ||
| 41 | |||
| 42 | =head2 License | ||
| 43 | |||
| 44 | This module may be distributed under the same terms as Perl itself. | ||
| 45 | |||
| 46 | =cut |