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 8 $DBIx::Lite::Schema::Table::VERSION = '0.41';
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 $Carp::Internal{$_}++ for __PACKAGE__;
8  
9 8 ▶sub new {
Subroutine new: called CC=7 SCAR=22.7
Pod documented
10 8 my $class = shift;
11 8 my (%params) = @_;
12
13 my $self = {
14 class => undef,
15 resultset_class => undef,
16 8 ▶ pk => delete $params{pk} || [],
Condition50%1/2
delete $params{'pk'} || []
l!l
08
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 8 for (qw(name)) {
22 8 ▶ $self->{$_} = delete $params{$_} or croak "$_ argument needed";
Branch: 1 branch
BranchTrueFalseTotal
$self->{$_} = delete $params{$_} or croak("$_ argument needed") 8 0 8
23 }
24
25 8 ▶ if ($self->{autopk} = delete $params{autopk}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"autopk"} = delete $params{"autopk"}) 0 8 8
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 8 ▶ !%params
Branch: 1 branch
BranchTrueFalseTotal
%params and croak('Unknown options: ' . join(", ", keys %params)) 0 8 8
31 or croak "Unknown options: " . join(', ', keys %params);
32
33 8 bless $self, $class;
34 8 $self;
35 }
36  
37 4 ▶sub pk {
Subroutine pk: called CC=3 SCAR=11.0
Pod documented
38 4 my $self = shift;
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 8 ▶sub autopk {
Subroutine autopk: called CC=2 SCAR=8.5
Pod documented
52 8 my $self = shift;
53 8 my $val = shift;
54
55 8 ▶ if ($val) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val) 0 8 8
56 0 $self->{autopk} = $val;
57 0 $self->{pk} = [$val];
58 0 return $self;
59 }
60 8 return $self->{autopk};
61 }
62  
63 1 ▶sub class {
Subroutine class: called CC=4 SCAR=13.9
Pod documented
64 1 my ($self, $class, $constructor, $storage) = @_;
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 8 ▶ 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 8 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
81 8 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
82 1 ▶ *{ "${class}::__dbix_lite_row_storage" } = sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
83 1 my ($row) = @_;
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 43 ▶sub resultset_class {
Subroutine resultset_class: called CC=4 SCAR=13.9
Pod documented
96 43 my $self = shift;
97 43 my $class = shift;
98
99 43 ▶ if ($class) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class) 1 42 43
100 1 $self->{resultset_class} = $class;
101 1 return $self;
102 }
103  
104 42 $class = $self->{resultset_class};
105 42 ▶ return undef if !$class;
Branch: 1 branch
BranchTrueFalseTotal
unless $class 41 1 42
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 8 ▶ 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 8 1;
117  
118 __END__
« Lite/Schema.pm ↑ Summary