| 1 | package Data::Transfigure::HashKeys::CapitalizedIDSuffix 1.03; | ||
| 2 | use v5.26; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | # ABSTRACT: a post-process transfigurator that rewrites hash keys to replace /Id$/ with ID | ||
| 6 | |||
| 7 | =head1 NAME | ||
| 8 | |||
| 9 | Data::Transfigure::HashKeys::CapitalizedIDSuffix - a post-process | ||
| 10 | transfigurator that rewrites hash keys to replace /Id$/ with ID | ||
| 11 | |||
| 12 | =head1 DESCRIPTION | ||
| 13 | |||
| 14 | C<Data::Transfigure::HashKeys::CapitalizedIDSuffix> addresses a side | ||
| 15 | effect of camelCasing keys, which is that keys like C<user_id> are transfigured | ||
| 16 | into C<userId> when you might prefer them to be C<userID> | ||
| 17 | |||
| 18 | =cut | ||
| 19 | |||
| 20 | use Object::Pad; | ||
| 21 | |||
| 22 | use Data::Transfigure::Tree; | ||
| 23 | class Data::Transfigure::HashKeys::CapitalizedIDSuffix : does(Data::Transfigure::Tree) { | ||
| 24 | use Data::Transfigure qw(hk_rewrite_cb); | ||
| 25 | |||
| 26 | =head1 FIELDS | ||
| 27 | |||
| 28 | I<none> | ||
| 29 | |||
| 30 | =cut | ||
| 31 | |||
| 32 | sub BUILDARGS ($class) { | ||
| 33 | $class->SUPER::BUILDARGS( | ||
| 34 | handler => sub ($entity) { | ||
| 35 | return hk_rewrite_cb($entity, sub ($k) {$k =~ s/Id$/ID/r}); | ||
| 36 | } | ||
| 37 | ); | ||
| 38 | } | ||
| 39 | |||
| 40 | } | ||
| 41 | |||
| 42 | =pod | ||
| 43 | |||
| 44 | =head1 AUTHOR | ||
| 45 | |||
| 46 | Mark Tyrrell C<< <mark@tyrrminal.dev> >> | ||
| 47 | |||
| 48 | =head1 LICENSE | ||
| 49 | |||
| 50 | Copyright (c) 2024 Mark Tyrrell | ||
| 51 | |||
| 52 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 53 | of this software and associated documentation files (the "Software"), to deal | ||
| 54 | in the Software without restriction, including without limitation the rights | ||
| 55 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 56 | copies of the Software, and to permit persons to whom the Software is | ||
| 57 | furnished to do so, subject to the following conditions: | ||
| 58 | |||
| 59 | The above copyright notice and this permission notice shall be included in all | ||
| 60 | copies or substantial portions of the Software. | ||
| 61 | |||
| 62 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 63 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 64 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 65 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 66 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 67 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| 68 | SOFTWARE. | ||
| 69 | |||
| 70 | =cut | ||
| 71 | |||
| 72 | 1; | ||
| 73 | |||
| 74 | __END__ |