Lite/Row.pm

filter: Statementstmt 52.9% 36 / 68 Branchbran 33.3% 8 / 24 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 50.0% 8 / 16 Podpod 100% 6 / 6 totaltotal 49.5% 58 / 117 CC 15 SCAR 19.5
CC
15
Cov
47%
insert_related
20.0
_pk
12.0
update
12.0
CRAP 7.1
« Lite/ResultSet.pm ↑ Summary Lite.pm »
1 package DBIx::Lite::Row;
2 7 $DBIx::Lite::Row::VERSION = '0.41';
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use Clone qw(clone);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use vars qw($AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 $Carp::Internal{$_}++ for __PACKAGE__;
10  
11 0 ▶sub _pk {
Subroutine _pk: not called CC=3 SCAR=24.8
12 0 my $self = shift;
13 0 my $selfs = $self->__dbix_lite_row_storage;
14
15 my @keys = $selfs->{table}->pk
16 0 ▶ or croak "No primary key defined for table " . $selfs->{table}{name};
Branch: 1 branch
BranchTrueFalseTotal
my(@keys) = $selfs->{"table"}->pk or croak('No primary key defined for table ' . $selfs->{"table"}{"name"}) 0 0 0
17
18 grep(!exists $selfs->{data}{$_}, @keys)
19 0 ▶ and croak "No primary key data retrieved for table " . $selfs->{table}{name};
Branch: 1 branch
BranchTrueFalseTotal
grep((!exists $selfs->{"data"}{$_}), @keys) and croak('No primary key data retrieved for table ' . $selfs->{"table"}{"name"}) 0 0 0
20
21 0 return { map +($_ => $selfs->{data}{$_}), @keys };
22 }
23  
24 12 ▶sub __dbix_lite_row_storage { $_[0] }
Subroutine __dbix_lite_row_storage: called CC=1 SCAR=0.0
25  
26 0 ▶sub hashref {
Subroutine hashref: not called CC=1 SCAR=6.9
Pod documented
27 0 my $self = shift;
28 0 my $selfs = $self->__dbix_lite_row_storage;
29
30 0 return clone $selfs->{data};
31 }
32  
33 0 ▶sub update {
Subroutine update: not called CC=3 SCAR=24.8
Pod documented
34 0 my $self = shift;
35 0 ▶ my $update_cols = shift or croak "update() requires a hashref";
Branch: 1 branch
BranchTrueFalseTotal
my $update_cols = shift() or croak("update() requires a hashref") 0 0 0
36 0 my $selfs = $self->__dbix_lite_row_storage;
37
38 0 $selfs->{dbix_lite}->table($selfs->{table}{name})->search($self->_pk)->update($update_cols);
39 0 $selfs->{data}{$_} = $update_cols->{$_} for keys %$update_cols;
40 0 $self;
41 }
42  
43 0 ▶sub delete {
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
44 0 my $self = shift;
45 0 my $selfs = $self->__dbix_lite_row_storage;
46
47 0 $selfs->{dbix_lite}->table($selfs->{table}{name})->search($self->_pk)->delete;
48 0 undef $self;
49 }
50  
51 0 ▶sub insert_related {
Subroutine insert_related: not called CC=4 SCAR=30.0
Pod documented
52 0 my $self = shift;
53 0 my ($rel_name, $insert_cols) = @_;
54 0 ▶ $rel_name or croak "insert_related() requires a table name";
Branch: 1 branch
BranchTrueFalseTotal
$rel_name or croak("insert_related() requires a table name") 0 0 0
55 0 ▶ $insert_cols //= {};
Condition0%0/2
$insert_cols //= {}
l!l
00
MC/DC0%0/1
$insert_cols //= {}
$insert_cols
Truth table0%0/2
A
A= $insert_cols
Aresult
11
00
56 0 my $selfs = $self->__dbix_lite_row_storage;
57
58 my ($table_name, $my_key, $their_key) = $self->_relationship($rel_name)
59 0 ▶ or croak "No $rel_name relationship defined for " . $selfs->{table}{name};
Branch: 1 branch
BranchTrueFalseTotal
() = $self->_relationship($rel_name) or croak("No $rel_name relationship defined for " . $selfs->{"table"}{"name"}) 0 0 0
60
61 return $selfs->{dbix_lite}
62 ->table($table_name)
63 0 ->insert({ $their_key => $selfs->{data}{$my_key}, %$insert_cols });
64 }
65  
66 4 ▶sub _relationship {
Subroutine _relationship: called CC=3 SCAR=11.1
67 4 my $self = shift;
68 4 my ($rel_name) = @_;
69 4 my $selfs = $self->__dbix_lite_row_storage;
70
71 4 ▶ my ($rel_type) = grep $selfs->{table}{$_}{$rel_name}, qw(has_one has_many)
Branch: 1 branch
BranchTrueFalseTotal
my($rel_type) = grep($selfs->{"table"}{$_}{$rel_name}, ("has_one", "has_many")) or return () 4 0 4
72 or return ();
73
74 4 my $rel = $selfs->{table}{$rel_type}{$rel_name};
75 4 my ($table_name, $my_key, $their_key) = ($rel->[0], %{ $rel->[1] });
76
77 exists $selfs->{data}{$my_key}
78 4 ▶ or croak "No $my_key key retrieved from " . $selfs->{table}{name};
Branch: 1 branch
BranchTrueFalseTotal
exists $selfs->{"data"}{$my_key} or croak("No $my_key key retrieved from " . $selfs->{"table"}{"name"}) 4 0 4
79
80 4 return ($table_name, $my_key, $their_key, $rel_type);
81 }
82  
83 0 ▶sub get {
Subroutine get: not called CC=2 SCAR=17.9
Pod documented
84 0 my $self = shift;
85 0 ▶ my $key = shift or croak "get() requires a column name";
Branch: 1 branch
BranchTrueFalseTotal
my $key = shift() or croak("get() requires a column name") 0 0 0
86 0 my $selfs = $self->__dbix_lite_row_storage;
87
88 0 return $selfs->{data}{$key};
89 }
90  
91 9 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=5 SCAR=16.4
92 9 ▶ my $self = shift or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or return undef 9 0 9
93 9 my $selfs = $self->__dbix_lite_row_storage;
94
95 # Get the called method name and trim off the namespace
96 9 (my $method = $AUTOLOAD) =~ s/.*:://;
97
98 9 ▶ if (exists $selfs->{data}{$method}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $selfs->{"data"}{$method}) 5 4 9
99 5 return $selfs->{data}{$method};
100 }
101
102 4 ▶ if (my ($table_name, $my_key, $their_key, $rel_type) = $self->_relationship($method)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $self->_relationship($method)) 4 0 4
103 my $rs = $selfs->{dbix_lite}
104 ->table($table_name)
105 4 ->search({ "me.$their_key" => $selfs->{data}{$my_key} });
106 4 ▶ return $rel_type eq 'has_many' ? $rs : $rs->single;
Branch: 1 branch
BranchTrueFalseTotal
$rel_type eq 'has_many' ? : 2 2 4
107 }
108
109 croak sprintf "No %s method is provided by this %s (%s) object",
110 0 $method, ref($self), $selfs->{table}{name};
111 }
112  
113 0 ▶sub db {
Subroutine db: not called CC=1 SCAR=6.9
Pod documented
114 0 my ($self) = @_;
115  
116 0 return $self->__dbix_lite_row_storage->{dbix_lite};
117 }
118  
119 0 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
120  
121 7 1;
122  
123 __END__
« Lite/ResultSet.pm ↑ Summary Lite.pm »