Smooth/Helper/ResultSet/Shortcut/OrderByCollation.pm

filter: Statementstmt 62.5% 20 / 32 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 2 totaltotal 54.1% 26 / 48 CC 4 SCAR 15.9
CC
4
Cov
53%
smooth__helper__orderbycollation__prepare_for_sql
12.0
order_by_collation
6.0
BEGIN
1.0
CRAP 4.9
« Smooth/Q.pm ↑ Summary Smooth/Helper/ResultSet/Shortcut/Join.pm »
1 1 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
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  
5 package DBIx::Class::Smooth::Helper::ResultSet::Shortcut::OrderByCollation;
6  
7 # ABSTRACT: Short intro
8 1 our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9 1 our $VERSION = '0.0108';
10  
11 1 ▶use parent 'DBIx::Class::Smooth::ResultSetBase';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Carp qw/confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use experimental qw/signatures postderef/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # This only expects calls like ->order_by_collation('utf8mb4_swedish_ci', 'name', '!other_name')
16 0 ▶sub order_by_collation($self, $collation, @column_names) {
Subroutine order_by_collation: not called CC=2 SCAR=17.9
Pod undocumented
17  
18 0 ▶ if(!defined $collation) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $collation) 0 0 0
19 0 return $self->order_by(@column_names);
20 }
21  
22 0 my $sql_order_by_args = join ', ' => map { $self->smooth__helper__orderbycollation__prepare_for_sql($collation, $_) } @column_names;
23  
24 0 return $self->search(undef, { order_by => \$sql_order_by_args });
25 }
26  
27 # This is based on DBIx::Class::Helper::ResultSet::Shortcut::OrderByMagic::order_by
28 0 ▶sub smooth__helper__orderbycollation__prepare_for_sql($self, $collation, $column_name) {
Subroutine smooth__helper__orderbycollation__prepare_for_sql: not called CC=3 SCAR=24.8
Pod undocumented
29 0 my $direction = 'ASC';
30 0 ▶ if(substr($column_name, 0, 1) eq '!') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($column_name, 0, 1) eq "!") 0 0 0
31 0 $column_name = substr $column_name, 1;
32 0 $direction = 'DESC';
33 }
34  
35 0 ▶ if(index($column_name, '.') == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($column_name, ".") == -1) 0 0 0
36 0 $column_name = join '.' => ($self->current_source_alias, $column_name);
37 }
38  
39 0 return "$column_name COLLATE $collation $direction";
40 }
41  
42 1 1;
43  
44 __END__
« Smooth/Q.pm ↑ Summary Smooth/Helper/ResultSet/Shortcut/Join.pm »