Lite/Schema/Table.pm

filter: Statementstmt 93.4% 71 / 76 Branchbran 57.1% 16 / 28 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 13 / 13 Podpod 100% 5 / 5 totaltotal 84.8% 106 / 125 CC 17 SCAR 14.6
CC
17
Cov
83%
new
9.7
class
4.0
resultset_class
4.0
CRAP 4.3
« Lite/Schema.pm ↑ Summary
1 package DBIx::Lite::Schema::Table;
2 7 $DBIx::Lite::Schema::Table::VERSION = '0.39';
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 $Carp::Internal{$_}++ for __PACKAGE__;
8  
9 sub new {
10 5 ▶ my $class = shift;
Subroutine new: called CC=7 SCAR=22.7
Pod documented
11 5 my (%params) = @_;
12
13 my $self = {
14 class => undef,
15 resultset_class => undef,
16 5 ▶ pk => delete $params{pk} || [],
Condition50%1/2
delete $params{'pk'} || []
l!l
05
MC/DC0%0/1
delete $params{'pk'} || []
delete $params{'pk'}
Truth table50%1/2
A
A= delete $params{'pk'}
Aresult
11
00
17 has_many => {},
18 has_one => {},
19 };
20
21 5 for (qw(name)) {
22 5 ▶ $self->{$_} = delete $params{$_} or croak "$_ argument needed";
Branch: 1 branch
BranchTrueFalseTotal
$self->{$_} = delete $params{$_} or croak("$_ argument needed") 0 5 5
23 }
24
25 5 ▶ if ($self->{autopk} = delete $params{autopk}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"autopk"} = delete $params{"autopk"}) 0 5 5
26 0 ▶ !ref $self->{autopk} or croak "autopk only accepts a single column";
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{"autopk"} and croak("autopk only accepts a single column") 0 0 0
27 0 $self->{pk} = [$self->{autopk}];
28 }
29
30 5 ▶ !%params
Branch: 1 branch
BranchTrueFalseTotal
%params and croak('Unknown options: ' . join(", ", keys %params)) 0 5 5
31 or croak "Unknown options: " . join(', ', keys %params);
32
33 5 bless $self, $class;
34 5 $self;
35 }
36  
37 sub pk {
38 4 ▶ my $self = shift;
Subroutine pk: called CC=3 SCAR=11.0
Pod documented
39 4 my @cols = @_;
40
41 4 ▶ if (@cols) {
Branch: 1 branch
BranchTrueFalseTotal
if (@cols) 3 1 4
42 $self->{pk} = [
43 grep defined $_,
44 3 ▶ map { (ref $_ eq 'ARRAY') ? @$_ : $_ } @cols
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 0 3 3
45 ];
46 3 return $self;
47 }
48 1 return @{$self->{pk}};
49 }
50  
51 sub autopk {
52 5 ▶ my $self = shift;
Subroutine autopk: called CC=2 SCAR=8.5
Pod documented
53 5 my $val = shift;
54
55 5 ▶ if ($val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val) 0 5 5
56 0 $self->{autopk} = $val;
57 0 $self->{pk} = [$val];
58 0 return $self;
59 }
60 5 return $self->{autopk};
61 }
62  
63 sub class {
64 1 ▶ my ($self, $class, $constructor, $storage) = @_;
Subroutine class: called CC=4 SCAR=13.9
Pod documented
65
66 1 $self->{class} = $class;
67 1 $self->{class_constructor} = $constructor;
68 1 $self->{class_storage} = $storage;
69
70 1 ▶ return undef if !$class;
Branch: 1 branch
BranchTrueFalseTotal
unless $class 0 1 1
71
72 # make the custom class inherit from our base
73 1 ▶ if (!$class->isa('DBIx::Lite::Row')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->isa("DBIx::Lite::Row")) 1 0 1
74 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
75 1 push @{"${class}::ISA"}, 'DBIx::Lite::Row';
76 }
77
78 # install the storage provider
79 1 ▶ if ($storage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($storage) 1 0 1
80 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
81 7 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
82 1 *{ "${class}::__dbix_lite_row_storage" } = sub {
83 1 ▶ my ($row) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.1
84
85 1 ▶ croak "$class does not provide a $storage method"
Branch: 1 branch
BranchTrueFalseTotal
unless $row->can($storage) 0 1 1
86 if !$row->can($storage);
87
88 1 return $row->$storage;
89 1 };
90 }
91
92 1 return $class;
93 }
94  
95 sub resultset_class {
96 35 ▶ my $self = shift;
Subroutine resultset_class: called CC=4 SCAR=13.9
Pod documented
97 35 my $class = shift;
98
99 35 ▶ if ($class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class) 1 34 35
100 1 $self->{resultset_class} = $class;
101 1 return $self;
102 }
103  
104 34 $class = $self->{resultset_class};
105 34 ▶ return undef if !$class;
Branch: 1 branch
BranchTrueFalseTotal
unless $class 33 1 34
106
107 # make the custom class inherit from our base
108 1 ▶ if (!$class->isa('DBIx::Lite::ResultSet')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->isa("DBIx::Lite::ResultSet")) 1 0 1
109 7 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
110 1 push @{"${class}::ISA"}, 'DBIx::Lite::ResultSet';
111 }
112
113 1 return $class;
114 }
115  
116 7 1;
117  
118 __END__
« Lite/Schema.pm ↑ Summary