File Coverage

blib/lib/DBIx/QuickORM/ORM.pm
Criterion Covered Total %
statement 32 39 82.0
branch 8 14 57.1
condition 4 9 44.4
subroutine 9 12 75.0
pod 0 7 0.0
total 53 81 65.4


line stmt bran cond sub pod time code
1             package DBIx::QuickORM::ORM;
2 24     24   21259 use strict;
  24         68  
  24         1258  
3 24     24   148 use warnings;
  24         68  
  24         2270  
4              
5             our $VERSION = '0.000019';
6              
7 24     24   206 use Carp qw/croak/;
  24         52  
  24         1742  
8              
9 24     24   34366 use DBIx::QuickORM::Connection;
  24         106  
  24         1517  
10              
11 24         185 use DBIx::QuickORM::Util::HashBase qw{
12             <name
13             +db
14             <schema
15             <autofill
16             <row_class
17             <created
18             <compiled
19             cache_class
20             <default_handle_class
21              
22             +connection
23 24     24   226 };
  24         55  
24              
25             sub init {
26 27     27 0 69 my $self = shift;
27              
28 27 50       197 delete $self->{+NAME} unless defined $self->{+NAME};
29              
30             croak "You must either provide the 'schema' attribute or enable 'autofill'"
31 27 50 66     246 unless $self->{+SCHEMA} || $self->{+AUTOFILL};
32             }
33              
34             sub db {
35 24     24 0 57 my $self = shift;
36              
37 24 100       134 if (@_) {
38 1 50       5 croak "'db' has already been set" if $self->{+DB};
39 1 50       5 croak "Too many arguments" if @_ > 1;
40 1         5 ($self->{+DB}) = @_;
41             }
42              
43 24   33     162 return $self->{+DB} // croak "'db' has not been set";
44             }
45              
46             sub connect {
47 23     23 0 84 my $self = shift;
48              
49 23 50       101 croak "'db' has not been set" unless $self->{+DB};
50              
51 23         91 my %params = (orm => $self);
52 23 50       116 $params{cache} = $self->{+CACHE_CLASS}->new() if $self->{+CACHE_CLASS};
53              
54 23         69 $params{+DEFAULT_HANDLE_CLASS} = $self->{+DEFAULT_HANDLE_CLASS};
55              
56 23         139 return DBIx::QuickORM::Connection->new(%params);
57             }
58              
59             sub disconnect {
60 0     0 0 0 my $self = shift;
61 0         0 delete $self->{+CONNECTION};
62             }
63              
64             sub reconnect {
65 0     0 0 0 my $self = shift;
66 0         0 $self->disconnect;
67 0         0 return $self->connection;
68             }
69              
70             sub connection {
71 2     2 0 5 my $self = shift;
72 2   33     14 return $self->{+CONNECTION} //= $self->connect;
73             }
74              
75             sub handle {
76 0     0 0   my $self = shift;
77 0           return $self->connection->handle(@_);
78             }
79              
80             1;