blib/lib/DBIx/Class/Helper/ResultSet/EnumMethods.pm

filter: Statementstmt 41.9% 13 / 31 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 57.1% 4 / 7 Podpod 0.0% 0 / 1 totaltotal 36.9% 17 / 46 CC 5 SCAR 26.6
CC
5
Cov
36%
make_variant
30.0
__ANON__
2.0
__ANON__
2.0
CRAP 14.4
↑ Summary
1 package DBIx::Class::Helper::ResultSet::EnumMethods;
2  
3 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 DBIx::Class::Helper::ResultSet::EnumMethods - Automatically create search methods for enum columns.
10  
11 =head1 VERSION
12  
13 Version 0.02
14  
15 =cut
16  
17 1 our $VERSION = '0.02';
18  
19 # Le 'install' => 1 est pour Subroutines::ProhibitCallsToUndeclaredSubs.
20 1 ▶use Package::Variant 'install' => 1, 'importing' => ['Moo::Role'];
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 0 ▶sub make_variant {
Subroutine make_variant: not called CC=5 SCAR=34.0
Pod undocumented
23 0 my ($class, $target_package, $resultset) = @_;
24  
25 0 my $result = $resultset;
26 0 $result =~ s/::ResultSet::/::Result::/oms;
27  
28 0 my $columns_info = $result->result_source_instance->columns_info;
29  
30 0 for my $method (keys %{$columns_info}) {
31 0 my $detail = $columns_info->{$method};
32  
33 0 ▶ if ('enum' ne $detail->{'data_type'} && $detail->{'extra'}{'list'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ("enum" ne $detail->{"data_type"} and $detail->{"extra"}{"list"}) 0 0 0
Condition0%0/3
"enum" ne $detail->{"data_type"} and $detail->{"extra"}{"list"}
!ll&&!rl&&r
000
MC/DC0%0/2
"enum" ne $detail->{"data_type"} and $detail->{"extra"}{"list"}
"enum" ne $detail->{"data_type"} $detail->{"extra"}{"list"}
Truth table0%0/3
A and B
A= "enum" ne $detail->{"data_type"}B= $detail->{"extra"}{"list"}
ABresult
0X0
100
111
34 0 next;
35 }
36  
37 0 for my $v (@{ $detail->{'extra'}{'list'} }) {
38  
39 0 ▶ install "${method}_${v}" => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
40 0 my $self = shift;
41  
42 0 return $self->search(
43 {
44 $self->me($method) => $v
45 }
46 );
47 0 };
48  
49 0 ▶ install "${method}_not_${v}" => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 0 my $self = shift;
51  
52 0 return $self->search(
53 {
54 $self->me($method) => {
55 q{!=} => $v,
56 }
57 }
58 );
59 0 };
60 }
61 }
62  
63 0 return;
64 }
65  
66 =head1 SYNOPSIS
67  
68 This module automatically creates search method helpers for enum columns.
69  
70 In your ResultSet class, add:
71  
72 use Role::Tiny::With qw(with);
73 use DBIx::Class::Helper::ResultSet::EnumMethods;
74  
75 with(EnumMethods(__PACKAGE__));
76  
77 =head1 METHODS
78  
79 Say your table has an enum column "payment_type", and the possible values for
80 the enum are "cash", "check", and "card", using this role will act as if you
81 added these methods:
82  
83 sub payment_type_cash {
84 return shift->search( {
85 $self->me('payment_type') => 'cash'
86 });
87 };
88
89 sub payment_type_not_cash {
90 return shift->search( {
91 $self->me('payment_type') => {
92 q{!=} => 'cash',
93 }
94 });
95 };
96
97 sub payment_type_check {
98 return shift->search( {
99 $self->me('payment_type') => 'check'
100 });
101 };
102
103 sub payment_type_not_check {
104 return shift->search( {
105 $self->me('payment_type') => {
106 q{!=} => 'check',
107 }
108 });
109 };
110
111 sub payment_type_card {
112 return shift->search( {
113 $self->me('payment_type') => 'card'
114 });
115 };
116
117 sub payment_type_not_card {
118 return shift->search( {
119 $self->me('payment_type') => {
120 q{!=} => 'card',
121 }
122 });
123 };
124  
125 =head1 AUTHOR
126  
127 Mathieu Arnold, C<< <mat at cpan.org> >>
128  
129 =head1 BUGS
130  
131 Please report any bugs or feature requests to C<bug-dbix-class-helper-resultset-enummethods at rt.cpan.org>, or through
132 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBIx-Class-Helper-ResultSet-EnumMethods>. I will be notified, and then you'll
133 automatically be notified of progress on your bug as I make changes.
134  
135  
136  
137  
138 =head1 SUPPORT
139  
140 You can find documentation for this module with the perldoc command.
141  
142 perldoc DBIx::Class::Helper::ResultSet::EnumMethods
143  
144  
145 You can also look for information at:
146  
147 =over 4
148  
149 =item * RT: CPAN's request tracker (report bugs here)
150  
151 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=DBIx-Class-Helper-ResultSet-EnumMethods>
152  
153 =item * CPAN Ratings
154  
155 L<https://cpanratings.perl.org/d/DBIx-Class-Helper-ResultSet-EnumMethods>
156  
157 =item * Search CPAN
158  
159 L<https://metacpan.org/release/DBIx-Class-Helper-ResultSet-EnumMethods>
160  
161 =back
162  
163  
164 =head1 ACKNOWLEDGEMENTS
165  
166 People on #dbix-class for the original idea.
167  
168 =head1 LICENSE AND COPYRIGHT
169  
170 This software is Copyright (c) 2019 by Mathieu Arnold.
171  
172 This is free software, licensed under:
173  
174 The Artistic License 2.0 (GPL Compatible)
175  
176  
177 =cut
178  
179 1 1;
↑ Summary