DBIx/Class/KiokuDB.pm

filter: Statementstmt 95.9% 95 / 99 Branchbran 62.5% 20 / 32 Conditioncond 77.7% 7 / 9 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 18 / 18 Podpod 100% 8 / 8 totaltotal 88.3% 152 / 172 CC 21 SCAR 11.2
CC
21
Cov
87%
get_kiokudb_column
5.4
kiokudb_column
4.1
_kiokudb_id_to_object
4.1
CRAP 3.1
« DBIx/Class/Schema/KiokuDB.pm ↑ Summary DBIx/Class/KiokuDB/EntryProxy.pm »
1 package DBIx::Class::KiokuDB;
2 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 $DBIx::Class::KiokuDB::AUTHORITY = 'cpan:NUFFIN';
4 }
5 # ABSTRACT: Refer to KiokuDB objects from DBIx::Class tables.
6 3 $DBIx::Class::KiokuDB::VERSION = '1.23';
7 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 3 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶use base qw(DBIx::Class::Core);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 4 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
18 4 my $self = shift->next::method(@_);
19  
20 4 foreach my $key ( $self->result_source->columns ) {
21 12 my $col_info = $self->column_info($key);
22  
23 12 ▶ if ( $col_info->{_kiokudb_info} and ref( my $obj = $self->get_column($key) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col_info->{"_kiokudb_info"} and ref(my $obj = $self->get_column($key))) 3 9 12
Condition100%3/3
$col_info->{"_kiokudb_info"} and ref(my $obj = $self->get_column($key))
!ll&&!rl&&r
813
MC/DC100%2/2
$col_info->{"_kiokudb_info"} and ref(my $obj = $self->get_column($key))
$col_info->{"_kiokudb_info"} ref(my $obj = $self->get_column($key))
Truth table100%3/3
A and B
A= $col_info->{"_kiokudb_info"}B= ref(my $obj = $self->get_column($key))
ABresult
0X0
100
111
24 3 $self->store_kiokudb_column( $key => $obj );
25 }
26 }
27  
28 4 return $self;
29 }
30  
31 4 ▶sub insert {
Subroutine insert: called CC=3 SCAR=11.0
Pod documented
32 4 my ( $self, @args ) = @_;
33  
34 4 my $schema = $self->result_source->schema;
35  
36 4 my $g = $schema->txn_scope_guard;
37  
38 4 my $dir = $schema->kiokudb_handle;
39 4 my $lo = $dir->live_objects;
40  
41 4 ▶ if ( my @insert = grep { ref and not $lo->object_to_entry($_) } values %{ $self->{_kiokudb_column} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@insert) = grep({ref $_ and not $lo->object_to_entry($_);} values %{$$self{"_kiokudb_column"};})) 2 2 4
Condition66%2/3
ref $_ && !$lo->object_to_entry($_)
!ll&&!rl&&r
012
MC/DC50%1/2
ref $_ && !$lo->object_to_entry($_)
ref $_ !$lo->object_to_entry($_)
Truth table66%2/3
A && not(B)
A= ref $_B= !$lo->object_to_entry($_)
ABresult
0X0
100
111
42 2 $dir->insert(@insert);
43 }
44  
45 4 my $ret = $self->next::method(@args);
46  
47 4 $g->commit;
48  
49 4 return $ret;
50 }
51  
52 4 ▶sub update {
Subroutine update: called CC=3 SCAR=11.0
Pod documented
53 4 my ( $self, @args ) = @_;
54  
55 4 my $dir = $self->result_source->schema->kiokudb_handle;
56 4 my $lo = $dir->live_objects;
57  
58 4 ▶ if ( my @insert = grep { ref and not $lo->object_to_entry($_) } values %{ $self->{_kiokudb_column} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@insert) = grep({ref $_ and not $lo->object_to_entry($_);} values %{$$self{"_kiokudb_column"};})) 1 3 4
Condition66%2/3
ref $_ && !$lo->object_to_entry($_)
!ll&&!rl&&r
011
MC/DC50%1/2
ref $_ && !$lo->object_to_entry($_)
ref $_ !$lo->object_to_entry($_)
Truth table66%2/3
A && not(B)
A= ref $_B= !$lo->object_to_entry($_)
ABresult
0X0
100
111
59 1 croak("Can't update object, related KiokuDB objects are not in storage");
60 }
61  
62 3 $self->next::method(@args);
63 }
64  
65 1 ▶sub store {
Subroutine store: called CC=2 SCAR=6.9
Pod documented
66 1 my ( $self, @args ) = @_;
67  
68 1 my $schema = $self->result_source->schema;
69  
70 1 my $g = $schema->txn_scope_guard;
71  
72 1 ▶ if ( my @objects = grep { ref } values %{ $self->{_kiokudb_column} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@objects) = grep({ref $_;} values %{$$self{"_kiokudb_column"};})) 1 0 1
73 1 $schema->kiokudb_handle->store(@objects);
74 }
75  
76 1 my $ret = $self->insert_or_update;
77  
78 1 $g->commit;
79  
80 1 return $ret;
81 }
82  
83 2 ▶sub kiokudb_column {
Subroutine kiokudb_column: called CC=4 SCAR=14.2
Pod documented
84 2 my ($self, $rel, $cond, $attrs) = @_;
85  
86 # assume a foreign key contraint unless defined otherwise
87 $attrs->{is_foreign_key_constraint} = 1
88 2 ▶ if not exists $attrs->{is_foreign_key_constraint};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $attrs->{"is_foreign_key_constraint"} 2 0 2
89  
90 2 ▶ my $fk = defined $cond ? $cond : $rel;
Branch: 1 branch
BranchTrueFalseTotal
defined $cond ? : 0 2 2
91  
92 2 $self->add_relationship( $rel, 'entries', { 'foreign.id' => "self.$fk" }, $attrs ); # FIXME hardcoded 'entries'
93  
94 2 my $col_info = $self->column_info($fk);
95  
96 2 $col_info->{_kiokudb_info} = {};
97  
98 2 my $accessor = $col_info->{accessor};
99 2 ▶ $accessor = $rel unless defined $accessor;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $accessor 2 0 2
100  
101 2 $self->mk_group_accessors('kiokudb_column' => [ $accessor, $fk]);
102 }
103  
104 5 ▶sub _kiokudb_id_to_object {
Subroutine _kiokudb_id_to_object: called CC=3 SCAR=14.2
105 5 my ( $self, $id ) = @_;
106  
107 5 ▶ if ( ref( my $obj = $self->result_source->schema->kiokudb_handle->lookup($id) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref(my $obj = $self->result_source->schema->kiokudb_handle->lookup($id))) { } 5 0 5
108 5 return $obj;
109 } else {
110 0 ▶ croak("No object with ID '$id' found") unless ref $obj;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $obj 0 0 0
111 }
112 }
113  
114 4 ▶sub _kiokudb_object_to_id {
Subroutine _kiokudb_object_to_id: called CC=3 SCAR=11.0
115 4 my ( $self, $object ) = @_;
116  
117 4 ▶ confess unless ref $object;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $object 0 4 4
118  
119 4 my $dir = $self->result_source->schema->kiokudb_handle;
120  
121 4 ▶ if ( my $id = $dir->object_to_id($object) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $id = $dir->object_to_id($object)) { } 1 3 4
122 1 return $id;
123 } else {
124 # generate an ID
125 3 my $collapser = $dir->collapser;
126 3 my $id_method = $collapser->id_method(ref $object);
127 3 my $id = $id = $collapser->$id_method($object);
128  
129 # register the ID
130 3 $dir->live_objects->insert( $id => $object );
131  
132 3 return $id;
133 }
134 }
135  
136 9 ▶sub get_kiokudb_column {
Subroutine get_kiokudb_column: called CC=5 SCAR=16.8
Pod documented
137 9 my ( $self, $col ) = @_;
138  
139 $self->throw_exception("$col is not a KiokuDB column")
140 9 ▶ unless exists $self->column_info($col)->{_kiokudb_info};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->column_info($col)->{"_kiokudb_info"} 0 9 9
141  
142 return $self->{_kiokudb_column}{$col}
143 9 ▶ if defined $self->{_kiokudb_column}{$col};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_kiokudb_column"}{$col} 4 5 9
144  
145 5 ▶ if ( defined( my $val = $self->get_column($col) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $val = $self->get_column($col))) { } 5 0 5
146 5 ▶ my $obj = ref $val ? $val : $self->_kiokudb_id_to_object($val);
Branch: 1 branch
BranchTrueFalseTotal
ref $val ? : 0 5 5
147  
148 # weaken by default, in case there are cycles, the live object scope will
149 # take care of this
150 5 weaken( $self->{_kiokudb_column}{$col} = $obj );
151  
152 5 return $obj;
153 } else {
154 0 return;
155 }
156 }
157  
158 4 ▶sub _set_kiokudb_column {
Subroutine _set_kiokudb_column: called CC=2 SCAR=7.6
159 4 my ( $self, $method, $col, $obj ) = @_;
160  
161 4 ▶ if ( ref $obj ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $obj) { } 4 0 4
162 4 $self->$method( $col, $self->_kiokudb_object_to_id($obj) );
163 4 $self->{_kiokudb_column}{$col} = $obj;
164 } else {
165 0 $self->$method( $col, undef );
166 0 delete $self->{_kiokudb_column}{$col};
167 }
168  
169 4 return $obj;
170 }
171  
172 1 ▶sub set_kiokudb_column {
Subroutine set_kiokudb_column: called CC=1 SCAR=0.0
Pod documented
173 1 my ( $self, @args ) = @_;
174 1 $self->_set_kiokudb_column( set_column => @args );
175 }
176  
177 3 ▶sub store_kiokudb_column {
Subroutine store_kiokudb_column: called CC=1 SCAR=0.0
Pod documented
178 3 my ( $self, @args ) = @_;
179 3 $self->_set_kiokudb_column( store_column => @args );
180 }
181  
182 # ex: set sw=4 et:
183  
184 3 __PACKAGE__
185  
186 __END__
« DBIx/Class/Schema/KiokuDB.pm ↑ Summary DBIx/Class/KiokuDB/EntryProxy.pm »