| 1 | package DBIx::Class::EncodedColumn; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use base qw/DBIx::Class/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Sub::Name; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 4 | __PACKAGE__->mk_classdata( '_column_encoders' ); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 4 | our $VERSION = '0.00014'; | |||||||||||||||||||||||||||
| 12 | 4 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub register_column { | ||||||||||||||||||||||||||||
| 15 | 15 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
register_column: called CC=13 SCAR=26.2
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 15 | my ($column, $info) = @_; | |||||||||||||||||||||||||||
| 17 | 15 | $self->next::method(@_); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 15 | ▶ | return unless exists $info->{encode_column} && $info->{encode_column} == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $info->{"encode_column"} and $info->{"encode_column"} == 1
MC/DC100%2/2
exists $info->{"encode_column"} and $info->{"encode_column"} == 1
exists $info->{"encode_column"}
$info->{"encode_column"} == 1
Truth table100%3/3
A and B
A= exists $info->{"encode_column"}B= $info->{"encode_column"} == 1
| |||||||||||||||||||||||||||||
| 20 | $self->throw_exception("'encode_class' is a required argument.") | ||||||||||||||||||||||||||||
| 21 | 11 | ▶ | unless exists $info->{encode_class} && defined $info->{encode_class}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $info->{"encode_class"} and defined $info->{"encode_class"}
MC/DC0%0/2
exists $info->{"encode_class"} and defined $info->{"encode_class"}
exists $info->{"encode_class"}
defined $info->{"encode_class"}
Truth table33%1/3
A and B
A= exists $info->{"encode_class"}B= defined $info->{"encode_class"}
| |||||||||||||||||||||||||||||
| 22 | 11 | my $class = $info->{encode_class}; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 11 | ▶ | my $args = exists $info->{encode_args} ? $info->{encode_args} : {}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 11 | ▶ | $self->throw_exception("'encode_args' must be a hashref") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | unless ref $args eq 'HASH'; | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 11 | $class = join("::", 'DBIx::Class::EncodedColumn', $class); | |||||||||||||||||||||||||||
| 29 | 11 | eval "require ${class};"; | |||||||||||||||||||||||||||
| 30 | 11 | ▶ | $self->throw_exception("Failed to use encode_class '${class}': $@") if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 11 | ▶ | defined( my $encode_sub = eval{ $class->make_encode_sub($column, $args) }) || | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | $self->throw_exception("Failed to create encoder with class '$class': $@"); | ||||||||||||||||||||||||||||
| 34 | 11 | ▶ | $self->_column_encoders({$column => $encode_sub, %{$self->_column_encoders || {}}}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 11 | ▶ | if ( exists $info->{encode_check_method} && $info->{encode_check_method} ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $info->{"encode_check_method"} and $info->{"encode_check_method"}
MC/DC50%1/2
exists $info->{"encode_check_method"} and $info->{"encode_check_method"}
exists $info->{"encode_check_method"}
$info->{"encode_check_method"}
Truth table66%2/3
A and B
A= exists $info->{"encode_check_method"}B= $info->{"encode_check_method"}
| |||||||||||||||||||||||||||||
| 37 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 9 | ▶ | defined( my $check_sub = eval{ $class->make_check_sub($column, $args) }) || | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | $self->throw_exception("Failed to create checker with class '$class': $@"); | ||||||||||||||||||||||||||||
| 40 | 9 | my $name = join '::', $self->result_class, $info->{encode_check_method}; | |||||||||||||||||||||||||||
| 41 | 9 | *$name = subname $name, $check_sub; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | sub set_column { | ||||||||||||||||||||||||||||
| 46 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
set_column: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 7 | ▶ | return $self->next::method(@_) unless defined $_[1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 6 | my $encs = $self->_column_encoders; | |||||||||||||||||||||||||||
| 49 | 6 | ▶ | if(exists $encs->{$_[0]} && defined(my $encoder = $encs->{$_[0]})){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $$encs{$_[0]} and defined(my $encoder = $$encs{$_[0]})
MC/DC50%1/2
exists $$encs{$_[0]} and defined(my $encoder = $$encs{$_[0]})
exists $$encs{$_[0]}
defined(my $encoder = $$encs{$_[0]})
Truth table66%2/3
A and B
A= exists $$encs{$_[0]}B= defined(my $encoder = $$encs{$_[0]})
| |||||||||||||||||||||||||||||
| 50 | 5 | return $self->next::method($_[0], $encoder->($_[1])); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | 1 | $self->next::method(@_); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | sub new { | ||||||||||||||||||||||||||||
| 56 | 3 | ▶ | my($self, $attr, @rest) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 3 | my $encoders = $self->_column_encoders; | |||||||||||||||||||||||||||
| 58 | 3 | for my $col (grep { defined $encoders->{$_} } keys %$encoders ) { | |||||||||||||||||||||||||||
| 59 | 11 | ▶ | next unless exists $attr->{$col} && defined $attr->{$col}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $attr->{$col} and defined $attr->{$col}
MC/DC0%0/2
exists $attr->{$col} and defined $attr->{$col}
exists $attr->{$col}
defined $attr->{$col}
Truth table33%1/3
A and B
A= exists $attr->{$col}B= defined $attr->{$col}
| |||||||||||||||||||||||||||||
| 60 | 11 | $attr->{$col} = $encoders->{$col}->( $attr->{$col} ); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 2 | return $self->next::method($attr, @rest); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 4 | 1; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | __END__; | ||||||||||||||||||||||||||||