Transfigure/HashKeys/SnakeCase.pm untested

filter: Statementstmt 0.0% 0 / 21 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 29 CC 1 SCAR 6.9
CC
1
Cov
0%
BUILDARGS
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Data::Transfigure::HashKeys::SnakeCase 1.03;
2 use v5.26;
3 use warnings;
4  
5 # ABSTRACT: converts hash keys to lower_snake_case
6  
7 =head1 NAME
8  
9 Data::Transfigure::HashKeys::SnakeCase - converts hash keys to
10 lower_snake_case
11  
12 =head1 DESCRIPTION
13  
14 C<Data::Transfigure::HashKeys::SnakeCase> is intended for cases where the
15 backend policies require C<snake_case> but the frontend (and API) policies
16 dictate C<camelCase>. As a post-process transfigurator, adding it rewrites all of
17 the structure's hash keys to the proper format in that scenario.
18  
19 =cut
20  
21 use Object::Pad;
22  
23 use Data::Transfigure::Tree;
24 class Data::Transfigure::HashKeys::SnakeCase : does(Data::Transfigure::Tree) {
25 use Data::Transfigure qw(hk_rewrite_cb);
26 use String::CamelSnakeKebab qw(lower_snake_case);
27  
28 =head1 FIELDS
29  
30 I<none>
31  
32 =cut
33  
34 sub BUILDARGS ($class) {
35 $class->SUPER::BUILDARGS(
36 handler => sub ($entity) {
37 return hk_rewrite_cb($entity, \&lower_snake_case);
38 }
39 );
40 }
41  
42 }
43  
44 =pod
45  
46 =head1 AUTHOR
47  
48 Mark Tyrrell C<< <mark@tyrrminal.dev> >>
49  
50 =head1 LICENSE
51  
52 Copyright (c) 2024 Mark Tyrrell
53  
54 Permission is hereby granted, free of charge, to any person obtaining a copy
55 of this software and associated documentation files (the "Software"), to deal
56 in the Software without restriction, including without limitation the rights
57 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
58 copies of the Software, and to permit persons to whom the Software is
59 furnished to do so, subject to the following conditions:
60  
61 The above copyright notice and this permission notice shall be included in all
62 copies or substantial portions of the Software.
63  
64 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
65 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
66 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
67 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
68 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
69 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
70 SOFTWARE.
71  
72 =cut
73  
74 1;
75  
76 __END__