| 1 | package DBIx::Class::ResultDDL::SchemaLoaderMixin; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 List::Util 'max', 'all'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use DBIx::Class::ResultDDL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | sub deparse; #local utilities to be cleaned from the namespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | sub deparse_hashkey; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # ABSTRACT: Modify Schema Loader to generate ResultDDL notation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | our $VERSION = '2.04'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | #sub _write_classfile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # my ($self, $class, $text, $is_schema)= @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # main::explain($class); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # main::explain($text); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # main::explain($self->{_dump_storage}{$class}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # $self->next::method($class, $text, $is_schema); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | #} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | ▶ | sub generate_resultddl_import_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_resultddl_import_line: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | qq|use DBIx::Class::ResultDDL qw/ -V2 /;\n| | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 20 | ▶ | sub generate_column_info_sugar { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_column_info_sugar: called CC=16 SCAR=28.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 20 | my ($self, $class, $col_name, $orig_col_info)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 20 | my $checkpkg= $self->_get_class_check_namespace($class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 20 | my $class_settings= DBIx::Class::ResultDDL::_settings_for_package($checkpkg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 20 | my %col_info= %$orig_col_info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 20 | my $stmt= _get_data_type_sugar(\%col_info, $class_settings); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | $stmt .= ' null' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 20 | ▶ | if delete $col_info{is_nullable}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | $stmt .= ' default('.deparse(delete $col_info{default_value}).'),' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 20 | ▶ | if exists $col_info{default_value}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # add sugar for inflate_json if the serializer class is JSON, but not if the package feature inflate_json | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # was enabled and the column type is flagged as json. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 20 | ▶ | $stmt .= ' inflate_json' if 'JSON' eq ($col_info{serializer_class}||''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$col_info{'serializer_class'} || ''
MC/DC0%0/1
$col_info{'serializer_class'} || ''
$col_info{'serializer_class'}
Truth table50%1/2
A
A= $col_info{'serializer_class'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 20 | ▶ | $stmt .= ' fk' if delete $col_info{is_foreign_key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # Test the syntax for equality to the original | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 20 | my $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 20 | eval "package $checkpkg; \$out= DBIx::Class::ResultDDL::expand_col_options(\$checkpkg, $stmt);"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 20 | ▶ | defined $out or croak "Error verifying generated ResultDDL for $class $col_name: $@"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 20 | ▶ | if ($out->{'extra.unsigned'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $out->{extra}{unsigned}= delete $out->{'extra.unsigned'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # Ignore the problem where 'integer' generates a default size for mysql that wasn't | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # in the Schema Loader spec. TODO: add an option to skip generating this. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 20 | ▶ | delete $out->{size} if $out->{size} && !$orig_col_info->{size}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$out->{"size"} and not $orig_col_info->{"size"}
MC/DC100%2/2
$out->{"size"} and not $orig_col_info->{"size"}
$out->{"size"}
not $orig_col_info->{"size"}
Truth table100%3/3
A and not(B)
A= $out->{"size"}B= not $orig_col_info->{"size"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # Data::Dumper gets confused and thinks sizes need quoted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 20 | ▶ | if (defined $orig_col_info->{size} && $orig_col_info->{size} =~ /^[0-9]+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $orig_col_info->{"size"} and $orig_col_info->{"size"} =~ /^[0-9]+$/
MC/DC50%1/2
defined $orig_col_info->{"size"} and $orig_col_info->{"size"} =~ /^[0-9]+$/
defined $orig_col_info->{"size"}
$orig_col_info->{"size"} =~ /^[0-9]+$/
Truth table66%2/3
A and B
A= defined $orig_col_info->{"size"}B= $orig_col_info->{"size"} =~ /^[0-9]+$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 8 | $orig_col_info->{size}= 0 + $orig_col_info->{size}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 20 | ▶ | if (deparse({ %col_info, %$out }) eq deparse({ %$orig_col_info })) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # Any field in %$out removes the need to have it in $col_info. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # This happens with implied options like serializer_class => 'JSON' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 20 | for (keys %col_info) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 4 | ▶ | delete $col_info{$_} if exists $out->{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # remove trailing comma | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 20 | $stmt =~ s/,\s*$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # dump the rest, and done. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | $stmt .= ', '.&_deparse_hashkey.' => '.deparse($col_info{$_}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 20 | for sort keys %col_info; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | warn "Unable to use ResultDDL sugar '$stmt'\n " | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | .deparse({ %col_info, %$out })." ne ".deparse($orig_col_info)."\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | $stmt= join(', ', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | map &_deparse_hashkey.' => '.deparse($orig_col_info->{$_}), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | sort keys %$orig_col_info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 20 | return $stmt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 4 | ▶ | sub generate_relationship_sugar { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_relationship_sugar: called CC=13 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 4 | my ($self, $class, $method, $relname, $foreignclass, $colmap, $options)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | #use DDP; &p(['before', @_[1..$#_]]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | my $expr= ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # The $foreignclass $colmap arguments can be combined into a simpler | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # hashref of { local_col => 'ForeignClass.colname' } as long as some expectations hold: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 4 | my ($parent_ns)= ($class =~ /^(.*?::)([^:]+)$/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 4 | ▶ | if (defined $parent_ns and !ref $foreignclass and (!ref $colmap || ref $colmap eq 'HASH')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
defined $parent_ns and not ref $foreignclass and !ref($colmap) || ref $colmap eq "HASH"
defined $parent_ns and not ref $foreignclass
not ref $colmap or ref $colmap eq "HASH"
MC/DC0%0/4
defined $parent_ns and not ref $foreignclass and !ref($colmap) || ref $colmap eq "HASH"
defined $parent_ns
not ref $foreignclass
not ref $colmap
ref $colmap eq "HASH"
Truth table20%1/5
A and not(B) and not(C) or D
A= defined $parent_nsB= not ref $foreignclassC= not ref $colmapD= ref $colmap eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # Can we use a shortened class name for the foreign table? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 4 | ▶ | if ($foreignclass =~ /^(.*?::)([^:]+)$/ and $1 eq $parent_ns) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$foreignclass =~ /^(.*?::)([^:]+)$/ and $1 eq $parent_ns
MC/DC0%0/2
$foreignclass =~ /^(.*?::)([^:]+)$/ and $1 eq $parent_ns
$foreignclass =~ /^(.*?::)([^:]+)$/
$1 eq $parent_ns
Truth table33%1/3
A and B
A= $foreignclass =~ /^(.*?::)([^:]+)$/B= $1 eq $parent_ns
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | $foreignclass= $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | ▶ | my %newmap= ref $colmap eq 'HASH'? (%$colmap) : ($colmap => $colmap); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # Just in case SchemaLoader prefixed them with 'self.' or 'foreign.'... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 4 | s/^self[.]// for values %newmap; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 4 | %newmap= reverse %newmap; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 4 | s/^foreign[.]// for values %newmap; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # Apply the foreign class name to the first column in the map | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 4 | my ($first_key)= sort keys %newmap; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 4 | $newmap{$first_key}= $foreignclass . '.' . $newmap{$first_key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 4 | $expr .= deparse(\%newmap); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $expr .= deparse($foreignclass, $colmap); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 4 | ▶ | if ($options && keys %$options) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$options and keys %$options
MC/DC0%0/2
$options and keys %$options
$options
keys %$options
Truth table33%1/3
A and B
A= $optionsB= keys %$options
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 4 | $expr .= ', ' . $self->generate_relationship_attr_sugar($options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # Test the syntax for equality to the original | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 4 | my $checkpkg= $self->_get_class_check_namespace($class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 4 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 4 | eval "package $checkpkg; \@out= DBIx::Class::ResultDDL::expand_relationship_params(\$class, \$method, \$relname, $expr);"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 4 | ▶ | @out or croak "Error verifying generated ResultDDL for $class $method $relname: $@"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | #use DDP; &p(['after', @out, $expr]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 4 | return $method . ' ' . deparse_hashkey($relname) . ' => ' . $expr . ';'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 4 | ▶ | sub generate_relationship_attr_sugar { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_relationship_attr_sugar: called CC=11 SCAR=25.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 4 | my ($self, $orig_options)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 4 | my %options= %$orig_options; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 4 | my @expr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 4 | ▶ | if (defined $options{on_update} && defined $options{on_delete} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $options{"on_update"} and defined $options{"on_delete"} and $options{"on_update"} eq $options{"on_delete"}
defined $options{"on_update"} and defined $options{"on_delete"}
MC/DC33%1/3
defined $options{"on_update"} and defined $options{"on_delete"} and $options{"on_update"} eq $options{"on_delete"}
defined $options{"on_update"}
defined $options{"on_delete"}
$options{"on_update"} eq $options{"on_delete"}
Truth table50%2/4
A and B and C
A= defined $options{"on_update"}B= defined $options{"on_delete"}C= $options{"on_update"} eq $options{"on_delete"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | && $options{on_update} eq $options{on_delete} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | my $val= delete $options{on_update}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 2 | delete $options{on_delete}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | ▶ | push @expr, $val eq 'CASCADE'? 'ddl_cascade' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | : $val eq 'RESTRICT'? 'ddl_cascade(0)' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | : 'ddl_cascade('.deparse($val).')' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 4 | ▶ | if (defined $options{cascade_copy} && defined $options{cascade_delete} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $options{"cascade_copy"} and defined $options{"cascade_delete"} and $options{"cascade_copy"} eq $options{"cascade_delete"}
defined $options{"cascade_copy"} and defined $options{"cascade_delete"}
MC/DC33%1/3
defined $options{"cascade_copy"} and defined $options{"cascade_delete"} and $options{"cascade_copy"} eq $options{"cascade_delete"}
defined $options{"cascade_copy"}
defined $options{"cascade_delete"}
$options{"cascade_copy"} eq $options{"cascade_delete"}
Truth table50%2/4
A and B and C
A= defined $options{"cascade_copy"}B= defined $options{"cascade_delete"}C= $options{"cascade_copy"} eq $options{"cascade_delete"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | && $options{cascade_copy} eq $options{cascade_delete} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | my $val= delete $options{cascade_copy}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | delete $options{cascade_delete}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | ▶ | push @expr, $val eq '1'? 'dbic_cascade' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | : 'dbic_cascade('.deparse($val).')' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 4 | ▶ | push @expr, substr(deparse(\%options),2,-2) if keys %options; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 4 | return join ', ', @expr | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | my %rel_methods= map +($_ => 1), qw( belongs_to might_have has_one has_many ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 22 | ▶ | sub _dbic_stmt { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbic_stmt: called CC=10 SCAR=23.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 22 | my ($self, $class, $method)= splice(@_, 0, 3); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # The first time we generate anything for each class, inject the 'use' line. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | $self->_raw_stmt($class, $self->generate_resultddl_import_line($class)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 22 | ▶ | unless $self->{_ResultDDL_SchemaLoader}{$class}{use_line}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 22 | ▶ | if ($method eq 'table') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 6 | $self->_raw_stmt($class, q|table |.deparse(@_).';'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | elsif ($method eq 'add_columns') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 6 | my @col_defs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 6 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 20 | my ($col_name, $col_info)= splice(@_, 0, 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 20 | push @col_defs, [ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | deparse_hashkey($col_name), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | $self->generate_column_info_sugar($class, $col_name, $col_info) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # align the definitions, but round up to help avoid unnecessary diffs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # when new columns get added. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 6 | my $widest= max map length($_->[0]), @col_defs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 6 | $widest= ($widest + 3) & ~3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | $self->_raw_stmt($class, sprintf("col %-*s => %s;", $widest, @$_)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 6 | for @col_defs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | elsif ($method eq 'set_primary_key') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 6 | $self->_raw_stmt($class, q|primary_key |.deparse(@_).";"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | ▶ | elsif ($rel_methods{$method} && @_ == 4) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$rel_methods{$method} and @_ == 4
MC/DC0%0/2
$rel_methods{$method} and @_ == 4
$rel_methods{$method}
@_ == 4
Truth table33%1/3
A and B
A= $rel_methods{$method}B= @_ == 4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # Add a linebreak before the relationships, for readability. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | $self->_raw_stmt($class, "\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 4 | ▶ | unless $self->{_ResultDDL_SchemaLoader}{$class}{relation_linebreak}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 4 | $self->_raw_stmt($class, $self->generate_relationship_sugar($class, $method, @_)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | $self->next::method($class, $method, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 22 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | my %data_type_sugar= ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | (map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 11 | my $type= $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 10 | ▶ | $type => sub { my ($col_info)= @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=30.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 10 | ▶ | if ($col_info->{size} && $col_info->{size} =~ /^[0-9]+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$col_info->{"size"} and $col_info->{"size"} =~ /^[0-9]+$/
MC/DC50%1/2
$col_info->{"size"} and $col_info->{"size"} =~ /^[0-9]+$/
$col_info->{"size"}
$col_info->{"size"} =~ /^[0-9]+$/
Truth table66%2/3
A and B
A= $col_info->{"size"}B= $col_info->{"size"} =~ /^[0-9]+$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 8 | return "$type(".delete($col_info->{size})."),"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | ▶ | } elsif ($col_info->{size} && ref $col_info->{size} eq 'ARRAY' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition25%3/12
$col_info->{"size"} and ref $col_info->{"size"} eq "ARRAY" and $#{$$col_info{"size"};} == 0 || $#{$$col_info{"size"};} == 1 and &all(sub {
/^[0-9]+$/;
}
, @{$$col_info{"size"};})
$col_info->{"size"} and ref $col_info->{"size"} eq "ARRAY" and $#{$$col_info{"size"};} == 0 || $#{$$col_info{"size"};} == 1
$col_info->{"size"} and ref $col_info->{"size"} eq "ARRAY"
$#{$$col_info{"size"};} == 0 or $#{$$col_info{"size"};} == 1
MC/DC0%0/5
$col_info->{"size"} and ref $col_info->{"size"} eq "ARRAY" and $#{$$col_info{"size"};} == 0 || $#{$$col_info{"size"};} == 1 and &all(sub {
/^[0-9]+$/;
}
, @{$$col_info{"size"};})
$col_info->{"size"}
ref $col_info->{"size"} eq "ARRAY"
$#{$$col_info{"size"};} == 0
$#{$$col_info{"size"};} == 1
&all(sub {
/^[0-9]+$/;
}
, @{$$col_info{"size"};})
Truth table14%1/7
A and B and C or D and E
A= $col_info->{"size"}B= ref $col_info->{"size"} eq "ARRAY"C= $#{$$col_info{"size"};} == 0D= $#{$$col_info{"size"};} == 1E= &all(sub {
/^[0-9]+$/;
}
, @{$$col_info{"size"};})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | && ($#{$col_info->{size}} == 0 || $#{$col_info->{size}} == 1) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | && (all { /^[0-9]+$/ } @{$col_info->{size}}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | return "$type(".join(',', @{delete($col_info->{size})})."),"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 2 | return $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 11 | } qw( integer float real numeric decimal varchar nvarchar char nchar binary varbinary )), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | (map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 2 | my $type= $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 6 | ▶ | $type => sub { my ($col_info, $class_settings)= @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # include timezone in type sugar, if known. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 6 | ▶ | if ($col_info->{timezone} && !ref $col_info->{timezone}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$col_info->{"timezone"} and not ref $col_info->{"timezone"}
MC/DC50%1/2
$col_info->{"timezone"} and not ref $col_info->{"timezone"}
$col_info->{"timezone"}
not ref $col_info->{"timezone"}
Truth table66%2/3
A and not(B)
A= $col_info->{"timezone"}B= not ref $col_info->{"timezone"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 1 | return "$type(".deparse(delete $col_info->{timezone})."),"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 5 | return $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 2 | } qw( datetime timestamp )), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | (map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | my $type= $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 2 | ▶ | $type => sub { my ($col_info, $class_settings)= @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # Remove serializer_class => 'JSON' if inflate_json is enabled package-wide | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | delete $col_info->{serializer_class} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 2 | ▶ | if $class_settings->{inflate_json} && ($col_info->{serializer_class}||'') eq 'JSON'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
$class_settings->{"inflate_json"} and ($col_info->{"serializer_class"} || "") eq "JSON"
$col_info->{'serializer_class'} || ''
MC/DC0%0/2
$class_settings->{"inflate_json"} and ($col_info->{"serializer_class"} || "") eq "JSON"
$class_settings->{"inflate_json"}
$col_info->{'serializer_class'}
Truth table33%1/3
A and B
A= $class_settings->{"inflate_json"}B= $col_info->{'serializer_class'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 2 | return $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 2 | } qw( json jsonb )), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 20 | ▶ | sub _get_data_type_sugar { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_data_type_sugar: called CC=11 SCAR=35.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 20 | my ($col_info, $class_settings)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | my $t= delete $col_info->{data_type} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 20 | ▶ | or return (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 20 | ▶ | my $pl= ($data_type_sugar{$t} //= do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$data_type_sugar{$t} //= do {
my $sugar = "DBIx::Class::ResultDDL"->can($t);
my(@out) = $sugar ? &$sugar() : ();
@out >= 2 && $out[0] eq "data_type" && $out[1] eq $t ? sub {
$t;
}
: sub {
'data_type => ' . deparse($t) . ',';
}
}
MC/DC0%0/2
$data_type_sugar{$t} //= do {
my $sugar = "DBIx::Class::ResultDDL"->can($t);
my(@out) = $sugar ? &$sugar() : ();
@out >= 2 && $out[0] eq "data_type" && $out[1] eq $t ? sub {
$t;
}
: sub {
'data_type => ' . deparse($t) . ',';
}
}
$data_type_sugar{$t}
do {
my $sugar = "DBIx::Class::ResultDDL"->can($t);
my(@out) = $sugar ? &$sugar() : ();
@out >= 2 && $out[0] eq "data_type" && $out[1] eq $t ? sub {
$t;
}
: sub {
'data_type => ' . deparse($t) . ',';
}
}
Truth table66%2/3
A //= B
A= $data_type_sugar{$t}B= do {
my $sugar = "DBIx::Class::ResultDDL"->can($t);
my(@out) = $sugar ? &$sugar() : ();
@out >= 2 && $out[0] eq "data_type" && $out[1] eq $t ? sub {
$t;
}
: sub {
'data_type => ' . deparse($t) . ',';
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 1 | my $sugar= DBIx::Class::ResultDDL->can($t); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 1 | ▶ | my @out= $sugar? $sugar->() : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 2 | ▶ | @out >= 2 && $out[0] eq 'data_type' && $out[1] eq $t? sub { $t } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | : sub { 'data_type => '.deparse($t).',' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 1 | ▶ | })->($col_info, $class_settings); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
@out >= 2 and $out[0] eq "data_type" and $out[1] eq $t
@out >= 2 and $out[0] eq "data_type"
MC/DC0%0/3
@out >= 2 and $out[0] eq "data_type" and $out[1] eq $t
@out >= 2
$out[0] eq "data_type"
$out[1] eq $t
Truth table25%1/4
A and B and C
A= @out >= 2B= $out[0] eq "data_type"C= $out[1] eq $t
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 20 | ▶ | if ($col_info->{extra} && $col_info->{extra}{unsigned}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$col_info->{"extra"} and $col_info->{"extra"}{"unsigned"}
MC/DC0%0/2
$col_info->{"extra"} and $col_info->{"extra"}{"unsigned"}
$col_info->{"extra"}
$col_info->{"extra"}{"unsigned"}
Truth table33%1/3
A and B
A= $col_info->{"extra"}B= $col_info->{"extra"}{"unsigned"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | $pl =~ s/,?$/,/ unless $pl =~ /\w$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | $pl .= ' unsigned'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | if (1 == keys %{ $col_info->{extra} }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | delete $col_info->{extra}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | $col_info->{extra}= { %{ $col_info->{extra} } }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | delete $col_info->{extra}{unsigned}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 20 | return $pl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 143 | ▶ | sub _deparse_scalar { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_deparse_scalar: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 143 | ▶ | return 'undef' unless defined; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 143 | ▶ | return $_ if /^(0|[1-9][0-9]*)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 67 | my $x= $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 67 | $x =~ s/\\/\\\\/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 67 | $x =~ s/'/\\'/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 67 | return "'$x'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 6 | ▶ | sub _deparse_scalarref { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_deparse_scalarref: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 6 | "\\" . (map &_deparse_scalar, $$_)[0] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 24 | ▶ | sub deparse_hashkey { local $_= $_[0]; &_deparse_hashkey } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deparse_hashkey: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 148 | ▶ | sub _deparse_hashkey { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_deparse_hashkey: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # TODO: complete support for perl's left-hand of => operator parsing rule | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 148 | ▶ | /^[A-Za-z_][A-Za-z0-9_]*$/? $_ : &_deparse_scalar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 46 | ▶ | sub _deparse_hashref { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_deparse_hashref: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 46 | my $h= $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 46 | return '{ '.join(', ', map +(&_deparse_hashkey.' => '.deparse($h->{$_})), sort keys %$h).' }' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | sub _deparse_arrayref { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_deparse_arrayref: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | return '[ '.join(', ', map &_deparse, @$_).' ]' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 189 | ▶ | sub _deparse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_deparse: called CC=5 SCAR=18.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | !ref()? &_deparse_scalar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | : ref() eq 'SCALAR'? &_deparse_scalarref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | : ref() eq 'ARRAY'? &_deparse_arrayref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | : ref() eq 'HASH'? &_deparse_hashref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 189 | ▶ | : do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | Data::Dumper->new([$_])->Terse(1)->Quotekeys(0)->Sortkeys(1)->Indent(0)->Dump; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 187 | ▶ | sub deparse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deparse: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 187 | join(', ', map &_deparse, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 1 | our %per_class_check_namespace; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 24 | ▶ | sub _get_class_check_namespace { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_class_check_namespace: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 24 | my ($self, $class)= @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 24 | ▶ | return ($per_class_check_namespace{$class} ||= do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$DBIx::Class::ResultDDL::SchemaLoaderMixin::per_class_check_namespace{$class} ||= do {
my $use_line = $self->generate_resultddl_import_line($class);
local $DBIx::Class::ResultDDL::DISABLE_AUTOCLEAN = 1;
my $pkg = 'DBIx::Class::ResultDDL_check' . scalar(keys %DBIx::Class::ResultDDL::SchemaLoaderMixin::per_class_check_namespace);
my $perl = "package $pkg; $use_line 1";
eval $perl or croak("Error setting up package to verify generated ResultDDL: $@\nFor code:\n$perl");
$pkg
}
MC/DC0%0/2
$DBIx::Class::ResultDDL::SchemaLoaderMixin::per_class_check_namespace{$class} ||= do {
my $use_line = $self->generate_resultddl_import_line($class);
local $DBIx::Class::ResultDDL::DISABLE_AUTOCLEAN = 1;
my $pkg = 'DBIx::Class::ResultDDL_check' . scalar(keys %DBIx::Class::ResultDDL::SchemaLoaderMixin::per_class_check_namespace);
my $perl = "package $pkg; $use_line 1";
eval $perl or croak("Error setting up package to verify generated ResultDDL: $@\nFor code:\n$perl");
$pkg
}
$DBIx::Class::ResultDDL::SchemaLoaderMixin::per_class_check_namespace{$class}
do {
my $use_line = $self->generate_resultddl_import_line($class);
local $DBIx::Class::ResultDDL::DISABLE_AUTOCLEAN = 1;
my $pkg = 'DBIx::Class::ResultDDL_check' . scalar(keys %DBIx::Class::ResultDDL::SchemaLoaderMixin::per_class_check_namespace);
my $perl = "package $pkg; $use_line 1";
eval $perl or croak("Error setting up package to verify generated ResultDDL: $@\nFor code:\n$perl");
$pkg
}
Truth table66%2/3
A ||= B
A= $DBIx::Class::ResultDDL::SchemaLoaderMixin::per_class_check_namespace{$class}B= do {
my $use_line = $self->generate_resultddl_import_line($class);
local $DBIx::Class::ResultDDL::DISABLE_AUTOCLEAN = 1;
my $pkg = 'DBIx::Class::ResultDDL_check' . scalar(keys %DBIx::Class::ResultDDL::SchemaLoaderMixin::per_class_check_namespace);
my $perl = "package $pkg; $use_line 1";
eval $perl or croak("Error setting up package to verify generated ResultDDL: $@\nFor code:\n$perl");
$pkg
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 6 | my $use_line= $self->generate_resultddl_import_line($class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 6 | local $DBIx::Class::ResultDDL::DISABLE_AUTOCLEAN= 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 6 | my $pkg= 'DBIx::Class::ResultDDL_check' . scalar keys %per_class_check_namespace; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 6 | my $perl= "package $pkg; $use_line 1"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 1 | ▶ | eval $perl or croak "Error setting up package to verify generated ResultDDL: $@\nFor code:\n$perl"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 6 | $pkg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||