« Sah/Schema/dirname/default_curdir_abs.pm
↑ Summary
Sah/Schema/dirname/default_only_subdir_not_file_in_curdir.pm »
| 1 | package Sah::Schema::dirname::default_only_subdir_in_curdir; | ||
| 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-02-16'; # DATE | |
| 7 | 1 | our $DIST = 'Sah-SchemaBundle-Path'; # DIST | |
| 8 | 1 | our $VERSION = '0.031'; # VERSION | |
| 9 | |||
| 10 | 1 | our $schema = ["dirname" => { | |
| 11 | summary => 'Directory name, defaults to only subdirectory in current directory (if there is one)', | ||
| 12 | description => <<'MARKDOWN', | ||
| 13 | |||
| 14 | This is like the `dirname` schema but with a default value of "only subdirectory | ||
| 15 | in the current directory". That is, if the current directory has a single | ||
| 16 | subdirectory and nothing else. | ||
| 17 | |||
| 18 | Difference with `dirname::default_only_subdir_not_file_in_subdir` schema: the | ||
| 19 | other schema ignores plain files. Thus, if a directory only contains `file1` and | ||
| 20 | `subdir1`, then that other schema will return `subdir1` but this schema will not | ||
| 21 | return a default value. | ||
| 22 | |||
| 23 | Note: be careful when using this schema for actions that are destructive, | ||
| 24 | because a user can perform those actions without giving an argument (e.g. in a | ||
| 25 | `delete-files-in` script). It is safer to use this schema when performing a | ||
| 26 | non-destructive action (e.g. `ls`) and/or operate in dry-run mode by default. | ||
| 27 | |||
| 28 | MARKDOWN | ||
| 29 | 'x.perl.default_value_rules' => ['Path::only_subdir_in_curdir'], | ||
| 30 | }]; | ||
| 31 | |||
| 32 | 1 | 1; | |
| 33 | # ABSTRACT: Directory name, defaults to only subdirectory in current directory (if there is one) | ||
| 34 | |||
| 35 | __END__ | ||