Smooth/ResultBase.pm

filter: Statementstmt 48.5% 17 / 35 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 36.0% 22 / 61 CC 12 SCAR 47.0
CC
12
Cov
33%
sqlt_deploy_hook
156.0
BEGIN
1.0
BEGIN
1.0
CRAP 110.4
« Smooth/Helper/ResultSet/Shortcut/RemoveColumns.pm ↑ Summary Smooth/ResultSetBase.pm »
1 2 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package DBIx::Class::Smooth::ResultBase;
6  
7 # ABSTRACT: Short intro
8 2 our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9 2 our $VERSION = '0.0105';
10  
11 2 ▶use parent 'DBIx::Class::Core';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶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
BranchTrueFalseTotal
if ($info->{"indexed"}) 0 0 0
21  
22 0 ▶ my $indexvalues = ref $info->{'indexed'} ne 'ARRAY' ? [ $info->{'indexed'} ] : $info->{'indexed'};
Branch: 1 branch
BranchTrueFalseTotal
ref $info->{'indexed'} ne 'ARRAY' ? : 0 0 0
23  
24 0 for my $indexvalue (@$indexvalues) {
25  
26 0 ▶ if(length $indexvalue == 1 && $indexvalue) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $indexvalue == 1 and $indexvalue) { } 0 0 0
elsif (length $indexvalue > 1) { } 0 0 0
Condition0%0/3
length $indexvalue == 1 and $indexvalue
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless (exists $indices->{$index_name}) 0 0 0
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
BranchTrueFalseTotal
if (scalar keys %$indices) 0 0 0
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
BranchTrueFalseTotal
if $self->next::can 0 0 0
48 }
49  
50 2 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.0105, released 2020-09-20.
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
« Smooth/Helper/ResultSet/Shortcut/RemoveColumns.pm ↑ Summary Smooth/ResultSetBase.pm »