| 1 | package Karas::Row; | ||||||||||||||
| 2 | 9 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 9 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 9 | ▶ | use utf8; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 9 | ▶ | use Carp (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 18 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 8 | 18 | my ($class, $values) = @_; | |||||||||||||
| 9 | 18 | bless { | |||||||||||||
| 10 | __private_dirty_column => +{}, | ||||||||||||||
| 11 | %$values, | ||||||||||||||
| 12 | }, $class; | ||||||||||||||
| 13 | } | ||||||||||||||
| 14 | |||||||||||||||
| 15 | # Abstract methods. | ||||||||||||||
| 16 | 0 | ▶ | sub table_name { Carp::croak("Abstract method"); } | ||||||||||||
|
Subroutine
table_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 17 | 0 | ▶ | sub primary_key { Carp::croak("Abstract method"); } | ||||||||||||
|
Subroutine
primary_key: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 18 | 0 | ▶ | sub column_names { Carp::croak("Abstract method"); } | ||||||||||||
|
Subroutine
column_names: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 19 | 2 | ▶ | sub has_column { | ||||||||||||
|
Subroutine
has_column: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 20 | 2 | my ($self, $column) = @_; | |||||||||||||
| 21 | 2 | return (grep { $_ eq $column } $self->column_names) > 0; | |||||||||||||
| 22 | } | ||||||||||||||
| 23 | |||||||||||||||
| 24 | 1 | ▶ | sub get_dirty_columns { $_[0]->{__private_dirty_column} } | ||||||||||||
|
Subroutine
get_dirty_columns: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 25 | |||||||||||||||
| 26 | 9 | ▶ | sub mk_column_accessors { | ||||||||||||
|
Subroutine
mk_column_accessors: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||||
| 27 | 9 | my ($class, @cols) = @_; | |||||||||||||
| 28 | 9 | ▶ | Carp::croak("mk_column_accessors is class method.") if ref $class; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 29 | |||||||||||||||
| 30 | 9 | for my $col (@cols) { | |||||||||||||
| 31 | 21 | ▶ | Carp::croak("Column is undefined") unless defined $col; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 32 | 21 | ▶ | Carp::croak("Invalid column name: $col") if $col =~ /^__private/; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 33 | 9 | ▶ | no strict 'refs'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 34 | 21 | ▶ | *{"${class}::${col}"} = sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=17.0
| |||||||||||||||
| 35 | 12 | ▶ | if (@_==1) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 36 | # my ($self) = @_; | ||||||||||||||
| 37 | 11 | ▶ | Carp::croak("You don't selected $col in SQL.") unless exists $_[0]->{$col}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 38 | 11 | return $_[0]->{$col}; | |||||||||||||
| 39 | } elsif (@_==2) { | ||||||||||||||
| 40 | # my ($self, $val) = @_; | ||||||||||||||
| 41 | 1 | ▶ | Carp::croak("You can't set non scalar value as column data: $col") if ref $_[1]; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 42 | 1 | $_[0]->{$col} = ($_[0]->{__private_dirty_column}->{$col} = $_[1]); | |||||||||||||
| 43 | } else { | ||||||||||||||
| 44 | 0 | Carp::croak("Too many arguments for ${class}::${col}"); | |||||||||||||
| 45 | } | ||||||||||||||
| 46 | 21 | }; | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | } | ||||||||||||||
| 49 | |||||||||||||||
| 50 | 2 | ▶ | sub make_where_condition { | ||||||||||||
|
Subroutine
make_where_condition: called CC=3 SCAR=11.8
Pod
undocumented
| |||||||||||||||
| 51 | 2 | my $self = shift; | |||||||||||||
| 52 | 2 | ▶ | unless ($self->primary_key()) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | 0 | Carp::croak("You can't get WHERE clause for @{[ $self->table_name ]}. There is no primary key settings."); | |||||||||||||
| 54 | } | ||||||||||||||
| 55 | 2 | my %cond; | |||||||||||||
| 56 | 2 | for my $key ($self->primary_key) { | |||||||||||||
| 57 | 2 | $cond{$key} = $self->get_column($key); | |||||||||||||
| 58 | } | ||||||||||||||
| 59 | 2 | return \%cond; | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 2 | ▶ | sub get_column { | ||||||||||||
|
Subroutine
get_column: called CC=5 SCAR=17.2
Pod
documented
| |||||||||||||||
| 63 | 2 | my ($self, $col) = @_; | |||||||||||||
| 64 | 2 | ▶ | Carp::croak("Usage: Karas::Row#get_column(\$col)") unless @_==2; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 65 | 2 | ▶ | Carp::croak("Column is undefined") unless defined $col; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 66 | 2 | ▶ | Carp::croak("You don't selected $col") unless exists $self->{$col}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 67 | 2 | ▶ | Carp::croak("Invalid column name: $col") if $col =~ /^__private/; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 68 | 2 | return $self->{$col}; | |||||||||||||
| 69 | } | ||||||||||||||
| 70 | |||||||||||||||
| 71 | 0 | ▶ | sub set_column { | ||||||||||||
|
Subroutine
set_column: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||
| 72 | 0 | my ($self, $col, $val) = @_; | |||||||||||||
| 73 | 0 | ▶ | Carp::croak("Usage: Karas::Row#set_column(\$col, \$val)") unless @_==3; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 74 | 0 | ▶ | Carp::croak("You can't set non scalar value as column data: $col") if ref $val; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 75 | 0 | $self->{__private_dirty_column}->{$col} = $val; | |||||||||||||
| 76 | } | ||||||||||||||
| 77 | |||||||||||||||
| 78 | 0 | ▶ | sub DESTROY { } | ||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||
| 79 | |||||||||||||||
| 80 | 9 | 1; | |||||||||||||
| 81 | __END__ | ||||||||||||||