DBIx/Class/Storage.pm

filter: Statementstmt 73.1% 117 / 160 Branchbran 60.2% 47 / 78 Conditioncond 50.0% 6 / 12 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 61.3% 27 / 44 Podpod 96.3% 26 / 27 totaltotal 68.3% 225 / 329 CC 44 SCAR 19.9
CC
44
Cov
68%
svp_rollback
27.6
svp_release
18.7
debugobj
10.4
CRAP 7.3
« DBIx/Class/CDBICompat/ColumnsAsHash.pm ↑ Summary DBIx/Class/Schema.pm »
1 package DBIx::Class::Storage;
2  
3 251 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 251 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 251 ▶use base qw/DBIx::Class/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 251 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 {
10 package # Hide from PAUSE
11 DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION;
12 251 ▶ use base 'DBIx::Class::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 }
14  
15 251 ▶use DBIx::Class::Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 251 ▶use DBIx::Class::Storage::BlockRunner;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 251 ▶use Scalar::Util qw/blessed weaken/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 251 ▶use DBIx::Class::Storage::TxnScopeGuard;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 251 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 251 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 251 __PACKAGE__->mk_group_accessors(simple => qw/debug schema transaction_depth auto_savepoint savepoints/);
23 251 __PACKAGE__->mk_group_accessors(component_class => 'cursor_class');
24  
25 251 __PACKAGE__->cursor_class('DBIx::Class::Cursor');
26  
27 0 ▶sub cursor { shift->cursor_class(@_); }
Subroutine cursor: not called CC=1 SCAR=6.9
Pod undocumented
28  
29 =head1 NAME
30  
31 DBIx::Class::Storage - Generic Storage Handler
32  
33 =head1 DESCRIPTION
34  
35 A base implementation of common Storage methods. For specific
36 information about L<DBI>-based storage, see L<DBIx::Class::Storage::DBI>.
37  
38 =head1 METHODS
39  
40 =head2 new
41  
42 Arguments: $schema
43  
44 Instantiates the Storage object.
45  
46 =cut
47  
48 sub new {
49 423 ▶ my ($self, $schema) = @_;
Subroutine new: called CC=4 SCAR=14.0
Pod documented
50  
51 423 ▶ $self = ref $self if ref $self;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 0 423 423
52  
53 423 my $new = bless( {
54 transaction_depth => 0,
55 savepoints => [],
56 }, $self);
57  
58 423 $new->set_schema($schema);
59 $new->debug(1)
60 423 ▶ if $ENV{DBIX_CLASS_STORAGE_DBI_DEBUG} || $ENV{DBIC_TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DBIX_CLASS_STORAGE_DBI_DEBUG"} or $ENV{"DBIC_TRACE"} 1 422 423
Condition66%2/3
$ENV{"DBIX_CLASS_STORAGE_DBI_DEBUG"} or $ENV{"DBIC_TRACE"}
l!l&&r!l&&!r
01422
MC/DC50%1/2
$ENV{"DBIX_CLASS_STORAGE_DBI_DEBUG"} or $ENV{"DBIC_TRACE"}
$ENV{"DBIX_CLASS_STORAGE_DBI_DEBUG"} $ENV{"DBIC_TRACE"}
Truth table66%2/3
A or B
A= $ENV{"DBIX_CLASS_STORAGE_DBI_DEBUG"}B= $ENV{"DBIC_TRACE"}
ABresult
1X1
011
000
61  
62 423 $new;
63 }
64  
65 =head2 set_schema
66  
67 Used to reset the schema class or object which owns this
68 storage object, such as during L<DBIx::Class::Schema/clone>.
69  
70 =cut
71  
72 sub set_schema {
73 429 ▶ my ($self, $schema) = @_;
Subroutine set_schema: called CC=2 SCAR=6.9
Pod documented
74 429 $self->schema($schema);
75 429 ▶ weaken $self->{schema} if ref $self->{schema};
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"schema"} 416 13 429
76 }
77  
78 =head2 connected
79  
80 Returns true if we have an open storage connection, false
81 if it is not (yet) open.
82  
83 =cut
84  
85 0 ▶sub connected { die "Virtual method!" }
Subroutine connected: not called CC=1 SCAR=6.9
Pod documented
86  
87 =head2 disconnect
88  
89 Closes any open storage connection unconditionally.
90  
91 =cut
92  
93 0 ▶sub disconnect { die "Virtual method!" }
Subroutine disconnect: not called CC=1 SCAR=6.9
Pod documented
94  
95 =head2 ensure_connected
96  
97 Initiate a connection to the storage if one isn't already open.
98  
99 =cut
100  
101 0 ▶sub ensure_connected { die "Virtual method!" }
Subroutine ensure_connected: not called CC=1 SCAR=6.9
Pod documented
102  
103 =head2 throw_exception
104  
105 Throws an exception - croaks.
106  
107 =cut
108  
109 sub throw_exception {
110 403 ▶ my $self = shift;
Subroutine throw_exception: called CC=3 SCAR=11.0
Pod documented
111  
112 403 ▶ if (ref $self and $self->schema) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self and $self->schema) { } 402 1 403
Condition66%2/3
ref $self and $self->schema
!ll&&!rl&&r
01402
MC/DC50%1/2
ref $self and $self->schema
ref $self $self->schema
Truth table66%2/3
A and B
A= ref $selfB= $self->schema
ABresult
0X0
100
111
113 402 $self->schema->throw_exception(@_);
114 }
115 else {
116 1 DBIx::Class::Exception->throw(@_);
117 }
118 }
119  
120 =head2 txn_do
121  
122 =over 4
123  
124 =item Arguments: C<$coderef>, @coderef_args?
125  
126 =item Return Value: The return value of $coderef
127  
128 =back
129  
130 Executes C<$coderef> with (optional) arguments C<@coderef_args> atomically,
131 returning its result (if any). If an exception is caught, a rollback is issued
132 and the exception is rethrown. If the rollback fails, (i.e. throws an
133 exception) an exception is thrown that includes a "Rollback failed" message.
134  
135 For example,
136  
137 my $author_rs = $schema->resultset('Author')->find(1);
138 my @titles = qw/Night Day It/;
139  
140 my $coderef = sub {
141 # If any one of these fails, the entire transaction fails
142 $author_rs->create_related('books', {
143 title => $_
144 }) foreach (@titles);
145  
146 return $author->books;
147 };
148  
149 my $rs;
150 try {
151 $rs = $schema->txn_do($coderef);
152 } catch {
153 my $error = shift;
154 # Transaction failed
155 die "something terrible has happened!"
156 if ($error =~ /Rollback failed/); # Rollback failed
157  
158 deal_with_failed_transaction();
159 };
160  
161 In a nested transaction (calling txn_do() from within a txn_do() coderef) only
162 the outermost transaction will issue a L</txn_commit>, and txn_do() can be
163 called in void, scalar and list context and it will behave as expected.
164  
165 Please note that all of the code in your coderef, including non-DBIx::Class
166 code, is part of a transaction. This transaction may fail out halfway, or
167 it may get partially double-executed (in the case that our DB connection
168 failed halfway through the transaction, in which case we reconnect and
169 restart the txn). Therefore it is best that any side-effects in your coderef
170 are idempotent (that is, can be re-executed multiple times and get the
171 same result), and that you check up on your side-effects in the case of
172 transaction failure.
173  
174 =cut
175  
176 sub txn_do {
177 462 ▶ my $self = shift;
Subroutine txn_do: called CC=1 SCAR=0.1
Pod documented
178  
179 DBIx::Class::Storage::BlockRunner->new(
180 storage => $self,
181 wrap_txn => 1,
182 retry_handler => sub {
183 15 ▶ $_[0]->failed_attempt_count == 1
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->failed_attempt_count == 1 and not $_[0]->storage->connected 15 0 15
184 and
185 ! $_[0]->storage->connected
186 },
187 462 )->run(@_);
188 }
189  
190 =head2 txn_begin
191  
192 Starts a transaction.
193  
194 See the preferred L</txn_do> method, which allows for
195 an entire code block to be executed transactionally.
196  
197 =cut
198  
199 sub txn_begin {
200 9047 ▶ my $self = shift;
Subroutine txn_begin: called CC=4 SCAR=13.9
Pod documented
201  
202 9047 ▶ if($self->transaction_depth == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->transaction_depth == 0) { } 8551 496 9047
elsif ($self->auto_savepoint) { } 2 494 496
203 8551 ▶ $self->debugobj->txn_begin()
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 8 8543 8551
204 if $self->debug;
205 8551 $self->_exec_txn_begin;
206 }
207 elsif ($self->auto_savepoint) {
208 2 $self->svp_begin;
209 }
210 9047 $self->{transaction_depth}++;
211  
212 }
213  
214 =head2 txn_commit
215  
216 Issues a commit of the current transaction.
217  
218 It does I<not> perform an actual storage commit unless there's a DBIx::Class
219 transaction currently in effect (i.e. you called L</txn_begin>).
220  
221 =cut
222  
223 sub txn_commit {
224 8774 ▶ my $self = shift;
Subroutine txn_commit: called CC=5 SCAR=16.2
Pod documented
225  
226 8774 ▶ if ($self->transaction_depth == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->transaction_depth == 1) { } 8391 383 8774
elsif ($self->transaction_depth > 1) { } 383 0 383
227 8391 ▶ $self->debugobj->txn_commit() if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 7 8384 8391
228 8391 $self->_exec_txn_commit;
229 8391 $self->{transaction_depth}--;
230 }
231 elsif($self->transaction_depth > 1) {
232 383 $self->{transaction_depth}--;
233 383 ▶ $self->svp_release if $self->auto_savepoint;
Branch: 1 branch
BranchTrueFalseTotal
if $self->auto_savepoint 1 382 383
234 }
235 else {
236 0 $self->throw_exception( 'Refusing to commit without a started transaction' );
237 }
238 }
239  
240 =head2 txn_rollback
241  
242 Issues a rollback of the current transaction. A nested rollback will
243 throw a L<DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION> exception,
244 which allows the rollback to propagate to the outermost transaction.
245  
246 =cut
247  
248 sub txn_rollback {
249 238 ▶ my $self = shift;
Subroutine txn_rollback: called CC=5 SCAR=16.2
Pod documented
250  
251 238 ▶ if ($self->transaction_depth == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->transaction_depth == 1) { } 125 113 238
elsif ($self->transaction_depth > 1) { } 113 0 113
252 125 ▶ $self->debugobj->txn_rollback() if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 1 124 125
253 125 $self->_exec_txn_rollback;
254 125 $self->{transaction_depth}--;
255 }
256 elsif ($self->transaction_depth > 1) {
257 113 $self->{transaction_depth}--;
258  
259 113 ▶ if ($self->auto_savepoint) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->auto_savepoint) { } 1 112 113
260 1 $self->svp_rollback;
261 1 $self->svp_release;
262 }
263 else {
264 112 DBIx::Class::Storage::NESTED_ROLLBACK_EXCEPTION->throw(
265 "A txn_rollback in nested transaction is ineffective! (depth $self->{transaction_depth})"
266 );
267 }
268 }
269 else {
270 0 $self->throw_exception( 'Refusing to roll back without a started transaction' );
271 }
272 }
273  
274 =head2 svp_begin
275  
276 Arguments: $savepoint_name?
277  
278 Created a new savepoint using the name provided as argument. If no name
279 is provided, a random name will be used.
280  
281 =cut
282  
283 sub svp_begin {
284 2 ▶ my ($self, $name) = @_;
Subroutine svp_begin: called CC=5 SCAR=16.8
Pod documented
285  
286 2 ▶ $self->throw_exception ("You can't use savepoints outside a transaction")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->transaction_depth 0 2 2
287 unless $self->transaction_depth;
288  
289 2 ▶ my $exec = $self->can('_exec_svp_begin')
Branch: 1 branch
BranchTrueFalseTotal
my $exec = $self->can("_exec_svp_begin") or $self->throw_exception("Your Storage implementation doesn't support savepoints") 0 2 2
290 or $self->throw_exception ("Your Storage implementation doesn't support savepoints");
291  
292 2 ▶ $name = $self->_svp_generate_name
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 2 0 2
293 unless defined $name;
294  
295 2 push @{ $self->{savepoints} }, $name;
296  
297 2 ▶ $self->debugobj->svp_begin($name) if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 2 2
298  
299 2 $exec->($self, $name);
300 }
301  
302 sub _svp_generate_name {
303 2 ▶ my ($self) = @_;
Subroutine _svp_generate_name: called CC=1 SCAR=0.0
304 2 return 'savepoint_'.scalar(@{ $self->{'savepoints'} });
305 }
306  
307  
308 =head2 svp_release
309  
310 Arguments: $savepoint_name?
311  
312 Release the savepoint provided as argument. If none is provided,
313 release the savepoint created most recently. This will implicitly
314 release all savepoints created after the one explicitly released as well.
315  
316 =cut
317  
318 sub svp_release {
319 2 ▶ my ($self, $name) = @_;
Subroutine svp_release: called CC=8 SCAR=29.3
Pod documented
320  
321 2 ▶ $self->throw_exception ("You can't use savepoints outside a transaction")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->transaction_depth 0 2 2
322 unless $self->transaction_depth;
323  
324 2 ▶ my $exec = $self->can('_exec_svp_release')
Branch: 1 branch
BranchTrueFalseTotal
my $exec = $self->can("_exec_svp_release") or $self->throw_exception("Your Storage implementation doesn't support savepoints") 0 2 2
325 or $self->throw_exception ("Your Storage implementation doesn't support savepoints");
326  
327 2 ▶ if (defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) { } 0 2 2
328 0 my @stack = @{ $self->savepoints };
329 0 my $svp;
330  
331 0 ▶ do { $svp = pop @stack } until $svp eq $name;
Branch: 1 branch
BranchTrueFalseTotal
$svp eq $name or do { do { $svp = pop @stack } } 0 0 0
332  
333 0 ▶ $self->throw_exception ("Savepoint '$name' does not exist")
Branch: 1 branch
BranchTrueFalseTotal
unless $svp 0 0 0
334 unless $svp;
335  
336 0 $self->savepoints(\@stack); # put back what's left
337 }
338 else {
339 2 ▶ $name = pop @{ $self->savepoints }
Branch: 1 branch
BranchTrueFalseTotal
$name = pop @{$self->savepoints;} or $self->throw_exception("No savepoints to release") 0 2 2
340 or $self->throw_exception('No savepoints to release');;
341 }
342  
343 2 ▶ $self->debugobj->svp_release($name) if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 2 2
344  
345 2 $exec->($self, $name);
346 }
347  
348 =head2 svp_rollback
349  
350 Arguments: $savepoint_name?
351  
352 Rollback to the savepoint provided as argument. If none is provided,
353 rollback to the savepoint created most recently. This will implicitly
354 release all savepoints created after the savepoint we rollback to.
355  
356 =cut
357  
358 sub svp_rollback {
359 1 ▶ my ($self, $name) = @_;
Subroutine svp_rollback: called CC=9 SCAR=33.2
Pod documented
360  
361 1 ▶ $self->throw_exception ("You can't use savepoints outside a transaction")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->transaction_depth 0 1 1
362 unless $self->transaction_depth;
363  
364 1 ▶ my $exec = $self->can('_exec_svp_rollback')
Branch: 1 branch
BranchTrueFalseTotal
my $exec = $self->can("_exec_svp_rollback") or $self->throw_exception("Your Storage implementation doesn't support savepoints") 0 1 1
365 or $self->throw_exception ("Your Storage implementation doesn't support savepoints");
366  
367 1 ▶ if (defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) { } 0 1 1
368 0 my @stack = @{ $self->savepoints };
369 0 my $svp;
370  
371 # a rollback doesn't remove the named savepoint,
372 # only everything after it
373 0 ▶ while (@stack and $stack[-1] ne $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stack and $stack[-1] ne $name) 0 0 0
Condition0%0/3
@stack and $stack[-1] ne $name
!ll&&!rl&&r
000
MC/DC0%0/2
@stack and $stack[-1] ne $name
@stack $stack[-1] ne $name
Truth table0%0/3
A and B
A= @stackB= $stack[-1] ne $name
ABresult
0X0
100
111
374 pop @stack
375 0 };
376  
377 0 ▶ $self->throw_exception ("Savepoint '$name' does not exist")
Branch: 1 branch
BranchTrueFalseTotal
unless @stack 0 0 0
378 unless @stack;
379  
380 0 $self->savepoints(\@stack); # put back what's left
381 }
382 else {
383 1 ▶ $name = $self->savepoints->[-1]
Branch: 1 branch
BranchTrueFalseTotal
$name = $self->savepoints->[-1] or $self->throw_exception("No savepoints to rollback") 0 1 1
384 or $self->throw_exception('No savepoints to rollback');;
385 }
386  
387 1 ▶ $self->debugobj->svp_rollback($name) if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 1 1
388  
389 1 $exec->($self, $name);
390 }
391  
392 =head2 txn_scope_guard
393  
394 An alternative way of transaction handling based on
395 L<DBIx::Class::Storage::TxnScopeGuard>:
396  
397 my $txn_guard = $storage->txn_scope_guard;
398  
399 $result->col1("val1");
400 $result->update;
401  
402 $txn_guard->commit;
403  
404 If an exception occurs, or the guard object otherwise leaves the scope
405 before C<< $txn_guard->commit >> is called, the transaction will be rolled
406 back by an explicit L</txn_rollback> call. In essence this is akin to
407 using a L</txn_begin>/L</txn_commit> pair, without having to worry
408 about calling L</txn_rollback> at the right places. Note that since there
409 is no defined code closure, there will be no retries and other magic upon
410 database disconnection. If you need such functionality see L</txn_do>.
411  
412 =cut
413  
414 sub txn_scope_guard {
415 8593 ▶ return DBIx::Class::Storage::TxnScopeGuard->new($_[0]);
Subroutine txn_scope_guard: called CC=1 SCAR=0.0
Pod documented
416 }
417  
418 =head2 sql_maker
419  
420 Returns a C<sql_maker> object - normally an object of class
421 C<DBIx::Class::SQLMaker>.
422  
423 =cut
424  
425 0 ▶sub sql_maker { die "Virtual method!" }
Subroutine sql_maker: not called CC=1 SCAR=6.9
Pod documented
426  
427 =head2 debug
428  
429 Causes trace information to be emitted on the L</debugobj> object.
430 (or C<STDERR> if L</debugobj> has not specifically been set).
431  
432 This is the equivalent to setting L</DBIC_TRACE> in your
433 shell environment.
434  
435 =head2 debugfh
436  
437 Set or retrieve the filehandle used for trace/debug output. This should be
438 an IO::Handle compatible object (only the C<print> method is used. Initially
439 set to be STDERR - although see information on the
440 L<DBIC_TRACE> environment variable.
441  
442 =cut
443  
444 sub debugfh {
445 3 ▶ my $self = shift;
Subroutine debugfh: called CC=2 SCAR=7.1
Pod documented
446  
447 3 ▶ if ($self->debugobj->can('debugfh')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debugobj->can("debugfh")) 3 0 3
448 3 return $self->debugobj->debugfh(@_);
449 }
450 }
451  
452 =head2 debugobj
453  
454 Sets or retrieves the object used for metric collection. Defaults to an instance
455 of L<DBIx::Class::Storage::Statistics> that is compatible with the original
456 method of using a coderef as a callback. See the aforementioned Statistics
457 class for more information.
458  
459 =cut
460  
461 sub debugobj {
462 448 ▶ my $self = shift;
Subroutine debugobj: called CC=5 SCAR=23.4
Pod documented
463  
464 448 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 32 416 448
465 32 return $self->{debugobj} = $_[0];
466 }
467  
468 416 ▶ $self->{debugobj} ||= do {
Condition66%2/3
$self->{"debugobj"} ||= do { if (my $profile = $ENV{"DBIC_TRACE_PROFILE"}) { require DBIx::Class::Storage::Debug::PrettyPrint; my @pp_args; if ($profile =~ m[^\.?/]) { require Config::Any; my $cfg = &try(sub { "Config::Any"->load_files({"files", [$profile], "use_ext", 1}); } , &catch(sub { $_ =~ s/at \s+ .+ Storage\.pm \s line \s \d+ $//x; $self->throw_exception("Failure processing \$ENV{DBIC_TRACE_PROFILE}: $_"); } )); @pp_args = values %{$$cfg[0];}; } else { @pp_args = {"profile", $profile}; } ; &try(sub { "DBIx::Class::Storage::Debug::PrettyPrint"->new(@pp_args); } , &catch(sub { $self->throw_exception($_); } )); } else { require DBIx::Class::Storage::Statistics; "DBIx::Class::Storage::Statistics"->new; } }
l!l&&r!l&&!r
391250
MC/DC0%0/2
$self->{"debugobj"} ||= do { if (my $profile = $ENV{"DBIC_TRACE_PROFILE"}) { require DBIx::Class::Storage::Debug::PrettyPrint; my @pp_args; if ($profile =~ m[^\.?/]) { require Config::Any; my $cfg = &try(sub { "Config::Any"->load_files({"files", [$profile], "use_ext", 1}); } , &catch(sub { $_ =~ s/at \s+ .+ Storage\.pm \s line \s \d+ $//x; $self->throw_exception("Failure processing \$ENV{DBIC_TRACE_PROFILE}: $_"); } )); @pp_args = values %{$$cfg[0];}; } else { @pp_args = {"profile", $profile}; } ; &try(sub { "DBIx::Class::Storage::Debug::PrettyPrint"->new(@pp_args); } , &catch(sub { $self->throw_exception($_); } )); } else { require DBIx::Class::Storage::Statistics; "DBIx::Class::Storage::Statistics"->new; } }
$self->{"debugobj"} do { if (my $profile = $ENV{"DBIC_TRACE_PROFILE"}) { require DBIx::Class::Storage::Debug::PrettyPrint; my @pp_args; if ($profile =~ m[^\.?/]) { require Config::Any; my $cfg = &try(sub { "Config::Any"->load_files({"files", [$profile], "use_ext", 1}); } , &catch(sub { $_ =~ s/at \s+ .+ Storage\.pm \s line \s \d+ $//x; $self->throw_exception("Failure processing \$ENV{DBIC_TRACE_PROFILE}: $_"); } )); @pp_args = values %{$$cfg[0];}; } else { @pp_args = {"profile", $profile}; } ; &try(sub { "DBIx::Class::Storage::Debug::PrettyPrint"->new(@pp_args); } , &catch(sub { $self->throw_exception($_); } )); } else { require DBIx::Class::Storage::Statistics; "DBIx::Class::Storage::Statistics"->new; } }
Truth table66%2/3
A ||= B
A= $self->{"debugobj"}B= do { if (my $profile = $ENV{"DBIC_TRACE_PROFILE"}) { require DBIx::Class::Storage::Debug::PrettyPrint; my @pp_args; if ($profile =~ m[^\.?/]) { require Config::Any; my $cfg = &try(sub { "Config::Any"->load_files({"files", [$profile], "use_ext", 1}); } , &catch(sub { $_ =~ s/at \s+ .+ Storage\.pm \s line \s \d+ $//x; $self->throw_exception("Failure processing \$ENV{DBIC_TRACE_PROFILE}: $_"); } )); @pp_args = values %{$$cfg[0];}; } else { @pp_args = {"profile", $profile}; } ; &try(sub { "DBIx::Class::Storage::Debug::PrettyPrint"->new(@pp_args); } , &catch(sub { $self->throw_exception($_); } )); } else { require DBIx::Class::Storage::Statistics; "DBIx::Class::Storage::Statistics"->new; } }
ABresult
1X1
011
000
469 25 ▶ if (my $profile = $ENV{DBIC_TRACE_PROFILE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $profile = $ENV{'DBIC_TRACE_PROFILE'}) { } 0 25 25
470 0 require DBIx::Class::Storage::Debug::PrettyPrint;
471 0 my @pp_args;
472  
473 0 ▶ if ($profile =~ /^\.?\//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($profile =~ m[^\.?/]) { } 0 0 0
474 0 require Config::Any;
475  
476 my $cfg = try {
477 0 ▶ Config::Any->load_files({ files => [$profile], use_ext => 1 });
Subroutine __ANON__: not called CC=1 SCAR=6.9
478 } catch {
479 # sanitize the error message a bit
480 0 ▶ $_ =~ s/at \s+ .+ Storage\.pm \s line \s \d+ $//x;
Subroutine __ANON__: not called CC=1 SCAR=6.9
481 0 $self->throw_exception("Failure processing \$ENV{DBIC_TRACE_PROFILE}: $_");
482 0 };
483  
484 0 @pp_args = values %{$cfg->[0]};
485 }
486 else {
487 0 @pp_args = { profile => $profile };
488 }
489  
490 # FIXME - FRAGILE
491 # Hash::Merge is a sorry piece of shit and tramples all over $@
492 # *without* throwing an exception
493 # This is a rather serious problem in the debug codepath
494 # Insulate the condition here with a try{} until a review of
495 # DBIx::Class::Storage::Debug::PrettyPrint takes place
496 # we do rethrow the error unconditionally, the only reason
497 # to try{} is to preserve the precise state of $@ (down
498 # to the scalar (if there is one) address level)
499 #
500 # Yes I am aware this is fragile and TxnScopeGuard needs
501 # a better fix. This is another yak to shave... :(
502 try {
503 0 ▶ DBIx::Class::Storage::Debug::PrettyPrint->new(@pp_args);
Subroutine __ANON__: not called CC=1 SCAR=6.9
504 } catch {
505 0 ▶ $self->throw_exception($_);
Subroutine __ANON__: not called CC=1 SCAR=6.9
506 }
507 0 }
508 else {
509 25 require DBIx::Class::Storage::Statistics;
510 25 DBIx::Class::Storage::Statistics->new
511 }
512 };
513 }
514  
515 =head2 debugcb
516  
517 Sets a callback to be executed each time a statement is run; takes a sub
518 reference. Callback is executed as $sub->($op, $info) where $op is
519 SELECT/INSERT/UPDATE/DELETE and $info is what would normally be printed.
520  
521 See L</debugobj> for a better way.
522  
523 =cut
524  
525 sub debugcb {
526 51 ▶ my $self = shift;
Subroutine debugcb: called CC=2 SCAR=7.1
Pod documented
527  
528 51 ▶ if ($self->debugobj->can('callback')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debugobj->can("callback")) 51 0 51
529 51 return $self->debugobj->callback(@_);
530 }
531 }
532  
533 =head2 cursor_class
534  
535 The cursor class for this Storage object.
536  
537 =cut
538  
539 =head2 deploy
540  
541 Deploy the tables to storage (CREATE TABLE and friends in a SQL-based
542 Storage class). This would normally be called through
543 L<DBIx::Class::Schema/deploy>.
544  
545 =cut
546  
547 0 ▶sub deploy { die "Virtual method!" }
Subroutine deploy: not called CC=1 SCAR=6.9
Pod documented
548  
549 =head2 connect_info
550  
551 The arguments of C<connect_info> are always a single array reference,
552 and are Storage-handler specific.
553  
554 This is normally accessed via L<DBIx::Class::Schema/connection>, which
555 encapsulates its argument list in an arrayref before calling
556 C<connect_info> here.
557  
558 =cut
559  
560 0 ▶sub connect_info { die "Virtual method!" }
Subroutine connect_info: not called CC=1 SCAR=6.9
Pod documented
561  
562 =head2 select
563  
564 Handle a select statement.
565  
566 =cut
567  
568 0 ▶sub select { die "Virtual method!" }
Subroutine select: not called CC=1 SCAR=6.9
Pod documented
569  
570 =head2 insert
571  
572 Handle an insert statement.
573  
574 =cut
575  
576 0 ▶sub insert { die "Virtual method!" }
Subroutine insert: not called CC=1 SCAR=6.9
Pod documented
577  
578 =head2 update
579  
580 Handle an update statement.
581  
582 =cut
583  
584 0 ▶sub update { die "Virtual method!" }
Subroutine update: not called CC=1 SCAR=6.9
Pod documented
585  
586 =head2 delete
587  
588 Handle a delete statement.
589  
590 =cut
591  
592 0 ▶sub delete { die "Virtual method!" }
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
593  
594 =head2 select_single
595  
596 Performs a select, fetch and return of data - handles a single row
597 only.
598  
599 =cut
600  
601 0 ▶sub select_single { die "Virtual method!" }
Subroutine select_single: not called CC=1 SCAR=6.9
Pod documented
602  
603 =head2 columns_info_for
604  
605 Returns metadata for the given source's columns. This
606 is *deprecated*, and will be removed before 1.0. You should
607 be specifying the metadata yourself if you need it.
608  
609 =cut
610  
611 0 ▶sub columns_info_for { die "Virtual method!" }
Subroutine columns_info_for: not called CC=1 SCAR=6.9
Pod documented
612  
613 =head1 ENVIRONMENT VARIABLES
614  
615 =head2 DBIC_TRACE
616  
617 If C<DBIC_TRACE> is set then trace information
618 is produced (as when the L</debug> method is set).
619  
620 If the value is of the form C<1=/path/name> then the trace output is
621 written to the file C</path/name>.
622  
623 This environment variable is checked when the storage object is first
624 created (when you call connect on your schema). So, run-time changes
625 to this environment variable will not take effect unless you also
626 re-connect on your schema.
627  
628 =head2 DBIC_TRACE_PROFILE
629  
630 If C<DBIC_TRACE_PROFILE> is set, L<DBIx::Class::Storage::Debug::PrettyPrint>
631 will be used to format the output from C<DBIC_TRACE>. The value it
632 is set to is the C<profile> that it will be used. If the value is a
633 filename the file is read with L<Config::Any> and the results are
634 used as the configuration for tracing. See L<SQL::Abstract::Tree/new>
635 for what that structure should look like.
636  
637  
638 =head2 DBIX_CLASS_STORAGE_DBI_DEBUG
639  
640 Old name for DBIC_TRACE
641  
642 =head1 SEE ALSO
643  
644 L<DBIx::Class::Storage::DBI> - reference storage implementation using
645 SQL::Abstract and DBI.
646  
647 =head1 AUTHOR AND CONTRIBUTORS
648  
649 See L<AUTHOR|DBIx::Class/AUTHOR> and L<CONTRIBUTORS|DBIx::Class/CONTRIBUTORS> in DBIx::Class
650  
651 =head1 LICENSE
652  
653 You may distribute this code under the same terms as Perl itself.
654  
655 =cut
656  
657 251 1;
« DBIx/Class/CDBICompat/ColumnsAsHash.pm ↑ Summary DBIx/Class/Schema.pm »