PONAPI/Utils/Names.pm

filter: Statementstmt 100% 19 / 19 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 96.8% 31 / 32 CC 5 SCAR 12.5
CC
5
Cov
100%
check_name
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.5
« PONAPI/Builder.pm ↑ Summary PONAPI/DAO/Request/Role/UpdateLike.pm »
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
BranchTrueFalseTotal
if ref $name 1 20 21
17 20 ▶ return if length($name) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if length $name == 0 1 19 20
18  
19 19 ▶ return $name =~ /\A $qr_edge \z/x if length($name) == 1;
Branch: 1 branch
BranchTrueFalseTotal
if length $name == 1 1 18 19
20 18 ▶ return $name =~ /\A $qr_edge $qr_edge \z/x if length($name) == 2;
Branch: 1 branch
BranchTrueFalseTotal
if length $name == 2 1 17 18
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
« PONAPI/Builder.pm ↑ Summary PONAPI/DAO/Request/Role/UpdateLike.pm »