File Coverage

blib/lib/Sort/Sub/sah_schema_clause.pm
Criterion Covered Total %
statement 8 18 44.4
branch 0 2 0.0
condition n/a
subroutine 3 8 37.5
pod 0 2 0.0
total 11 30 36.6


line stmt bran cond sub pod time code
1             package Sort::Sub::sah_schema_clause;
2              
3 1     1   394189 use 5.010001;
  1         5  
4 1     1   7 use strict;
  1         2  
  1         34  
5 1     1   6 use warnings;
  1         2  
  1         3512  
6              
7             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8             our $DATE = '2024-01-12'; # DATE
9             our $DIST = 'Sort-SubBundle-Sah'; # DIST
10             our $VERSION = '0.001'; # VERSION
11              
12             sub meta {
13             return {
14 0     0 0   v => 1,
15             summary => 'Sort Sah schema clause (and attributes)',
16             };
17             }
18              
19             sub gen_sorter {
20 0     0 0   require Sort::BySpec;
21              
22 0           my ($is_reverse, $is_ci) = @_;
23              
24             Sort::BySpec::cmp_by_spec(
25             spec => [
26             # from defhash
27             'v',
28              
29             # from defhash
30             'defhash_v',
31              
32             'schema_v',
33              
34             'base_v',
35              
36             # from defhash
37             'default_lang',
38              
39             # from defhash
40             'name',
41             qr/\Aname\./,
42              
43             # from defhash
44             'caption',
45             qr/\Acaption\./,
46              
47             # from defhash
48             'summary',
49             qr/\Asummary\./,
50              
51             # from defhash
52             'description',
53             qr/\Adescription\./,
54              
55             # from defhash
56             'tags',
57              
58             'c',
59 0     0     qr/\Ac\./ => sub { $_[0] cmp $_[1] },
60              
61              
62              
63             ## begin normal priority clauses
64              
65             # base type
66             qr/\A(!)?ok([&|=])?\z/,
67             qr/\A(!)?default([&|=])?\z/,
68             qr/\A(!)?req([&|=])?\z/,
69             qr/\A(!)?forbidden([&|=])?\z/,
70             qr/\A(!)?prefilters([&|=])?\z/,
71             qr/\A(!)?clause([&|=])?\z/,
72             qr/\A(!)?clset([&|=])?\z/,
73             qr/\A(!)?check([&|=])?\z/,
74             qr/\A(!)?prop([&|=])?\z/,
75             qr/\A(!)?check_prop([&|=])?\z/,
76             qr/\A(!)?if([&|=])?\z/,
77              
78             # comparable
79             qr/\A(!)?in([&|=])?\z/,
80             qr/\A(!)?is([&|=])?\z/,
81              
82             # haselems
83             qr/\A(!)?max_len([&|=])?\z/,
84             qr/\A(!)?min_len([&|=])?\z/,
85             qr/\A(!)?len_between([&|=])?\z/,
86             qr/\A(!)?len([&|=])?\z/,
87             qr/\A(!)?has([&|=])?\z/,
88             qr/\A(!)?uniq([&|=])?\z/,
89             qr/\A(!)?each_elem([&|=])?\z/,
90             qr/\A(!)?check_each_elem([&|=])?\z/,
91             qr/\A(!)?each_index([&|=])?\z/,
92             qr/\A(!)?check_eaach_index([&|=])?\z/,
93             qr/\A(!)?exists([&|=])?\z/,
94             qr/\A(!)?check_exists([&|=])?\z/,
95              
96             # sortable
97             qr/\A(!)?min([&|=])?\z/,
98             qr/\A(!)?xmin([&|=])?\z/,
99             qr/\A(!)?max([&|=])?\z/,
100             qr/\A(!)?xmax([&|=])?\z/,
101             qr/\A(!)?between([&|=])?\z/,
102             qr/\A(!)?xbetween([&|=])?\z/,
103              
104             # float
105             qr/\A(!)?is_nan([&|=])?\z/,
106             qr/\A(!)?is_inf([&|=])?\z/,
107             qr/\A(!)?is_pos_inf_len([&|=])?\z/,
108             qr/\A(!)?is_neg_inf([&|=])?\z/,
109              
110             # int
111             qr/\A(!)?mod([&|=])?\z/,
112             qr/\A(!)?div_by([&|=])?\z/,
113              
114             # str
115             qr/\A(!)?encoding([&|=])?\z/,
116             qr/\A(!)?match([&|=])?\z/,
117             qr/\A(!)?is_re([&|=])?\z/,
118              
119             # bool
120             qr/\A(!)?is_true([&|=])?\z/,
121              
122             # array
123             qr/\A(!)?elems([&|=])?\z/,
124             qr/\A(!)?of([&|=])?\z/, # as well as for 'any', 'all' types
125              
126             # hash
127             qr/\A(!)?keys([&|=])?\z/,
128             qr/\A(!)?re_keys([&|=])?\z/,
129             qr/\A(!)?req_keys([&|=])?\z/,
130             qr/\A(!)?allowed_keys([&|=])?\z/,
131             qr/\A(!)?allowed_keys_re([&|=])?\z/,
132             qr/\A(!)?forbidden_keys([&|=])?\z/,
133             qr/\A(!)?forbidden_keys_re([&|=])?\z/,
134             qr/\A(!)?each_key([&|=])?\z/,
135             qr/\A(!)?each_value([&|=])?\z/,
136             qr/\A(!)?check_each_key([&|=])?\z/,
137             qr/\A(!)?check_each_value([&|=])?\z/,
138             qr/\A(!)?choose_one_key([&|=])?\z/,
139             qr/\A(!)?choose_one([&|=])?\z/,
140             qr/\A(!)?choose_all_keys([&|=])?\z/,
141             qr/\A(!)?choose_all([&|=])?\z/,
142             qr/\A(!)?choose_some_keys([&|=])?\z/,
143             qr/\A(!)?choose_some([&|=])?\z/,
144             qr/\A(!)?req_one_key([&|=])?\z/,
145             qr/\A(!)?req_one([&|=])?\z/,
146             qr/\A(!)?req_all_keys([&|=])?\z/,
147             qr/\A(!)?req_all([&|=])?\z/,
148             qr/\A(!)?req_some_keys([&|=])?\z/,
149             qr/\A(!)?req_some([&|=])?\z/,
150             qr/\A(!)?dep_any([&|=])?\z/,
151             qr/\A(!)?dep_all([&|=])?\z/,
152             qr/\A(!)?req_dep_any([&|=])?\z/,
153             qr/\A(!)?req_dep_all([&|=])?\z/,
154              
155             # obj
156             qr/\A(!)?can([&|=])?\z/,
157             qr/\A(!)?isa([&|=])?\z/,
158              
159             # end normal priority clauses
160              
161              
162              
163             ### begin low priority clauses
164              
165             # base type
166             qr/\A(!)?postfilters([&|=])?\z/,
167             qr/\A(!)?examples([&|=])?\z/,
168             qr/\A(!)?invalid_examples([&|=])?\z/,
169              
170             ### end low priority clauses
171              
172             'x',
173 0     0     qr/\Ax\./ => sub { $_[0] cmp $_[1] },
174              
175             #
176             qr// => sub {
177 0     0     my ($normalized_a, $normalized_b) = @_;
178 0           for ($normalized_a, $normalized_b) {
179 0           s/\A!|[&|=]\z//;
180             }
181 0 0         $normalized_a cmp $normalized_b || $_[0] cmp $_[1];
182             },
183 0           ],
184             reverse => $is_reverse,
185             );
186             }
187              
188             1;
189             # ABSTRACT: Sort Sah schema clause (and attributes)
190              
191             __END__