| 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'} || []
MC/DC0%0/1
delete $params{'pk'} || []
delete $params{'pk'}
Truth table50%1/2
A
A= delete $params{'pk'}
| |||||||||||||
| 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
| |||||||||||||
| 23 | } | ||||||||||||
| 24 | |||||||||||||
| 25 | 8 | ▶ | if ($self->{autopk} = delete $params{autopk}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 26 | 0 | ▶ | !ref $self->{autopk} or croak "autopk only accepts a single column"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 27 | 0 | $self->{pk} = [$self->{autopk}]; | |||||||||||
| 28 | } | ||||||||||||
| 29 | |||||||||||||
| 30 | 8 | ▶ | !%params | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 42 | $self->{pk} = [ | ||||||||||||
| 43 | grep defined $_, | ||||||||||||
| 44 | 3 | ▶ | map { (ref $_ eq 'ARRAY') ? @$_ : $_ } @cols | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 71 | |||||||||||||
| 72 | # make the custom class inherit from our base | ||||||||||||
| 73 | 1 | ▶ | if (!$class->isa('DBIx::Lite::Row')) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 106 | |||||||||||||
| 107 | # make the custom class inherit from our base | ||||||||||||
| 108 | 1 | ▶ | if (!$class->isa('DBIx::Lite::ResultSet')) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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__ | ||||||||||||