Core.pm

filter: Statementstmt 9.0% 12 / 133 Branchbran 0.0% 0 / 68 Conditioncond 0.0% 0 / 50 MC/DCmcdc 0.0% 0 / 29 Subroutinesub 25.0% 3 / 12 Podpod 100% 1 / 1 totaltotal 5.4% 16 / 293 SCAR 79.6
CC
57
Cov
5%
_get_connection
650.0
database
462.0
_get_settings
42.0
CRAP 2861.9
↑ Summary Core/Handle.pm »
1 package Dancer::Plugin::Database::Core;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 Dancer::Plugin::Database::Core - Shared core for D1 and D2 Database plugins
10  
11 =cut
12  
13 1 our $VERSION = '0.15';
14  
15 1 my %handles;
16 # Hashref used as key for default handle, so we don't have a magic value that
17 # the user could use for one of their connection names and cause problems
18 # (Kudos to Igor Bujna for the idea)
19 1 my $def_handle = {};
20  
21 =head1 SYNOPSIS
22  
23 This module should not be used directly. It is a shared library for
24 L<Dancer::Plugin::Database> and L<Dancer2::Plugin::Database> modules.
25  
26 =head1 METHODS
27  
28 =head2 database
29  
30 Implements the C<database> keyword.
31  
32 =cut
33  
34 sub database {
35 0 ▶ my %args = @_;
Subroutine database: not called CC=21 SCAR=61.4
Pod documented
36 0 ▶ my $arg = $args{arg} || undef;
Condition0%0/2
$args{'arg'} || undef
l!l
00
MC/DC0%0/1
$args{'arg'} || undef
$args{'arg'}
Truth table0%0/2
A
A= $args{'arg'}
Aresult
11
00
37 0 ▶ my $settings = $args{settings} || {};
Condition0%0/2
$args{'settings'} || {}
l!l
00
MC/DC0%0/1
$args{'settings'} || {}
$args{'settings'}
Truth table0%0/2
A
A= $args{'settings'}
Aresult
11
00
38 0 ▶ my $logger = $args{logger} || sub {}; ## die?
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$args{'logger'} || sub { }
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'logger'} || sub { }
$args{'logger'} sub { }
Truth table0%0/3
A || B
A= $args{'logger'}B= sub { }
ABresult
1X1
011
000
39 0 ▶ my $hook_exec = $args{hook_exec} || sub {}; ## die?
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$args{'hook_exec'} || sub { }
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'hook_exec'} || sub { }
$args{'hook_exec'} sub { }
Truth table0%0/3
A || B
A= $args{'hook_exec'}B= sub { }
ABresult
1X1
011
000
40  
41 # The key to use to store this handle in %handles. This will be either the
42 # name supplied to database(), the hashref supplied to database() (thus, as
43 # long as the same hashref of settings is passed, the same handle will be
44 # reused) or $def_handle if database() is called without args:
45 0 my $handle_key;
46 my $conn_details; # connection settings to use.
47 0 my $handle;
48  
49 # Accept a hashref of settings to use, if desired. If so, we use this
50 # hashref to look for the handle, too, so as long as the same hashref is
51 # passed to the database() keyword, we'll reuse the same handle:
52 0 ▶ if (ref $arg eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg eq 'HASH') { } 0 0 0
53 0 $handle_key = $arg;
54 0 $conn_details = _merge_settings($arg, $settings, $logger);
55 } else {
56 0 ▶ $handle_key = defined $arg ? $arg : $def_handle;
Branch: 1 branch
BranchTrueFalseTotal
defined $arg ? : 0 0 0
57 0 $conn_details = _get_settings($arg, $settings, $logger);
58 0 ▶ if (!$conn_details) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($conn_details) 0 0 0
59 0 ▶ $logger->(error => "No DB settings for " . ($arg || "default connection"));
Condition0%0/2
$arg || 'default connection'
l!l
00
MC/DC0%0/1
$arg || 'default connection'
$arg
Truth table0%0/2
A
A= $arg
Aresult
11
00
60 0 return (undef, $settings);
61 }
62 }
63  
64 # To be fork safe and thread safe, use a combination of the PID and TID (if
65 # running with use threads) to make sure no two processes/threads share
66 # handles. Implementation based on DBIx::Connector by David E. Wheeler.
67 0 my $pid_tid = $$;
68 0 ▶ $pid_tid .= '_' . threads->tid if $INC{'threads.pm'};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"threads.pm"} 0 0 0
69  
70 # OK, see if we have a matching handle
71 0 ▶ $handle = $handles{$pid_tid}{$handle_key} || {};
Condition0%0/2
$handles{$pid_tid}{$handle_key} || {}
l!l
00
MC/DC0%0/1
$handles{$pid_tid}{$handle_key} || {}
$handles{$pid_tid}{$handle_key}
Truth table0%0/2
A
A= $handles{$pid_tid}{$handle_key}
Aresult
11
00
72  
73 0 ▶ if ($handle->{dbh}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handle->{"dbh"}) 0 0 0
74 # If we should never check, go no further:
75 0 ▶ if (!$conn_details->{connection_check_threshold}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($conn_details->{"connection_check_threshold"}) 0 0 0
76 0 return ($handle->{dbh}, $settings);
77 }
78  
79 0 ▶ if ($handle->{dbh}{Active} && $conn_details->{connection_check_threshold} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($handle->{'dbh'}{'Active'} and $conn_details->{'connection_check_threshold'} and time - $handle->{'last_connection_check'} < $conn_details->{'connection_check_threshold'}) { } 0 0 0
Condition0%0/6
$handle->{"dbh"}{"Active"} and $conn_details->{"connection_check_threshold"} and time - $handle->{"last_connection_check"} < $conn_details->{"connection_check_threshold"}
!ll&&!rl&&r
000
$handle->{"dbh"}{"Active"} and $conn_details->{"connection_check_threshold"}
!ll&&!rl&&r
000
MC/DC0%0/3
$handle->{"dbh"}{"Active"} and $conn_details->{"connection_check_threshold"} and time - $handle->{"last_connection_check"} < $conn_details->{"connection_check_threshold"}
$handle->{"dbh"}{"Active"} $conn_details->{"connection_check_threshold"} time - $handle->{"last_connection_check"} < $conn_details->{"connection_check_threshold"}
Truth table0%0/4
A and B and C
A= $handle->{"dbh"}{"Active"}B= $conn_details->{"connection_check_threshold"}C= time - $handle->{"last_connection_check"} < $conn_details->{"connection_check_threshold"}
ABCresult
0XX0
10X0
1100
1111
80 time - $handle->{last_connection_check}
81 < $conn_details->{connection_check_threshold})
82 {
83 0 return ($handle->{dbh}, $settings);
84 } else {
85 0 ▶ if (_check_connection($handle->{dbh})) {
Branch: 1 branch
BranchTrueFalseTotal
if (_check_connection($handle->{'dbh'})) { } 0 0 0
86 0 $handle->{last_connection_check} = time;
87 0 return ($handle->{dbh}, $settings);
88 } else {
89  
90 0 $logger->(debug => "Database connection went away, reconnecting");
91 0 $hook_exec->('database_connection_lost', $handle->{dbh});
92  
93 0 ▶ if ($handle->{dbh}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handle->{"dbh"}) 0 0 0
94 0 eval { $handle->{dbh}->disconnect }
95 }
96  
97 # Need a new handle.
98 # Fall through to the new connection codepath to get one.
99 }
100 }
101 }
102  
103 # Get a new connection
104 0 $handle->{dbh} = _get_connection($conn_details, $logger, $hook_exec);
105  
106 0 ▶ if ($handle->{dbh}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handle->{'dbh'}) { } 0 0 0
107  
108 0 $handle->{last_connection_check} = time;
109 0 $handles{$pid_tid}{$handle_key} = $handle;
110  
111 0 ▶ if (ref $handle_key && ref $handle_key ne ref $def_handle) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $handle_key and ref $handle_key ne ref $def_handle) 0 0 0
Condition0%0/3
ref $handle_key and ref $handle_key ne ref $def_handle
!ll&&!rl&&r
000
MC/DC0%0/2
ref $handle_key and ref $handle_key ne ref $def_handle
ref $handle_key ref $handle_key ne ref $def_handle
Truth table0%0/3
A and B
A= ref $handle_keyB= ref $handle_key ne ref $def_handle
ABresult
0X0
100
111
112 # We were given a hashref of connection settings. Shove a
113 # reference to that hashref into the handle, so that the hashref
114 # doesn't go out of scope for the life of the handle.
115 # Otherwise, that area of memory could be re-used, and, given
116 # different DB settings in a hashref that just happens to have
117 # the same address, we'll happily hand back the original handle.
118 # See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=665221
119 # Thanks to Sam Kington for suggesting this fix :)
120 0 $handle->{_orig_settings_hashref} = $handle_key;
121 }
122  
123 0 return ($handle->{dbh}, $settings);
124 } else {
125 0 return (undef, $settings);
126 }
127  
128 }
129  
130  
131 sub _merge_settings {
132 0 ▶ my ($arg, $settings, $logger) = @_;
Subroutine _merge_settings: not called CC=1 SCAR=6.9
133 0 $arg->{charset} = $settings->{charset};
134  
135 0 $arg = _set_defaults($arg);
136  
137 0 return $arg;
138 }
139  
140 sub _get_settings {
141 0 ▶ my ($name, $settings, $logger) = @_;
Subroutine _get_settings: not called CC=6 SCAR=37.4
142 0 my $return_settings;
143  
144 # If no name given, just return the default settings
145 0 ▶ if (!defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $name) { } 0 0 0
146 0 $return_settings = { %$settings };
147 0 ▶ if (!$return_settings->{driver} && !$return_settings->{dsn}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($return_settings->{"driver"} or $return_settings->{"dsn"}) 0 0 0
Condition0%0/3
$return_settings->{"driver"} or $return_settings->{"dsn"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$return_settings->{"driver"} or $return_settings->{"dsn"}
$return_settings->{"driver"} $return_settings->{"dsn"}
Truth table0%0/3
A or B
A= $return_settings->{"driver"}B= $return_settings->{"dsn"}
ABresult
1X1
011
000
148 0 $logger->('error',
149 "Asked for default connection (no name given)"
150 ." but no default connection details found in config"
151 );
152 }
153 } else {
154 # If there are no named connections in the config, bail now:
155 0 ▶ return unless exists $settings->{connections};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $settings->{"connections"} 0 0 0
156  
157  
158 # OK, find a matching config for this name:
159 0 ▶ if (my $named_settings = $settings->{connections}{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $named_settings = $settings->{'connections'}{$name}) { } 0 0 0
160 # Take a (shallow) copy of the settings, so we don't change them
161 0 $return_settings = { %$named_settings };
162 } else {
163 # OK, didn't match anything
164 0 $logger->('error',
165 "Asked for a database handle named '$name' but no matching "
166 ."connection details found in config"
167 );
168 }
169 }
170  
171 0 $return_settings = _set_defaults($return_settings);
172  
173 0 return $return_settings;
174 }
175  
176 sub _set_defaults {
177 0 ▶ my $return_settings = shift;
Subroutine _set_defaults: not called CC=4 SCAR=30.0
178 # We should have something to return now; make sure we have a
179 # connection_check_threshold, then return what we found. In previous
180 # versions the documentation contained a typo mentioning
181 # connectivity-check-threshold, so support that as an alias.
182 0 ▶ if (exists $return_settings->{'connectivity-check-threshold'}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $return_settings->{"connectivity-check-threshold"} and not exists $return_settings->{"connection_check_threshold"}) 0 0 0
Condition0%0/3
exists $return_settings->{"connectivity-check-threshold"} and not exists $return_settings->{"connection_check_threshold"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $return_settings->{"connectivity-check-threshold"} and not exists $return_settings->{"connection_check_threshold"}
exists $return_settings->{"connectivity-check-threshold"} not exists $return_settings->{"connection_check_threshold"}
Truth table0%0/3
A and not(B)
A= exists $return_settings->{"connectivity-check-threshold"}B= not exists $return_settings->{"connection_check_threshold"}
ABresult
0X0
100
111
183 && !exists $return_settings->{connection_check_threshold})
184 {
185 $return_settings->{connection_check_threshold}
186 0 = delete $return_settings->{'connectivity-check-threshold'};
187 }
188  
189 # If the setting wasn't provided, default to 30 seconds; if a false value is
190 # provided, though, leave it alone. (Older versions just checked for
191 # truthiness, so a value of zero would still default to 30 seconds, which
192 # isn't ideal.)
193 0 ▶ if (!exists $return_settings->{connection_check_threshold}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $return_settings->{"connection_check_threshold"}) 0 0 0
194 0 $return_settings->{connection_check_threshold} = 30;
195 }
196  
197 0 return $return_settings;
198 }
199  
200  
201 # Given the settings to use, try to get a database connection
202 sub _get_connection {
203 0 ▶ my ($settings, $logger, $hook_exec) = @_;
Subroutine _get_connection: not called CC=25 SCAR=64.8
204  
205 0 ▶ if (!$settings->{dsn} && !$settings->{driver}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($settings->{"dsn"} or $settings->{"driver"}) 0 0 0
Condition0%0/3
$settings->{"dsn"} or $settings->{"driver"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$settings->{"dsn"} or $settings->{"driver"}
$settings->{"dsn"} $settings->{"driver"}
Truth table0%0/3
A or B
A= $settings->{"dsn"}B= $settings->{"driver"}
ABresult
1X1
011
000
206 0 die "Can't get a database connection without settings supplied!\n"
207 . "Please check you've supplied settings in config as per the "
208 . "Dancer::Plugin::Database documentation";
209 }
210  
211 # Assemble the DSN:
212 0 my $dsn = '';
213 0 my $driver = '';
214 0 ▶ if ($settings->{dsn}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($settings->{'dsn'}) { } 0 0 0
215 0 $dsn = $settings->{dsn};
216 0 ($driver) = $dsn =~ m{^dbi:([^:]+)}i;
217 } else {
218 0 $dsn = "dbi:" . $settings->{driver};
219 0 $driver = $settings->{driver};
220 0 my @extra_args;
221  
222 # DBD::SQLite wants 'dbname', not 'database', so special-case this
223 # (DBI's documentation recommends that DBD::* modules should understand
224 # 'database', but older versions of DBD::SQLite didn't; let's make
225 # things easier for our users by handling this for them):
226 # (I asked in RT #61117 for DBD::SQLite to support 'database', too; this
227 # was included in DBD::SQLite 1.33, released Mon 20 May 2011.
228 # Special-casing may as well stay, rather than forcing dependency on
229 # DBD::SQLite 1.33.
230 0 ▶ if ($driver eq 'SQLite'
Branch: 1 branch
BranchTrueFalseTotal
if ($driver eq "SQLite" and $settings->{"database"} and not $settings->{"dbname"}) 0 0 0
Condition0%0/6
$driver eq "SQLite" and $settings->{"database"} and not $settings->{"dbname"}
!ll&&!rl&&r
000
$driver eq "SQLite" and $settings->{"database"}
!ll&&!rl&&r
000
MC/DC0%0/3
$driver eq "SQLite" and $settings->{"database"} and not $settings->{"dbname"}
$driver eq "SQLite" $settings->{"database"} not $settings->{"dbname"}
Truth table0%0/4
A and B and not(C)
A= $driver eq "SQLite"B= $settings->{"database"}C= not $settings->{"dbname"}
ABCresult
0XX0
10X0
1100
1111
231 && $settings->{database} && !$settings->{dbname}) {
232 0 $settings->{dbname} = delete $settings->{database};
233 }
234  
235 0 for (qw(database dbname host port sid server)) {
236 0 ▶ if (exists $settings->{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $settings->{$_}) 0 0 0
237 0 push @extra_args, $_ . "=" . $settings->{$_};
238 }
239 }
240 0 ▶ if (my $even_more_dsn_args = $settings->{dsn_extra}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $even_more_dsn_args = $settings->{"dsn_extra"}) 0 0 0
241 0 foreach my $arg ( keys %$even_more_dsn_args ) {
242 0 push @extra_args, $arg . '=' . $even_more_dsn_args->{$arg};
243 }
244 }
245 0 ▶ $dsn .= ':' . join(';', @extra_args) if @extra_args;
Branch: 1 branch
BranchTrueFalseTotal
if @extra_args 0 0 0
246 }
247  
248 # If the app is configured to use UTF-8, the user will want text from the
249 # database in UTF-8 to Just Work, so if we know how to make that happen, do
250 # so, unless they've set the auto_utf8 plugin setting to a false value.
251 0 ▶ my $app_charset = $settings->{charset} || "";
Condition0%0/2
$settings->{'charset'} || ''
l!l
00
MC/DC0%0/1
$settings->{'charset'} || ''
$settings->{'charset'}
Truth table0%0/2
A
A= $settings->{'charset'}
Aresult
11
00
252 0 ▶ my $auto_utf8 = exists $settings->{auto_utf8} ? $settings->{auto_utf8} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $settings->{'auto_utf8'} ? : 0 0 0
253  
254 0 ▶ if (lc $app_charset eq 'utf-8' && $auto_utf8) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $app_charset eq "utf-8" and $auto_utf8) 0 0 0
Condition0%0/3
lc $app_charset eq "utf-8" and $auto_utf8
!ll&&!rl&&r
000
MC/DC0%0/2
lc $app_charset eq "utf-8" and $auto_utf8
lc $app_charset eq "utf-8" $auto_utf8
Truth table0%0/3
A and B
A= lc $app_charset eq "utf-8"B= $auto_utf8
ABresult
0X0
100
111
255 # The option to pass to the DBI->connect call depends on the driver:
256 0 my %param_for_driver = (
257 SQLite => 'sqlite_unicode',
258 mysql => 'mysql_enable_utf8',
259 Pg => 'pg_enable_utf8',
260 );
261  
262 0 my $param = $param_for_driver{$driver};
263  
264 0 ▶ if ($param && !$settings->{dbi_params}{$param}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param and not $settings->{"dbi_params"}{$param}) 0 0 0
Condition0%0/3
$param and not $settings->{"dbi_params"}{$param}
!ll&&!rl&&r
000
MC/DC0%0/2
$param and not $settings->{"dbi_params"}{$param}
$param not $settings->{"dbi_params"}{$param}
Truth table0%0/3
A and not(B)
A= $paramB= not $settings->{"dbi_params"}{$param}
ABresult
0X0
100
111
265 0 $logger->(
266 debug => "Adding $param to DBI connection params"
267 . " to enable UTF-8 support"
268 );
269 0 $settings->{dbi_params}{$param} = 1;
270 }
271 }
272  
273 # To support the database_error hook, use DBI's HandleError option
274 $settings->{dbi_params}{HandleError} = sub {
275 0 ▶ my ($error, $handle) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
276 0 $hook_exec->('database_error', $error, $handle);
277 0 };
278  
279 my $dbh = DBI->connect($dsn,
280 $settings->{username}, $settings->{password}, $settings->{dbi_params}
281 0 );
282  
283 0 ▶ if (!$dbh) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $dbh) { } 0 0 0
elsif (exists $settings->{'on_connect_do'}) { } 0 0 0
284 0 $logger->(error => "Database connection failed - " . $DBI::errstr);
285 0 $hook_exec->('database_connection_failed', $settings);
286 0 return undef;
287 } elsif (exists $settings->{on_connect_do}) {
288 my $to_do = ref $settings->{on_connect_do} eq 'ARRAY'
289 ? $settings->{on_connect_do}
290 0 ▶ : [ $settings->{on_connect_do} ];
Branch: 1 branch
BranchTrueFalseTotal
ref $settings->{'on_connect_do'} eq 'ARRAY' ? : 0 0 0
291 0 for (@$to_do) {
292 0 ▶ $dbh->do($_) or
Branch: 1 branch
BranchTrueFalseTotal
$dbh->do($_) or &$logger("error", "Failed to perform on-connect command $_") 0 0 0
293 $logger->(error => "Failed to perform on-connect command $_");
294 }
295 }
296  
297 0 $hook_exec->('database_connected', $dbh);
298  
299 # Indicate whether queries generated by quick_query() etc in
300 # Dancer::Plugin::Database::Core::Handle should be logged or not; this seemed a
301 # little dirty, but DBI's docs encourage it
302 # ("You can stash private data into DBI handles via $h->{private_..._*}..")
303 $dbh->{private_dancer_plugin_database} = {
304 0 ▶ log_queries => $settings->{log_queries} || 0,
Condition0%0/2
$settings->{'log_queries'} || 0
l!l
00
MC/DC0%0/1
$settings->{'log_queries'} || 0
$settings->{'log_queries'}
Truth table0%0/2
A
A= $settings->{'log_queries'}
Aresult
11
00
305 logger => $logger,
306 };
307  
308  
309  
310 # Re-bless it as a Dancer::Plugin::Database::Core::Handle object, to provide nice
311 # extra features (unless the config specifies a different class; if it does,
312 # this should be a subclass of Dancer::Plugin::Database::Core::Handle in order to
313 # extend the features provided by it, or a direct subclass of DBI::db (or
314 # even DBI::db itself) to bypass the features provided by D::P::D::Handle)
315 my $handle_class =
316 0 ▶ $settings->{handle_class} || 'Dancer::Plugin::Database::Core::Handle';
Condition0%0/2
$settings->{'handle_class'} || 'Dancer::Plugin::Database::Core::Handle'
l!l
00
MC/DC0%0/1
$settings->{'handle_class'} || 'Dancer::Plugin::Database::Core::Handle'
$settings->{'handle_class'}
Truth table0%0/2
A
A= $settings->{'handle_class'}
Aresult
11
00
317 0 my $package = $handle_class;
318 0 $package =~ s{::}{/}g;
319 0 $package .= '.pm';
320 0 require $package;
321  
322 0 return bless($dbh => $handle_class);
323 }
324  
325  
326  
327 # Check the connection is alive
328 sub _check_connection {
329 0 ▶ my $dbh = shift;
Subroutine _check_connection: not called CC=5 SCAR=34.0
330 0 ▶ return unless $dbh;
Branch: 1 branch
BranchTrueFalseTotal
unless $dbh 0 0 0
331 0 ▶ if ($dbh->{Active}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbh->{'Active'}) { } 0 0 0
332 0 my $result = eval { $dbh->ping };
333  
334 0 ▶ return 0 if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
335  
336 0 ▶ if (int($result)) {
Branch: 1 branch
BranchTrueFalseTotal
if (int $result) { } 0 0 0
337 # DB driver itself claims all is OK, trust it:
338 0 return 1;
339 } else {
340 # It was "0 but true", meaning the default DBI ping implementation
341 # Implement our own basic check, by performing a real simple query.
342 0 my $ok;
343 0 eval {
344 0 $ok = $dbh->do('select 1');
345 };
346 0 return $ok;
347 }
348 } else {
349 0 return;
350 }
351 }
352  
353  
354 =head1 AUTHOR
355  
356 David Precious, C<< <davidp at preshweb.co.uk> >>
357  
358 =head1 BUGS
359  
360 Please report any bugs or feature requests to C<bug-dancer-plugin-database-core at rt.cpan.org>, or through
361 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dancer-Plugin-Database-Core>. I will be notified, and then you'll
362 automatically be notified of progress on your bug as I make changes.
363  
364 =head1 SUPPORT
365  
366 You can find documentation for this module with the perldoc command.
367  
368 perldoc Dancer::Plugin::Database::Core
369  
370  
371 You can also look for information at:
372  
373 =over 4
374  
375 =item * RT: CPAN's request tracker (report bugs here)
376  
377 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dancer-Plugin-Database-Core>
378  
379 =item * AnnoCPAN: Annotated CPAN documentation
380  
381 L<http://annocpan.org/dist/Dancer-Plugin-Database-Core>
382  
383 =item * CPAN Ratings
384  
385 L<http://cpanratings.perl.org/d/Dancer-Plugin-Database-Core>
386  
387 =item * Search CPAN
388  
389 L<http://search.cpan.org/dist/Dancer-Plugin-Database-Core/>
390  
391 =back
392  
393  
394 =head1 ACKNOWLEDGEMENTS
395  
396  
397 =head1 LICENSE AND COPYRIGHT
398  
399 Copyright 2016 David Precious.
400  
401 This program is free software; you can redistribute it and/or modify it
402 under the terms of the the Artistic License (2.0). You may obtain a
403 copy of the full license at:
404  
405 L<http://www.perlfoundation.org/artistic_license_2_0>
406  
407 Any use, modification, and distribution of the Standard or Modified
408 Versions is governed by this Artistic License. By using, modifying or
409 distributing the Package, you accept this license. Do not use, modify,
410 or distribute the Package, if you do not accept this license.
411  
412 If your Modified Version has been derived from a Modified Version made
413 by someone other than you, you are nevertheless required to ensure that
414 your Modified Version complies with the requirements of this license.
415  
416 This license does not grant you the right to use any trademark, service
417 mark, tradename, or logo of the Copyright Holder.
418  
419 This license includes the non-exclusive, worldwide, free-of-charge
420 patent license to make, have made, use, er to sell, sell, import and
421 otherwise transfer the Package with respect to any patent claims
422 licensable by the Copyright Holder that are necessarily infringed by the
423 Package. If you institute patent litigation (including a cross-claim or
424 counterclaim) against any party alleging that the Package constitutes
425 direct or contributory patent infringement, then this Artistic License
426 to you shall terminate on the date that such litigation is filed.
427  
428 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
429 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
430 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
431 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
432 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
433 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
434 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
435 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
436  
437  
438 =cut
439  
440 1 1; # End of Dancer::Plugin::Database::Core
↑ Summary Core/Handle.pm »