| 1 | package Sah::Schema::unix::username; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | |||
| 5 | 1 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |
| 6 | 1 | our $DATE = '2024-11-15'; # DATE | |
| 7 | 1 | our $DIST = 'Sah-SchemaBundle-Unix'; # DIST | |
| 8 | 1 | our $VERSION = '0.022'; # VERSION | |
| 9 | |||
| 10 | 1 | our $schema = [str => { | |
| 11 | summary => 'Unix account name', | ||
| 12 | description => <<'MARKDOWN', | ||
| 13 | |||
| 14 | The checking follows POSIX rules: does not begin with a hyphen and only contains | ||
| 15 | [A-Za-z0-9._-]. | ||
| 16 | |||
| 17 | The above rule allows integers like 1234, which can be confused with UID, so | ||
| 18 | this schema disallows pure integers. | ||
| 19 | |||
| 20 | The maximum length is 32 following libc6's limit. | ||
| 21 | |||
| 22 | Note that this schema does not check whether the user name exists (has record in | ||
| 23 | the user database e.g. `/etc/group`). To do that, use the | ||
| 24 | `unix::username::exists` schema. | ||
| 25 | |||
| 26 | MARKDOWN | ||
| 27 | 'prefilters' => ['Unix::convert_uid_to_unix_user'], | ||
| 28 | 'x.completion' => ['unix_user_or_uid'], | ||
| 29 | |||
| 30 | min_len => 1, | ||
| 31 | max_len => 32, | ||
| 32 | match => qr/(?=\A[A-Za-z0-9._][A-Za-z0-9._-]{0,31}\z)(?=.*[A-Za-z._-])/, | ||
| 33 | |||
| 34 | examples => [ | ||
| 35 | {value=>'', valid=>0}, | ||
| 36 | {value=>'foo', valid=>1}, | ||
| 37 | {value=>'-andy', valid=>0}, | ||
| 38 | {value=>'1234', valid=>0}, | ||
| 39 | {value=>'andy2', valid=>1}, | ||
| 40 | {value=>'an dy', valid=>0}, | ||
| 41 | {value=>'an.dy', valid=>1}, | ||
| 42 | {value=>'a' x 33, valid=>0, summary=>'Too long'}, | ||
| 43 | ], | ||
| 44 | |||
| 45 | }]; | ||
| 46 | |||
| 47 | 1 | 1; | |
| 48 | # ABSTRACT: Unix account name | ||
| 49 | |||
| 50 | __END__ | ||