File Coverage

blib/lib/DBIx/SQLite/Simple.pm
Criterion Covered Total %
statement 16 23 69.5
branch 3 10 30.0
condition n/a
subroutine 5 7 71.4
pod 3 3 100.0
total 27 43 62.7


line stmt bran cond sub pod time code
1             #
2             # $Id: Simple.pm,v 1.14 2007/01/27 13:35:02 gomor Exp $
3             #
4             package DBIx::SQLite::Simple;
5 4     4   10308 use strict;
  4         9  
  4         163  
6 4     4   25 use warnings;
  4         9  
  4         138  
7 4     4   33 use Carp;
  4         13  
  4         2007  
8              
9             our $VERSION = '0.34';
10              
11             require DBI;
12             require Class::Gomor::Array;
13             our @ISA = qw(Class::Gomor::Array);
14              
15             our @AS = qw(
16             db
17             _dbh
18             );
19             __PACKAGE__->cgBuildIndices;
20             __PACKAGE__->cgBuildAccessorsScalar(\@AS);
21              
22             our $Dbo;
23              
24             =head1 NAME
25              
26             DBIx::SQLite::Simple - easy access to SQLite databases using objects
27              
28             =head1 ATTRIBUTES
29              
30             =over 4
31              
32             =item B
33              
34             Used to store the filename containing the SQLite database.
35              
36             =back
37              
38             =head1 METHODS
39              
40             =over 4
41              
42             =item B(db => 'filename.db')
43              
44             Object creator. Takes one argument, and sets the global variable $Dbo to the newly created database handler.
45              
46             =cut
47              
48             sub new {
49 3     3 1 569 my $self = shift->SUPER::new(@_);
50              
51 3 50       321 confess('Usage: new(db => $db)') unless $self->db;
52              
53 3 50       147 my $dbh = DBI->connect(
54             'dbi:SQLite:dbname='. $self->db,
55             '', '',
56             {
57             RaiseError => 0,
58             PrintError => 0,
59             PrintWarn => 0,
60             AutoCommit => 0,
61             },
62             ) or croak("new: ". $DBI::errstr);
63              
64 3         52251 $self->_dbh($dbh);
65              
66 3         87 $Dbo = $self;
67             }
68              
69             =item B
70              
71             Changes made on created database are not automatically commited. You must call this method if you want to commit pending changes.
72              
73             =cut
74              
75             sub commit {
76 8     8 1 102 my $self = shift;
77 8 50       29 $self->_dbh->commit if $self->_dbh;
78             }
79              
80             =item B
81              
82             When you're done using the database, you can disconnect from it. This method will not commit changes, so do it before closing.
83              
84             =cut
85              
86             sub close {
87 0     0 1   my $self = shift;
88 0 0         $self->_dbh->disconnect if $self->_dbh;
89 0           $self->_dbh(undef);
90             }
91              
92             sub DESTROY {
93 0     0     my $self = shift;
94              
95 0 0         if ($self->_dbh) {
96 0           $self->commit;
97 0           $self->close;
98             }
99             }
100              
101             =back
102              
103             =head1 AUTHOR
104              
105             Patrice EGomoRE Auffret
106              
107             =head1 COPYRIGHT AND LICENSE
108              
109             Copyright (c) 2005-2007, Patrice EGomoRE Auffret
110              
111             You may distribute this module under the terms of the Artistic license.
112             See LICENSE.Artistic file in the source distribution archive.
113              
114             =cut
115              
116             1;