File Coverage

blib/lib/DBIx/Class/Smooth/Lookup/Util.pm
Criterion Covered Total %
statement 17 49 34.6
branch 0 12 0.0
condition 0 9 0.0
subroutine 6 9 66.6
pod 0 3 0.0
total 23 82 28.0


line stmt bran cond sub pod time code
1 2     2   768 use 5.20.0;
  2         7  
2 2     2   9 use strict;
  2         5  
  2         33  
3 2     2   9 use warnings;
  2         4  
  2         125  
4              
5             package DBIx::Class::Smooth::Lookup::Util;
6              
7             # ABSTRACT: Short intro
8             our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9             our $VERSION = '0.0102';
10              
11 2         10 use parent qw/
12             DBIx::Class::Smooth::ResultSetBase
13 2     2   13 /;
  2         2  
14 2     2   151 use Carp qw/confess/;
  2         3  
  2         121  
15 2     2   10 use experimental qw/signatures postderef/;
  2         5  
  2         13  
16              
17 0     0 0   sub smooth__lookup_util__ensure_value_is_arrayref($self, $lookup_name, $value) {
  0            
  0            
  0            
  0            
18 0 0         if(ref $value ne 'ARRAY') {
19 0           confess sprintf '<%s> expects an array, got <%s>', $lookup_name, $value;
20             }
21             }
22              
23 0     0 0   sub smooth__lookup_util__ensure_value_is_scalar($self, $lookup_name, $value) {
  0            
  0            
  0            
  0            
24 0 0         if(ref $value) {
25 0           confess sprintf '<%s> expects a scalar, got a <%s>', $lookup_name, ref($value);
26             }
27             }
28              
29 0     0 0   sub smooth__lookup_util__ensure_param_count($self, $lookup_name, $params, $ensure_options) {
  0            
  0            
  0            
  0            
  0            
30 0   0       my $at_least = delete $ensure_options->{'at_least'} || 0;
31 0   0       my $at_most = delete $ensure_options->{'at_most'} || 10000;
32 0   0       my $regex = delete $ensure_options->{'regex'} || undef;
33              
34 0 0         if(keys $ensure_options->%*) {
35 0           confess sprintf "Unexpected keys <%s>", join(', ', sort keys $ensure_options->%*);
36             }
37              
38 0 0 0       if(scalar $params->@* < $at_least || scalar $params->@* > $at_most) {
39 0           confess sprintf "<%s> expects between $at_least and $at_most params, got %d: <%s>", $lookup_name, scalar ($params->@*), join (', ' => $params->@*);
40             }
41              
42 0 0         if($regex) {
43 0           my @correct_params = grep { /$regex/ } $params->@*;
  0            
44 0 0         if(scalar @correct_params != scalar $params->@*) {
45 0           confess sprintf '<%s> got faulty params, check documentation: <%s>', $lookup_name, join (', ' => $params->@*);
46             }
47             }
48             }
49              
50             1;
51              
52             __END__
53              
54             =pod
55              
56             =encoding UTF-8
57              
58             =head1 NAME
59              
60             DBIx::Class::Smooth::Lookup::Util - Short intro
61              
62             =head1 VERSION
63              
64             Version 0.0102, released 2019-12-22.
65              
66             =head1 SOURCE
67              
68             L<https://github.com/Csson/p5-DBIx-Class-Smooth>
69              
70             =head1 HOMEPAGE
71              
72             L<https://metacpan.org/release/DBIx-Class-Smooth>
73              
74             =head1 AUTHOR
75              
76             Erik Carlsson <info@code301.com>
77              
78             =head1 COPYRIGHT AND LICENSE
79              
80             This software is copyright (c) 2018 by Erik Carlsson.
81              
82             This is free software; you can redistribute it and/or modify it under
83             the same terms as the Perl 5 programming language system itself.
84              
85             =cut