| 1 | 3 | ▶ | use 5.20.0; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | package DBIx::Class::Smooth::ResultBase; | ||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | # ABSTRACT: Short intro | ||||||||||||||||||||||||||||||||
| 8 | 3 | our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY | |||||||||||||||||||||||||||||||
| 9 | 3 | our $VERSION = '0.0104'; | |||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use parent 'DBIx::Class::Core'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use experimental qw/signatures/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | ▶ | sub sqlt_deploy_hook($self, $table) { | |||||||||||||||||||||||||||||||
|
Subroutine
sqlt_deploy_hook: not called CC=12 SCAR=50.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 16 | 0 | my $indices = {}; | |||||||||||||||||||||||||||||||
| 17 | 0 | for my $column_name ($self->columns) { | |||||||||||||||||||||||||||||||
| 18 | 0 | my $info = $self->column_info($column_name); | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | if($info->{'indexed'}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | my $indexvalues = ref $info->{'indexed'} ne 'ARRAY' ? [ $info->{'indexed'} ] : $info->{'indexed'}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 0 | for my $indexvalue (@$indexvalues) { | |||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | if(length $indexvalue == 1 && $indexvalue) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
length $indexvalue == 1 and $indexvalue
MC/DC0%0/2
length $indexvalue == 1 and $indexvalue
length $indexvalue == 1
$indexvalue
Truth table0%0/3
A and B
A= length $indexvalue == 1B= $indexvalue
| |||||||||||||||||||||||||||||||||
| 27 | 0 | my $index_name = sprintf '%s_idxa_%s', $table, $column_name; | |||||||||||||||||||||||||||||||
| 28 | 0 | $indices->{ $index_name } = [$column_name]; | |||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||
| 30 | elsif(length $indexvalue > 1) { | ||||||||||||||||||||||||||||||||
| 31 | 0 | my $index_name = sprintf '%s_idxm_%s', $table, $indexvalue; | |||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if(!exists $indices->{ $index_name }) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 34 | 0 | $indices->{ $index_name } = []; | |||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||
| 36 | 0 | push @{ $indices->{ $index_name } } => $column_name; | |||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | if(scalar keys %$indices) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 43 | 0 | for my $index_name (keys %$indices) { | |||||||||||||||||||||||||||||||
| 44 | 0 | $table->add_index(name => $index_name, fields => $indices->{ $index_name }); | |||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | $self->next::method(@_) if $self->next::can; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 3 | 1; | |||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | __END__ | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | =pod | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | DBIx::Class::Smooth::ResultBase - Short intro | ||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | =head1 VERSION | ||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | Version 0.0104, released 2020-08-30. | ||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | # in MyApp::Schema::Result::YourResultClass, instead of inheriting from DBIx::Class::Core | ||||||||||||||||||||||||||||||||
| 69 | use parent 'DBIx::Class::Smooth::Result::Base'; | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | column last_name => { | ||||||||||||||||||||||||||||||||
| 72 | data_type => 'varchar', | ||||||||||||||||||||||||||||||||
| 73 | size => 150, | ||||||||||||||||||||||||||||||||
| 74 | indexed => 1, | ||||||||||||||||||||||||||||||||
| 75 | }; | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | Adding indices (apart from primary keys and unique constraints) requires creating a C<sqlt_deploy_hook> method and calling C<add_index> manually. This module | ||||||||||||||||||||||||||||||||
| 80 | adds the C<indexed> column attribute. | ||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | =head2 Possible values | ||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||
| 84 | C<indexed> behaves differently depending on the value it is given: | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | =over 4 | ||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | =item * | ||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | If given a one-character value, that evaluates to true, an index is created named C<[table_name]_idxa_[column_name]>. | ||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | =item * | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | If given a more-than-one-character value an index is created named C<[table_name]_idxm_[index_name]>. If multiple columns are given the same name a composite index is created. | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | =item * | ||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | If given an array reference each value in it is treated according to the two rules above. | ||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | =back | ||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | With these column definitions: | ||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | table('Author'); | ||||||||||||||||||||||||||||||||
| 105 | column first_name => { | ||||||||||||||||||||||||||||||||
| 106 | data_type => 'varchar', | ||||||||||||||||||||||||||||||||
| 107 | size => 150, | ||||||||||||||||||||||||||||||||
| 108 | indexed => 'name', | ||||||||||||||||||||||||||||||||
| 109 | }; | ||||||||||||||||||||||||||||||||
| 110 | column last_name => { | ||||||||||||||||||||||||||||||||
| 111 | data_type => 'varchar', | ||||||||||||||||||||||||||||||||
| 112 | size => 150, | ||||||||||||||||||||||||||||||||
| 113 | indexed => [1, 'name'], | ||||||||||||||||||||||||||||||||
| 114 | }; | ||||||||||||||||||||||||||||||||
| 115 | column country => { | ||||||||||||||||||||||||||||||||
| 116 | data_type => 'varchar', | ||||||||||||||||||||||||||||||||
| 117 | size => 150, | ||||||||||||||||||||||||||||||||
| 118 | indexed => 1, | ||||||||||||||||||||||||||||||||
| 119 | }; | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | The following indices are created: | ||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | =over 4 | ||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | =item * | ||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | C<Author_idxm_name> for C<first_name> and C<last_name> | ||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | =item * | ||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | C<Author_idxa_last_name> for C<last_name> | ||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | =item * | ||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||
| 135 | C<Author_idxa_country> for C<country> | ||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | =back | ||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | =head2 Still need a custom sqlt_deploy_hook? | ||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | If you need an C<sqlt_deploy_hook> method in a result source just call the parent's C<sqlt_deploy_hook> in your local sqlt_deploy_hook: | ||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | sub sqlt_deploy_hook { | ||||||||||||||||||||||||||||||||
| 144 | my $self = shift; | ||||||||||||||||||||||||||||||||
| 145 | my $table = shift; | ||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | $self->next::method($table); | ||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | ... | ||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | =head1 SOURCE | ||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | L<https://github.com/Csson/p5-DBIx-Class-Smooth> | ||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||
| 157 | =head1 HOMEPAGE | ||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||
| 159 | L<https://metacpan.org/release/DBIx-Class-Smooth> | ||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||
| 161 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||
| 163 | Erik Carlsson <info@code301.com> | ||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||
| 165 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||
| 167 | This software is copyright (c) 2018 by Erik Carlsson. | ||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||
| 169 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||
| 170 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||
| 172 | =cut | ||||||||||||||||||||||||||||||||