| 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
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
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 8 | foreach my $col (@cols) { | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 42 | ▶ | next if ref $col; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 20 | ▶ | next unless exists $info->{extra}{list}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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];
}
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];
}
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 20 | ▶ | next unless $handlers; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 20 | ▶ | if ( Ref::Util::is_plain_coderef($handlers) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | $info->{extra}{handles} = { | ||||||||||||||||||||||||||||
| 46 | map { | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 40 | ▶ | if ( my $method = $handlers->( $_, $col, $class ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 61 | unless Ref::Util::is_plain_hashref($handlers); | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 20 | foreach my $handler ( keys %$handlers ) { | |||||||||||||||||||||||||||
| 64 | 45 | ▶ | next unless $handler; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 45 | ▶ | my $value = $handlers->{$handler} or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$self->can($method) and not $MINE{$method}
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}
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | my $code = | ||||||||||||||||||||||||||||
| 78 | $info->{is_nullable} | ||||||||||||||||||||||||||||
| 79 | 45 | ▶ | ? qq{ my \$val = \$_[0]->get_column("${col}"); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||