| 1 | package Egg::Plugin::DBIC; | ||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Carp qw/ croak /; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||
| 8 | 0 | ▶ | sub _setup { | ||||||||||||||||||||||||||||
|
Subroutine
_setup: not called CC=6 SCAR=36.3
| |||||||||||||||||||||||||||||||
| 9 | 0 | my($e)= @_; | |||||||||||||||||||||||||||||
| 10 | 0 | ▶ | $e->is_model('dbic') || die q{ I want setup Egg::Model::DBIC. }; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 11 | 0 | my $project= $e->project_name; | |||||||||||||||||||||||||||||
| 12 | 0 | my $schemas= $e->global->{dbic_schemas}; | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | no strict 'refs'; ## no critic | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | *{"${project}::dbh"}= sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||
| 16 | 0 | my $self= shift; | |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | my $begins= $self->{dbic_begins} ||= $self->ixhash; | ||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"dbic_begins"} ||= $self->ixhash
MC/DC0%0/2
$self->{"dbic_begins"} ||= $self->ixhash
$self->{"dbic_begins"}
$self->ixhash
Truth table0%0/3
A ||= B
A= $self->{"dbic_begins"}B= $self->ixhash
| |||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | if (my $s_name= lc(shift)) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | $begins->{$s_name} || &{"${project}::begin_$s_name"}($self); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 20 | } else { | ||||||||||||||||||||||||||||||
| 21 | 0 | my @result; | |||||||||||||||||||||||||||||
| 22 | 0 | for my $label (keys %$schemas) { | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | my $s_name= $label=~m{^dbic\:+(.+)} ? $1: $label; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 24 | my $dbh= $begins->{$s_name} | ||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | || &{"${project}::begin_$s_name"}($self) || next; | ||||||||||||||||||||||||||||
|
Condition0%0/5
$begins->{$s_name} || &{"${project}::begin_$s_name";}($self) || (next)
$begins->{$s_name} or &{"${project}::begin_$s_name";}($self)
MC/DC0%0/2
$begins->{$s_name} || &{"${project}::begin_$s_name";}($self) || (next)
$begins->{$s_name}
&{"${project}::begin_$s_name";}($self)
Truth table0%0/3
A or B
A= $begins->{$s_name}B= &{"${project}::begin_$s_name";}($self)
| |||||||||||||||||||||||||||||||
| 26 | 0 | push @result, $dbh; | |||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | wantarray ? @result: \@result; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||
| 30 | 0 | }; | |||||||||||||||||||||||||||||
| 31 | 0 | for my $accessor (qw/ commit rollback /) { | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | *{"${project}::${accessor}_ok"}= sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||
| 33 | 0 | my $self= shift; | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my $label= lc(shift) || croak q{I want schema name.}; | ||||||||||||||||||||||||||||
|
Condition0%0/2
lc shift() || croak('I want schema name.')
MC/DC0%0/1
lc shift() || croak('I want schema name.')
lc shift()
Truth table0%0/2
A
A= lc shift()
| |||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | my $s_name= $label=~m{^dbic\:+(.+)} ? $1: $label; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | my $ok= $self->{"dbic_${accessor}_ok"} ||= {}; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$$self{"dbic_${accessor}_ok"} ||= {}
MC/DC0%0/1
$$self{"dbic_${accessor}_ok"} ||= {}
$$self{"dbic_${accessor}_ok"}
Truth table0%0/2
A
A= $$self{"dbic_${accessor}_ok"}
| |||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | @_ ? $ok->{$s_name}= ($_[0] || 0) : ($ok->{$s_name} || 0); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/4
$_[0] || 0
$ok->{$s_name} or 0
MC/DC0%0/1
$_[0] || 0
$_[0]
MC/DC0%0/1
$ok->{$s_name} or 0
$ok->{$s_name}
Truth table0%0/2
A
A= $_[0]
Truth table0%0/2
A
A= $ok->{$s_name}
| |||||||||||||||||||||||||||||||
| 38 | 0 | }; | |||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | *{"${project}::dbic_finalize_error"}= sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||
| 41 | 0 | my($self)= @_; | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | my $begins= $self->{dbic_begins} || return 0; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'dbic_begins'} || (return 0)
MC/DC0%0/1
$self->{'dbic_begins'} || (return 0)
$self->{'dbic_begins'}
Truth table0%0/2
A
A= $self->{'dbic_begins'}
| |||||||||||||||||||||||||||||||
| 43 | 0 | &{"${project}::rollback_$_"}($self) for keys %$begins; | |||||||||||||||||||||||||||||
| 44 | 0 | %$begins= (); | |||||||||||||||||||||||||||||
| 45 | 0 | }; | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | *{"${project}::dbic_finish"}= sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||
| 47 | 0 | my($self)= @_; | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my $begins= $self->{dbic_begins} || return 0; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'dbic_begins'} || (return 0)
MC/DC0%0/1
$self->{'dbic_begins'} || (return 0)
$self->{'dbic_begins'}
Truth table0%0/2
A
A= $self->{'dbic_begins'}
| |||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | my $commit= $self->{dbic_commit_ok} || {}; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'dbic_commit_ok'} || {}
MC/DC0%0/1
$self->{'dbic_commit_ok'} || {}
$self->{'dbic_commit_ok'}
Truth table0%0/2
A
A= $self->{'dbic_commit_ok'}
| |||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my $roback= $self->{dbic_rollback_ok} || {}; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'dbic_rollback_ok'} || {}
MC/DC0%0/1
$self->{'dbic_rollback_ok'} || {}
$self->{'dbic_rollback_ok'}
Truth table0%0/2
A
A= $self->{'dbic_rollback_ok'}
| |||||||||||||||||||||||||||||||
| 51 | 0 | for my $s_name (keys %$begins) { | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | my $method= ($commit->{$s_name} and ! $roback->{$s_name}) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$commit->{$s_name} and not $roback->{$s_name}
MC/DC0%0/2
$commit->{$s_name} and not $roback->{$s_name}
$commit->{$s_name}
not $roback->{$s_name}
Truth table0%0/3
A and not(B)
A= $commit->{$s_name}B= not $roback->{$s_name}
| |||||||||||||||||||||||||||||||
| 53 | ? "commit_$s_name": "rollback_$s_name"; | ||||||||||||||||||||||||||||||
| 54 | 0 | $self->$method; | |||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||
| 56 | 0 | %$begins= (); | |||||||||||||||||||||||||||||
| 57 | 0 | }; | |||||||||||||||||||||||||||||
| 58 | 0 | for my $label (keys %$schemas) { | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | my $s_name= $label=~m{^dbic\:+(.+)} ? $1: $label; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 60 | 0 | my $schema= $e->model($label); | |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | *{"${project}::schema_$s_name"}= sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | $_[0]->{"dbic_schema_$s_name"} ||= $_[0]->model($label); | ||||||||||||||||||||||||||||
|
Condition0%0/3
$_[0]{"dbic_schema_$s_name"} ||= $_[0]->model($label)
MC/DC0%0/2
$_[0]{"dbic_schema_$s_name"} ||= $_[0]->model($label)
$_[0]{"dbic_schema_$s_name"}
$_[0]->model($label)
Truth table0%0/3
A ||= B
A= $_[0]{"dbic_schema_$s_name"}B= $_[0]->model($label)
| |||||||||||||||||||||||||||||||
| 63 | 0 | }; | |||||||||||||||||||||||||||||
| 64 | my $begin_code= $schema->storage->dbh->{AutoCommit} ? do { | ||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | *{"${project}::commit_$s_name"} = sub { 1 }; | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | *{"${project}::rollback_$s_name"} = sub { 1 }; | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub { 1 }; | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | }: do { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | *{"${project}::commit_$s_name"}= sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 70 | 0 | my($self)= @_; | |||||||||||||||||||||||||||||
| 71 | 0 | $self->dbh($label)->txn_commit; | |||||||||||||||||||||||||||||
| 72 | 0 | $self->debug_out("# + DBIC '$label' Transaction commit."); | |||||||||||||||||||||||||||||
| 73 | 0 | $self; | |||||||||||||||||||||||||||||
| 74 | 0 | }; | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | *{"${project}::rollback_$s_name"}= sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 76 | 0 | my($self)= @_; | |||||||||||||||||||||||||||||
| 77 | 0 | $self->dbh($label)->txn_rollback; | |||||||||||||||||||||||||||||
| 78 | 0 | $self->debug_out("# + DBIC '$label' Transaction rollback."); | |||||||||||||||||||||||||||||
| 79 | 0 | $self; | |||||||||||||||||||||||||||||
| 80 | 0 | }; | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 82 | 0 | $_[1]->txn_begin; | |||||||||||||||||||||||||||||
| 83 | 0 | $_[0]->debug_out("# + DBIC '$label' Transaction Start."); | |||||||||||||||||||||||||||||
| 84 | 0 | }; | |||||||||||||||||||||||||||||
| 85 | }; | ||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | *{"${project}::begin_$s_name"}= sub { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||
| 87 | 0 | my($self)= @_; | |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | my $begins= $self->{dbic_begins} ||= $self->ixhash; | ||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"dbic_begins"} ||= $self->ixhash
MC/DC0%0/2
$self->{"dbic_begins"} ||= $self->ixhash
$self->{"dbic_begins"}
$self->ixhash
Truth table0%0/3
A ||= B
A= $self->{"dbic_begins"}B= $self->ixhash
| |||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | return $begins->{$s_name} if $begins->{$s_name}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | my $context= $self->model($label) || return 0; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$self->model($label) || (return 0)
MC/DC0%0/1
$self->model($label) || (return 0)
$self->model($label)
Truth table0%0/2
A
A= $self->model($label)
| |||||||||||||||||||||||||||||||
| 91 | 0 | $begin_code->($self, $context); | |||||||||||||||||||||||||||||
| 92 | 0 | $begins->{$s_name}= $context->storage->dbh; | |||||||||||||||||||||||||||||
| 93 | 0 | }; | |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||
| 95 | 0 | $e->next::method; | |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub _finish { | ||||||||||||||||||||||||||||
|
Subroutine
_finish: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 98 | 0 | my $e= shift->next::method; | |||||||||||||||||||||||||||||
| 99 | 0 | $e->dbic_finish; | |||||||||||||||||||||||||||||
| 100 | 0 | $e; | |||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub _finalize_error { | ||||||||||||||||||||||||||||
|
Subroutine
_finalize_error: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 103 | 0 | my($e)= @_; | |||||||||||||||||||||||||||||
| 104 | 0 | $e->dbic_finalize_error; | |||||||||||||||||||||||||||||
| 105 | 0 | $e->next::method; | |||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||
| 108 | 1 | 1; | |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||
| 110 | __END__ | ||||||||||||||||||||||||||||||