Karas/Row.pm

filter: Statementstmt 82.1% 46 / 56 Branchbran 46.4% 13 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.5% 12 / 17 Podpod 50.0% 5 / 10 totaltotal 68.4% 76 / 111 CC 17 SCAR 14.6
CC
17
Cov
70%
set_column
12.0
get_column
5.6
__ANON__
5.5
CRAP 4.3
« Karas.pm ↑ Summary Karas/Dumper.pm »
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
BranchTrueFalseTotal
if ref $class 0 9 9
29  
30 9 for my $col (@cols) {
31 21 ▶ Carp::croak("Column is undefined") unless defined $col;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $col 0 21 21
32 21 ▶ Carp::croak("Invalid column name: $col") if $col =~ /^__private/;
Branch: 1 branch
BranchTrueFalseTotal
if $col =~ /^__private/ 0 21 21
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
BranchTrueFalseTotal
if (@_ == 1) { } 11 1 12
elsif (@_ == 2) { } 1 0 1
36 # my ($self) = @_;
37 11 ▶ Carp::croak("You don't selected $col in SQL.") unless exists $_[0]->{$col};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $_[0]{$col} 0 11 11
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
BranchTrueFalseTotal
if ref $_[1] 0 1 1
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
BranchTrueFalseTotal
unless ($self->primary_key) 0 2 2
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
BranchTrueFalseTotal
unless @_ == 2 0 2 2
65 2 ▶ Carp::croak("Column is undefined") unless defined $col;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $col 0 2 2
66 2 ▶ Carp::croak("You don't selected $col") unless exists $self->{$col};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{$col} 0 2 2
67 2 ▶ Carp::croak("Invalid column name: $col") if $col =~ /^__private/;
Branch: 1 branch
BranchTrueFalseTotal
if $col =~ /^__private/ 0 2 2
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
BranchTrueFalseTotal
unless @_ == 3 0 0 0
74 0 ▶ Carp::croak("You can't set non scalar value as column data: $col") if ref $val;
Branch: 1 branch
BranchTrueFalseTotal
if ref $val 0 0 0
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__
« Karas.pm ↑ Summary Karas/Dumper.pm »