blib/lib/DBIx/Class/HTMLWidget.pm

filter: Statementstmt 22.0% 11 / 50 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 66 MC/DCmcdc 0.0% 0 / 32 Subroutinesub 50.0% 3 / 6 Podpod 66.6% 2 / 3 totaltotal 8.6% 16 / 185 CC 40 SCAR 55.8
CC
40
Cov
8%
populate_from_widget
420.0
fill_widget
210.0
experimental_populate_from_widget
72.0
CRAP 264.9
↑ Summary
1 package DBIx::Class::HTMLWidget;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 #use Data::Dump qw(dump);
6  
7 1 our $VERSION = '0.16';
8 # pod after __END__
9  
10 0 ▶sub fill_widget {
Subroutine fill_widget: not called CC=14 SCAR=53.5
Pod documented
11 0 my ($dbic,$widget)=@_;
12  
13 0 ▶ croak('fill_widget needs a HTML::Widget object as argument')
Branch: 1 branch
BranchTrueFalseTotal
unless ref $widget and $widget->isa("HTML::Widget") 0 0 0
Condition0%0/3
ref $widget and $widget->isa("HTML::Widget")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $widget and $widget->isa("HTML::Widget")
ref $widget $widget->isa("HTML::Widget")
Truth table0%0/3
A and B
A= ref $widgetB= $widget->isa("HTML::Widget")
ABresult
0X0
100
111
14 unless ref $widget && $widget->isa('HTML::Widget');
15 0 my @real_elements = $widget->find_elements;
16
17 0 foreach my $element ( @real_elements ) {
18 0 my $name=$element->name;
19 0 ▶ next unless $name && $dbic->can($name) && $element->can('value');
Branch: 1 branch
BranchTrueFalseTotal
unless $name and $dbic->can($name) and $element->can("value") 0 0 0
Condition0%0/6
$name and $dbic->can($name) and $element->can("value")
!ll&&!rl&&r
000
$name and $dbic->can($name)
!ll&&!rl&&r
000
MC/DC0%0/3
$name and $dbic->can($name) and $element->can("value")
$name $dbic->can($name) $element->can("value")
Truth table0%0/4
A and B and C
A= $nameB= $dbic->can($name)C= $element->can("value")
ABCresult
0XX0
10X0
1100
1111
20 0 ▶ next if ($element->value());
Branch: 1 branch
BranchTrueFalseTotal
if $element->value 0 0 0
21 0 ▶ if($element->isa('HTML::Widget::Element::Checkbox')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($element->isa('HTML::Widget::Element::Checkbox')) { } 0 0 0
22 0 ▶ $element->checked($dbic->$name?1:0);
Branch: 1 branch
BranchTrueFalseTotal
$dbic->$name ? : 0 0 0
23 } else {
24 0 ▶ if (ref $dbic->$name and $dbic->$name->can('id') and $dbic->$name->id) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dbic->$name and $dbic->$name->can('id') and $dbic->$name->id) { } 0 0 0
Condition0%0/6
ref $dbic->$name and $dbic->$name->can("id") and $dbic->$name->id
!ll&&!rl&&r
000
ref $dbic->$name and $dbic->$name->can("id")
!ll&&!rl&&r
000
MC/DC0%0/3
ref $dbic->$name and $dbic->$name->can("id") and $dbic->$name->id
ref $dbic->$name $dbic->$name->can("id") $dbic->$name->id
Truth table0%0/4
A and B and C
A= ref $dbic->$nameB= $dbic->$name->can("id")C= $dbic->$name->id
ABCresult
0XX0
10X0
1100
1111
25 0 $element->value($dbic->$name->id);
26 } else {
27 0 ▶ $element->value($dbic->$name)
Branch: 1 branch
BranchTrueFalseTotal
unless $element->isa("HTML::Widget::Element::Password") 0 0 0
28 unless $element->isa('HTML::Widget::Element::Password');
29 }
30 }
31 }
32 }
33  
34  
35 0 ▶sub populate_from_widget {
Subroutine populate_from_widget: not called CC=20 SCAR=60.4
Pod documented
36 0 my ($dbic,$result)=@_;
37 0 ▶ croak('populate_from_widget needs a HTML::Widget::Result object as argument')
Branch: 1 branch
BranchTrueFalseTotal
unless ref $result and $result->isa("HTML::Widget::Result") 0 0 0
Condition0%0/3
ref $result and $result->isa("HTML::Widget::Result")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $result and $result->isa("HTML::Widget::Result")
ref $result $result->isa("HTML::Widget::Result")
Truth table0%0/3
A and B
A= ref $resultB= $result->isa("HTML::Widget::Result")
ABresult
0X0
100
111
38 unless ref $result && $result->isa('HTML::Widget::Result');
39  
40 # find all checkboxes
41 0 my %cb = map {$_->name => undef } grep { $_->isa('HTML::Widget::Element::Checkbox') }
42 $result->find_elements;
43  
44 0 foreach my $col ( $dbic->result_source->columns ) {
45 0 my $col_info = $dbic->column_info($col);
46 0 my $value = scalar($result->param($col));
47 0 ▶ if ($col_info->{data_type} and $col_info->{data_type} =~ m/^timestamp|date|integer|numeric/i
Branch: 1 branch
BranchTrueFalseTotal
if ($col_info->{"data_type"} and $col_info->{"data_type"} =~ /^timestamp|date|integer|numeric/i and defined $value and $value eq "") 0 0 0
Condition0%0/9
$col_info->{"data_type"} and $col_info->{"data_type"} =~ /^timestamp|date|integer|numeric/i and defined $value and $value eq ""
!ll&&!rl&&r
000
$col_info->{"data_type"} and $col_info->{"data_type"} =~ /^timestamp|date|integer|numeric/i and defined $value
!ll&&!rl&&r
000
$col_info->{"data_type"} and $col_info->{"data_type"} =~ /^timestamp|date|integer|numeric/i
!ll&&!rl&&r
000
MC/DC0%0/4
$col_info->{"data_type"} and $col_info->{"data_type"} =~ /^timestamp|date|integer|numeric/i and defined $value and $value eq ""
$col_info->{"data_type"} $col_info->{"data_type"} =~ /^timestamp|date|integer|numeric/i defined $value $value eq ""
Truth table0%0/5
A and B and C and D
A= $col_info->{"data_type"}B= $col_info->{"data_type"} =~ /^timestamp|date|integer|numeric/iC= defined $valueD= $value eq ""
ABCDresult
0XXX0
10XX0
110X0
11100
11111
48 and defined $value and $value eq '') {
49 0 $value = undef;
50 0 $dbic->$col(undef);
51 }
52  
53 0 ▶ if (defined($value) and !ref($value) and $value eq 'undef') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and not ref $value and $value eq "undef") 0 0 0
Condition0%0/6
defined $value and not ref $value and $value eq "undef"
!ll&&!rl&&r
000
defined $value and not ref $value
!ll&&!rl&&r
000
MC/DC0%0/3
defined $value and not ref $value and $value eq "undef"
defined $value not ref $value $value eq "undef"
Truth table0%0/4
A and not(B) and C
A= defined $valueB= not ref $valueC= $value eq "undef"
ABCresult
0XX0
10X0
1100
1111
54 0 $dbic->$col(undef);
55 0 $value = undef;
56 }
57 0 ▶ if ($col_info->{data_type} and $col_info->{data_type} =~ m/boolean/i
Branch: 1 branch
BranchTrueFalseTotal
if ($col_info->{"data_type"} and ($col_info->{"data_type"} =~ /boolean/i and exists $col_info->{"is_nullable"} and not $col_info->{"is_nullable"} and exists $cb{$col} and not defined $value and $dbic->result_source->schema->storage->sqlt_type eq "PostgreSQL")) 0 0 0
Condition0%0/18
$col_info->{"data_type"} and ($col_info->{"data_type"} =~ /boolean/i and exists $col_info->{"is_nullable"} and not $col_info->{"is_nullable"} and exists $cb{$col} and not defined $value and $dbic->result_source->schema->storage->sqlt_type eq "PostgreSQL")
!ll&&!rl&&r
000
$col_info->{"data_type"} =~ /boolean/i and exists $col_info->{"is_nullable"} and not $col_info->{"is_nullable"} and exists $cb{$col} and not defined $value and $dbic->result_source->schema->storage->sqlt_type eq "PostgreSQL"
!ll&&!rl&&r
000
$col_info->{"data_type"} =~ /boolean/i and exists $col_info->{"is_nullable"} and not $col_info->{"is_nullable"} and exists $cb{$col} and not defined $value
!ll&&!rl&&r
000
$col_info->{"data_type"} =~ /boolean/i and exists $col_info->{"is_nullable"} and not $col_info->{"is_nullable"} and exists $cb{$col}
!ll&&!rl&&r
000
$col_info->{"data_type"} =~ /boolean/i and exists $col_info->{"is_nullable"} and not $col_info->{"is_nullable"}
!ll&&!rl&&r
000
$col_info->{"data_type"} =~ /boolean/i and exists $col_info->{"is_nullable"}
!ll&&!rl&&r
000
MC/DC0%0/7
$col_info->{"data_type"} and ($col_info->{"data_type"} =~ /boolean/i and exists $col_info->{"is_nullable"} and not $col_info->{"is_nullable"} and exists $cb{$col} and not defined $value and $dbic->result_source->schema->storage->sqlt_type eq "PostgreSQL")
$col_info->{"data_type"} $col_info->{"data_type"} =~ /boolean/i exists $col_info->{"is_nullable"} not $col_info->{"is_nullable"} exists $cb{$col} not defined $value $dbic->result_source->schema->storage->sqlt_type eq "PostgreSQL"
Truth table0%0/8
A and B and C and not(D) and E and not(F) and G
A= $col_info->{"data_type"}B= $col_info->{"data_type"} =~ /boolean/iC= exists $col_info->{"is_nullable"}D= not $col_info->{"is_nullable"}E= exists $cb{$col}F= not defined $valueG= $dbic->result_source->schema->storage->sqlt_type eq "PostgreSQL"
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110XX0
111110X0
11111100
11111111
58 && exists $col_info->{is_nullable} && !$col_info->{is_nullable}
59 && exists $cb{$col} && !defined($value)
60 && $dbic->result_source->schema->storage->sqlt_type eq 'PostgreSQL') {
61 # We need to set the value to 0 if it is postgres
62 0 $value = 0;
63 }
64 $dbic->$col($value)
65 0 ▶ if defined $value || exists $cb{$col};
Branch: 1 branch
BranchTrueFalseTotal
if defined $value or exists $cb{$col} 0 0 0
Condition0%0/3
defined $value or exists $cb{$col}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $value or exists $cb{$col}
defined $value exists $cb{$col}
Truth table0%0/3
A or B
A= defined $valueB= exists $cb{$col}
ABresult
1X1
011
000
66 }
67 0 $dbic->insert_or_update;
68 0 return $dbic;
69 }
70  
71  
72 0 ▶sub experimental_populate_from_widget {
Subroutine experimental_populate_from_widget: not called CC=8 SCAR=42.8
Pod undocumented
73 0 my ($dbic,$result)=@_;
74 0 foreach (@{$result->{_elements}} ) {
75 # Its called a fair few times so save name
76 0 my $name = $_->name;
77 #prevent passwords being overwritten.
78 0 ▶ next if $_->isa('HTML::Widget::Element::Password') && $result->param($name) eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $_->isa("HTML::Widget::Element::Password") and $result->param($name) eq "" 0 0 0
Condition0%0/3
$_->isa("HTML::Widget::Element::Password") and $result->param($name) eq ""
!ll&&!rl&&r
000
MC/DC0%0/2
$_->isa("HTML::Widget::Element::Password") and $result->param($name) eq ""
$_->isa("HTML::Widget::Element::Password") $result->param($name) eq ""
Truth table0%0/3
A and B
A= $_->isa("HTML::Widget::Element::Password")B= $result->param($name) eq ""
ABresult
0X0
100
111
79 $dbic->set_column($name, scalar $result->param($name))
80 if (defined $result->param($name) || $_->isa('HTML::Widget::Element::Checkbox')) &&
81 # Ignore this element if its readonly or not in the DBIC
82 0 ▶ !$_->{attributes}{readonly} && $dbic->has_column($name);
Branch: 1 branch
BranchTrueFalseTotal
if defined $result->param($name) || $_->isa("HTML::Widget::Element::Checkbox") and not $_->{"attributes"}{"readonly"} and $dbic->has_column($name) 0 0 0
Condition0%0/9
defined $result->param($name) || $_->isa("HTML::Widget::Element::Checkbox") and not $_->{"attributes"}{"readonly"} and $dbic->has_column($name)
!ll&&!rl&&r
000
defined $result->param($name) || $_->isa("HTML::Widget::Element::Checkbox") and not $_->{"attributes"}{"readonly"}
!ll&&!rl&&r
000
defined $result->param($name) or $_->isa("HTML::Widget::Element::Checkbox")
l!l&&r!l&&!r
000
MC/DC0%0/4
defined $result->param($name) || $_->isa("HTML::Widget::Element::Checkbox") and not $_->{"attributes"}{"readonly"} and $dbic->has_column($name)
defined $result->param($name) $_->isa("HTML::Widget::Element::Checkbox") not $_->{"attributes"}{"readonly"} $dbic->has_column($name)
Truth table0%0/7
A or B and not(C) and D
A= defined $result->param($name)B= $_->isa("HTML::Widget::Element::Checkbox")C= not $_->{"attributes"}{"readonly"}D= $dbic->has_column($name)
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
83 }
84 0 $dbic->insert_or_update;
85 0 return $dbic;
86 }
87  
88 1 1;
89 __END__
↑ Summary