blib/lib/DBIx/Class/Helper/Row/Enumeration.pm

filter: Statementstmt 100% 46 / 46 Branchbran 72.7% 16 / 22 Conditioncond 55.5% 5 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 81.3% 74 / 91 CC 17 SCAR 26.3
CC
17
Cov
87%
add_columns
18.3
__ANON__
1.0
BEGIN
1.0
CRAP 13.8
↑ Summary
1 package DBIx::Class::Helper::Row::Enumeration;
2  
3 # ABSTRACT: Add methods for emum values
4  
5 2 ▶use v5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Ref::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Sub::Quote ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # RECOMMEND PREREQ: Ref::Util::XS
14  
15 2 our $VERSION = 'v0.1.8';
16  
17 # The names of all methods installed by this module.
18 2 my %MINE;
19  
20  
21  
22 8 ▶sub add_columns {
Subroutine add_columns: called CC=17 SCAR=29.1
Pod undocumented
23 8 my ( $self, @cols ) = @_;
24  
25 8 $self->next::method(@cols);
26  
27 8 ▶ my $class = Ref::Util::is_ref($self) || $self;
Condition33%1/3
Ref::Util::XS::is_ref($self) || $self
l!l&&r!l&&!r
080
MC/DC0%0/2
Ref::Util::XS::is_ref($self) || $self
Ref::Util::XS::is_ref($self) $self
Truth table33%1/3
A || B
A= Ref::Util::XS::is_ref($self)B= $self
ABresult
1X1
011
000
28  
29 8 foreach my $col (@cols) {
30  
31 42 ▶ next if ref $col;
Branch: 1 branch
BranchTrueFalseTotal
if ref $col 19 23 42
32  
33 23 $col =~ s/^\+//;
34 23 my $info = $self->column_info($col);
35  
36 23 ▶ next unless $info->{data_type} eq 'enum';
Branch: 1 branch
BranchTrueFalseTotal
unless $info->{"data_type"} eq "enum" 3 20 23
37  
38 20 ▶ next unless exists $info->{extra}{list};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $info->{"extra"}{"list"} 0 20 20
39  
40 20 ▶ my $handlers = $info->{extra}{handles} //= sub { "is_" . $_[0] };
Subroutine __ANON__: called CC=1 SCAR=0.1
Condition66%2/3
$info->{"extra"}{"handles"} //= sub { 'is_' . $_[0]; }
l!l&&r!l&&!r
10100
MC/DC0%0/2
$info->{"extra"}{"handles"} //= sub { 'is_' . $_[0]; }
$info->{"extra"}{"handles"} sub { 'is_' . $_[0]; }
Truth table66%2/3
A //= B
A= $info->{"extra"}{"handles"}B= sub { 'is_' . $_[0]; }
ABresult
1X1
011
000
41  
42 20 ▶ next unless $handlers;
Branch: 1 branch
BranchTrueFalseTotal
unless $handlers 0 20 20
43  
44 20 ▶ if ( Ref::Util::is_plain_coderef($handlers) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (Ref::Util::XS::is_plain_coderef($handlers)) 15 5 20
45 $info->{extra}{handles} = {
46 map {
47  
48 40 ▶ if ( my $method = $handlers->( $_, $col, $class ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $method = &$handlers($_, $col, $class)) { } 35 5 40
49 35 ( $method => $_ )
50 }
51 else {
52 ()
53 5 }
54  
55 15 } @{ $info->{extra}{list} }
56 };
57 15 $handlers = $info->{extra}{handles};
58 }
59  
60 20 ▶ DBIx::Class::Exception->throw("handles is not a hashref")
Branch: 1 branch
BranchTrueFalseTotal
unless Ref::Util::XS::is_plain_hashref($handlers) 0 20 20
61 unless Ref::Util::is_plain_hashref($handlers);
62  
63 20 foreach my $handler ( keys %$handlers ) {
64 45 ▶ next unless $handler;
Branch: 1 branch
BranchTrueFalseTotal
unless $handler 0 45 45
65 45 ▶ my $value = $handlers->{$handler} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $value = $handlers->{$handler} or next 45 0 45
66  
67 45 my $method = "${class}::${handler}";
68  
69 # Keep track of what we've installed, and don't complain about
70 # being asked to reinstall it. This is needed when using
71 # DBIx::Class::Schema::Loader. In theory we should check whether
72 # the current method is the one we installed, and throw anyway if
73 # it isn't, but this seems adequate.
74 DBIx::Class::Exception->throw("${method} is already defined")
75 45 ▶ if $self->can($method) && !$MINE{$method};
Branch: 1 branch
BranchTrueFalseTotal
if $self->can($method) and not $MINE{$method} 0 45 45
Condition66%2/3
$self->can($method) and not $MINE{$method}
!ll&&!rl&&r
3690
MC/DC0%0/2
$self->can($method) and not $MINE{$method}
$self->can($method) not $MINE{$method}
Truth table66%2/3
A and not(B)
A= $self->can($method)B= not $MINE{$method}
ABresult
0X0
100
111
76  
77 my $code =
78 $info->{is_nullable}
79 45 ▶ ? qq{ my \$val = \$_[0]->get_column("${col}"); }
Branch: 1 branch
BranchTrueFalseTotal
$info->{'is_nullable'} ? : 10 35 45
80 . qq{ defined(\$val) && \$val eq "${value}" }
81 : qq{ \$_[0]->get_column("${col}") eq "${value}" };
82  
83 45 $MINE{$method} = 1;
84 45 Sub::Quote::quote_sub $method, $code;
85  
86 }
87  
88 }
89  
90 8 return $self;
91 }
92  
93  
94 2 1;
95  
96 __END__
↑ Summary