Schema/Journal.pm

filter: Statementstmt 26.2% 26 / 99 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 33.3% 5 / 15 Podpod 0.0% 0 / 7 totaltotal 18.3% 31 / 169 CC 22 SCAR 35.0
CC
22
Cov
19%
connection
72.0
_journal_schema_prototype
56.0
txn_do
30.0
CRAP 33.1
↑ Summary Schema/Journal/DB.pm »
1 package DBIx::Class::Schema::Journal;
2  
3 2 ▶use base qw/DBIx::Class/;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use DBIx::Class::Schema::Journal::DB;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 __PACKAGE__->mk_classdata('journal_storage_type');
9 2 __PACKAGE__->mk_classdata('journal_connection');
10 2 __PACKAGE__->mk_classdata('journal_deploy_on_connect');
11 2 __PACKAGE__->mk_classdata('journal_sources'); ## [ source names ]
12 2 __PACKAGE__->mk_classdata('journal_user'); ## [ class, field for user id ]
13 2 __PACKAGE__->mk_classdata('journal_copy_sources');
14 2 __PACKAGE__->mk_classdata('__journal_schema_prototype');
15 2 __PACKAGE__->mk_classdata('_journal_schema'); ## schema object for journal
16 2 __PACKAGE__->mk_classdata('journal_component');
17 2 __PACKAGE__->mk_classdata('journal_nested_changesets');
18  
19 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 # sub throw_exception
23 # {
24 # }
25  
26 # sub exception_action
27 # {
28 # my $self = shift;
29 # # print STDERR Carp::longmess;
30
31 # $self->next::method(@_);
32 # }
33  
34 # sub load_classes
35 # {
36 # my $class = shift;
37  
38  
39 # $class->next::method(@_);
40
41 # }
42  
43 sub _journal_schema_prototype
44 {
45 0 ▶ my $self = shift;
Subroutine _journal_schema_prototype: not called CC=7 SCAR=40.3
46 0 ▶ if (my $proto = $self->__journal_schema_prototype)
Branch: 1 branch
BranchTrueFalseTotal
if (my $proto = $self->__journal_schema_prototype) 0 0 0
47 {
48 0 return $proto;
49 }
50 0 ▶ my $proto = $self->__journal_schema_prototype
Condition0%0/3
builtin::blessed($self) || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
builtin::blessed($self) || $self
builtin::blessed($self) $self
Truth table0%0/3
A || B
A= builtin::blessed($self)B= $self
ABresult
1X1
011
000
51 (
52 DBIx::Class::Schema::Journal::DB->compose_namespace
53 (
54 (blessed($self)||$self) . '::Journal'
55 )
56 );
57 0 ▶ my $comp = $self->journal_component || "Journal";
Condition0%0/2
$self->journal_component || 'Journal'
l!l
00
MC/DC0%0/1
$self->journal_component || 'Journal'
$self->journal_component
Truth table0%0/2
A
A= $self->journal_component
Aresult
11
00
58  
59 ## Create auditlog+history per table
60 0 ▶ my %j_sources = map { $_ => 1 } $self->journal_sources
Branch: 1 branch
BranchTrueFalseTotal
$self->journal_sources ? : 0 0 0
61 0 ? @{$self->journal_sources}
62 : $self->sources;
63  
64 0 foreach my $s_name ($self->sources)
65 {
66 0 ▶ next unless($j_sources{$s_name});
Branch: 1 branch
BranchTrueFalseTotal
unless $j_sources{$s_name} 0 0 0
67 0 $self->create_journal_for($s_name => $proto);
68 0 $self->class($s_name)->load_components($comp);
69 # print STDERR "$s_name :", $self->class($s_name), "\n";
70 }
71 0 return $proto;
72 }
73  
74 sub connection
75 {
76 0 ▶ my $self = shift;
Subroutine connection: not called CC=8 SCAR=42.8
Pod undocumented
77 0 my $schema = $self->next::method(@_);
78  
79 # print STDERR join(":", $self->sources), "\n";
80  
81 0 ▶ my $journal_schema = (ref $self||$self)->_journal_schema_prototype->clone;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
82  
83 0 ▶ if($self->journal_connection)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->journal_connection) { } 0 0 0
84 {
85 0 ▶ if($self->journal_storage_type)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->journal_storage_type) 0 0 0
86 {
87 0 $journal_schema->storage_type($self->journal_storage_type);
88 }
89 0 $journal_schema->connection(@{ $self->journal_connection });
90 } else {
91 0 $journal_schema->storage( $schema->storage );
92 }
93  
94 0 $self->_journal_schema($journal_schema);
95  
96  
97 0 ▶ if ( $self->journal_nested_changesets ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->journal_nested_changesets) 0 0 0
98 0 $self->_journal_schema->nested_changesets(1);
99 0 die "FIXME nested changeset schema not yet supported... add parent_id to ChangeSet here";
100 }
101  
102 $self->journal_schema_deploy()
103 0 ▶ if $self->journal_deploy_on_connect;
Branch: 1 branch
BranchTrueFalseTotal
if $self->journal_deploy_on_connect 0 0 0
104  
105 ## Set up relationship between changeset->user_id and this schema's user
106 0 ▶ if(!@{$self->journal_user || []})
Branch: 2 branches
BranchTrueFalseTotal
unless (@{$self->journal_user or [];}) 0 0 0
$self->journal_user or [] 0 0 0
107 {
108 #warn "No Journal User set!"; # no need to warn, user_id is useful even without a rel
109 0 return $schema;
110 }
111  
112 0 $self->_journal_schema->class('ChangeSet')->belongs_to('user', @{$self->journal_user});
113 0 $self->_journal_schema->storage->disconnect();
114  
115 0 return $schema;
116 }
117  
118 sub deploy
119 {
120 0 ▶ my ( $self, $sqlt_args, @args ) = @_;
Subroutine deploy: not called CC=1 SCAR=6.9
Pod undocumented
121  
122 0 $self->next::method($sqlt_args, @args);
123  
124 0 $self->journal_schema_deploy($sqlt_args, @args);
125 }
126  
127 sub journal_schema_deploy
128 {
129 0 ▶ my ( $self, $sqlt_args, @args ) = @_;
Subroutine journal_schema_deploy: not called CC=1 SCAR=6.9
Pod undocumented
130  
131 0 $self->_journal_schema->deploy( $sqlt_args, @args );
132 }
133  
134 sub create_journal_for
135 {
136 0 ▶ my ($self, $s_name, $journal_schema) = @_;
Subroutine create_journal_for: not called CC=3 SCAR=24.8
Pod undocumented
137  
138 0 my $source = $self->source($s_name);
139  
140 0 foreach my $audit (qw(AuditLog AuditHistory)) {
141 0 my $audit_source = join("", $s_name, $audit);
142 0 my $class = blessed($journal_schema) . "::$audit_source";
143  
144 0 DBIx::Class::Componentised->inject_base($class, "DBIx::Class::Schema::Journal::DB::$audit");
145  
146 0 $class->journal_define_table($source);
147  
148 0 $journal_schema->register_class($audit_source, $class);
149  
150 0 ▶ if ($self->journal_copy_sources)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->journal_copy_sources) 0 0 0
151 {
152 0 $self->register_class($audit_source, $class);
153 }
154 }
155 }
156  
157 sub txn_do
158 {
159 0 ▶ my ($self, $user_code, @args) = @_;
Subroutine txn_do: not called CC=5 SCAR=34.0
Pod undocumented
160  
161 0 my $jschema = $self->_journal_schema;
162  
163 0 my $code = $user_code;
164  
165 0 my $current_changeset = $jschema->_current_changeset;
166 0 ▶ if ( !$current_changeset || $self->journal_nested_changesets )
Branch: 1 branch
BranchTrueFalseTotal
if (not $current_changeset or $self->journal_nested_changesets) 0 0 0
Condition0%0/3
not $current_changeset or $self->journal_nested_changesets
l!l&&r!l&&!r
000
MC/DC0%0/2
not $current_changeset or $self->journal_nested_changesets
not $current_changeset $self->journal_nested_changesets
Truth table0%0/3
not(A) or B
A= not $current_changesetB= $self->journal_nested_changesets
ABresult
1X1
011
000
167 {
168 0 my $current_changeset_ref = $jschema->_current_changeset_container;
169  
170 0 ▶ unless ( $current_changeset_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($current_changeset_ref) 0 0 0
171 # this is a hash because scalar refs can't be localized
172 0 $current_changeset_ref = { };
173 0 $jschema->_current_changeset_container($current_changeset_ref);
174 }
175  
176 # wrap the thunk with a new changeset creation
177 $code = sub {
178 0 ▶ my $changeset = $jschema->journal_create_changeset( parent_id => $current_changeset );
Subroutine __ANON__: not called CC=1 SCAR=6.9
179 0 local $current_changeset_ref->{changeset} = $changeset->id;
180 0 $user_code->(@_);
181 0 };
182  
183 }
184  
185 0 ▶ if ( $jschema->storage != $self->storage ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($jschema->storage != $self->storage) 0 0 0
186 0 my $inner_code = $code;
187 0 ▶ $code = sub { $jschema->txn_do($inner_code, @_) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
188 }
189  
190 0 return $self->next::method($code, @args);
191 }
192  
193 sub changeset_user
194 {
195 0 ▶ my ($self, $userid) = @_;
Subroutine changeset_user: not called CC=2 SCAR=17.9
Pod undocumented
196  
197 0 ▶ return $self->_journal_schema->current_user() if(@_ == 1);
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
198  
199 0 $self->_journal_schema->current_user($userid);
200 }
201  
202 sub changeset_session
203 {
204 0 ▶ my ($self, $sessionid) = @_;
Subroutine changeset_session: not called CC=2 SCAR=17.9
Pod undocumented
205  
206 0 ▶ return $self->_journal_schema->current_session() if(@_ == 1);
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
207  
208 0 $self->_journal_schema->current_session($sessionid);
209 }
210  
211  
212 2 1;
↑ Summary Schema/Journal/DB.pm »