| 1 | # ABSTRACT: Member names validation utility | ||||||||||
| 2 | package PONAPI::Utils::Names; | ||||||||||
| 3 | |||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 4 | ▶ | use parent qw< Exporter >; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 4 | our @EXPORT_OK = qw< check_name >; | |||||||||
| 9 | |||||||||||
| 10 | 4 | my $qr_edge = qr/[a-zA-Z0-9\P{ASCII}]/; | |||||||||
| 11 | 4 | my $qr_mid = qr/[a-zA-Z0-9\P{ASCII}_\ -]/; | |||||||||
| 12 | |||||||||||
| 13 | sub check_name { | ||||||||||
| 14 | 21 | ▶ | my $name = shift; | ||||||||
|
Subroutine
check_name: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||
| 15 | |||||||||||
| 16 | 21 | ▶ | return if ref($name); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 20 | ▶ | return if length($name) == 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | |||||||||||
| 19 | 19 | ▶ | return $name =~ /\A $qr_edge \z/x if length($name) == 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 18 | ▶ | return $name =~ /\A $qr_edge $qr_edge \z/x if length($name) == 2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 17 | return $name =~ /\A $qr_edge $qr_mid+ $qr_edge \z/x; | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 4 | 1; | |||||||||
| 25 | |||||||||||
| 26 | __END__ | ||||||||||
| 27 | |||||||||||
| 28 | =pod | ||||||||||
| 29 | |||||||||||
| 30 | =encoding UTF-8 | ||||||||||
| 31 | |||||||||||
| 32 | =head1 NAME | ||||||||||
| 33 | |||||||||||
| 34 | PONAPI::Utils::Names - Member names validation utility | ||||||||||
| 35 | |||||||||||
| 36 | =head1 VERSION | ||||||||||
| 37 | |||||||||||
| 38 | version 0.002012 | ||||||||||
| 39 | |||||||||||
| 40 | =head1 SYNOPSIS | ||||||||||
| 41 | |||||||||||
| 42 | use PONAPI::Utils::Names 'check_name'; | ||||||||||
| 43 | |||||||||||
| 44 | check_name('a'); # Valid | ||||||||||
| 45 | check_name('a-'); # Invalid | ||||||||||
| 46 | check_name('-a'); # Invalid | ||||||||||
| 47 | check_name('a-b'); # Valid | ||||||||||
| 48 | check_name('a b'); # Valid | ||||||||||
| 49 | |||||||||||
| 50 | =head1 DESCRIPTION | ||||||||||
| 51 | |||||||||||
| 52 | This module implements the L<member name restrictions|http://jsonapi.org/format/#document-member-names> | ||||||||||
| 53 | from the {json:api} specification; it can be used by repositories | ||||||||||
| 54 | to implement strict member names, if desired. | ||||||||||
| 55 | |||||||||||
| 56 | =head1 AUTHORS | ||||||||||
| 57 | |||||||||||
| 58 | =over 4 | ||||||||||
| 59 | |||||||||||
| 60 | =item * | ||||||||||
| 61 | |||||||||||
| 62 | Mickey Nasriachi <mickey@cpan.org> | ||||||||||
| 63 | |||||||||||
| 64 | =item * | ||||||||||
| 65 | |||||||||||
| 66 | Stevan Little <stevan@cpan.org> | ||||||||||
| 67 | |||||||||||
| 68 | =item * | ||||||||||
| 69 | |||||||||||
| 70 | Brian Fraser <hugmeir@cpan.org> | ||||||||||
| 71 | |||||||||||
| 72 | =back | ||||||||||
| 73 | |||||||||||
| 74 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 75 | |||||||||||
| 76 | This software is copyright (c) 2016 by Mickey Nasriachi, Stevan Little, Brian Fraser. | ||||||||||
| 77 | |||||||||||
| 78 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 79 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 80 | |||||||||||
| 81 | =cut | ||||||||||