ODS/Table/Row.pm

filter: Statementstmt 100% 47 / 47 Branchbran 90.0% 9 / 10 Conditioncond 40.0% 4 / 10 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 7 totaltotal 80.9% 72 / 89 CC 13 SCAR 10.5
CC
13
Cov
90%
store_row
5.2
validate
4.1
build
3.0
CRAP 2.9
« ODS/Iterator.pm ↑ Summary ODS/Utils.pm »
1 package ODS::Table::Row;
2  
3 72 ▶use YAOO;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 use overload
6 157435 ▶ '%{}' => sub { caller() =~ m/YAOO$/ ? $_[0] : $_[0]->as_hash; },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
(caller()) =~ /YAOO$/ ? : 157306 129 157435
7 72 ▶ fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 72 has table => isa(object);
10  
11 72 has columns => isa(ordered_hash), default(1);
12  
13 72 has __file => isa(string);
14  
15 72 has __custom_file_name => isa(string);
16  
17 sub build {
18 2648 ▶ my ($self, %args) = @_;
Subroutine build: called CC=3 SCAR=11.0
Pod undocumented
19  
20 2648 $self->table($args{table});
21 2648 $self->__custom_file_name(delete $args{data}{__custom_file_name});
22 2648 $self->__file(delete $args{data}{__file});
23  
24 2648 for my $column ( keys %{ $self->table->columns } ) {
25 my $col = $self->table->columns->{$column}->build_column(
26 $args{data}{$column}, $args{inflated}, $args{serialize_class}
27 39374 );
28 39374 $self->columns->{$column} = $col;
29 YAOO::make_keyword($self->table->row_class, $column, sub {
30 161 ▶ my $self = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
31 161 $self->columns->{$column}->value(@_);
32 39374 ▶ }) unless $self->can($column);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($column) 1517 37857 39374
33 }
34 2648 return $self;
35 }
36  
37 sub as_hash {
38 132 ▶ my %hash;
Subroutine as_hash: called CC=2 SCAR=6.9
Pod undocumented
39 $hash{$_} = $_[0]->columns->{$_}->value
40 132 for keys %{$_[0]->columns};
41 132 return \%hash;
42 }
43  
44 sub set_row {
45 6 ▶ my ($self, $data) = @_;
Subroutine set_row: called CC=2 SCAR=6.9
Pod undocumented
46 6 for my $key ( keys %{ $data } ) {
47 4 $self->$key($data->{$key});
48 }
49 }
50  
51 sub store_row {
52 1760 ▶ my ($self, $data) = @_;
Subroutine store_row: called CC=4 SCAR=16.4
Pod undocumented
53 1760 ▶ $self->set_row($data) if defined $data && ref($data || "") eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if defined $data and ref($data || "") eq "HASH" 0 1760 1760
Condition20%1/5
defined $data and ref($data || "") eq "HASH"
!ll&&!rl&&r
176000
$data || ''
l!l
00
MC/DC0%0/2
defined $data and ref($data || "") eq "HASH"
defined $data $data
Truth table33%1/3
A and B
A= defined $dataB= $data
ABresult
0X0
100
111
54 my %hash = map +(
55 $_ => $self->columns->{$_}->store_column()->value
56 1760 ), keys %{ $self->columns };
57 1760 return \%hash;
58 }
59  
60 sub validate {
61 1720 ▶ my ($self, $data) = @_;
Subroutine validate: called CC=4 SCAR=14.0
Pod undocumented
62 1720 ▶ $self->set_row($data) if defined $data && ref($data || "") eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if defined $data and ref($data || "") eq "HASH" 2 1718 1720
Condition60%3/5
defined $data and ref($data || "") eq "HASH"
!ll&&!rl&&r
171802
$data || ''
l!l
20
MC/DC50%1/2
defined $data and ref($data || "") eq "HASH"
defined $data $data
Truth table66%2/3
A and B
A= defined $dataB= $data
ABresult
0X0
100
111
63 my %hash = map +(
64 $_ => $self->columns->{$_}->validate()->value
65 1720 ), keys %{ $self->columns };
66 1720 return \%hash;
67 }
68  
69 sub update {
70 4 ▶ my ($self, $update) = (shift, @_ > 1 ? { @_ } : $_[0]);
Subroutine update: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 2 2 4
71 4 $self->set_row($update);
72 4 $self->table->storage->update_row($self);
73 }
74  
75 sub delete {
76 2 ▶ my ($self) = @_;
Subroutine delete: called CC=1 SCAR=0.0
Pod undocumented
77 2 $self->table->storage->delete_row($self);
78 }
79  
80 72 1;
« ODS/Iterator.pm ↑ Summary ODS/Utils.pm »