File Coverage

blib/lib/Config/Model/TypeConstraints.pm
Criterion Covered Total %
statement 8 8 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             #
2             # This file is part of Config-Model
3             #
4             # This software is Copyright (c) 2005-2022 by Dominique Dumont.
5             #
6             # This is free software, licensed under:
7             #
8             # The GNU Lesser General Public License, Version 2.1, February 1999
9             #
10             package Config::Model::TypeConstraints 2.153; # TRIAL
11              
12 59     59   471 use Mouse;
  59         144  
  59         448  
13 59     59   24416 use Mouse::Util::TypeConstraints;
  59         196  
  59         453  
14              
15             # used only for tests
16             my $__test_home = '';
17 14     14   50 sub _set_test_home { $__test_home = shift; }
18 4     4   16 sub _get_test_home { return $__test_home ; }
19              
20             subtype 'Config::Model::TypeContraints::Path' => as 'Maybe[Path::Tiny]' ;
21             coerce 'Config::Model::TypeContraints::Path' => from 'Str' => via sub {
22             if (defined $_ and /^~/) {
23             # because of tests, we can't rely on Path::Tiny's tilde processing
24             # TODO: should this be my_config ? May be once this is done:
25             # https://github.com/perl5-utils/File-HomeDir/pull/5/files
26             # beware of compat and migration issues
27             my $home = $__test_home || File::HomeDir->my_home;
28             s/^~/$home/;
29             }
30             return defined $_ ? Path::Tiny::path($_) : undef ;
31             } ;
32              
33             1;
34              
35             # ABSTRACT: Mouse type constraints for Config::Model
36              
37             __END__
38              
39             =pod
40              
41             =encoding UTF-8
42              
43             =head1 NAME
44              
45             Config::Model::TypeConstraints - Mouse type constraints for Config::Model
46              
47             =head1 VERSION
48              
49             version 2.153
50              
51             =head1 SYNOPSIS
52              
53             use Config::Model::TypeConstraints ;
54              
55             has 'some_dir' => (
56             is => 'ro',
57             isa => 'Config::Model::TypeContraints::Path',
58             coerce => 1
59             );
60              
61             =head1 DESCRIPTION
62              
63             This module provides type constraints used by Config::Model:
64              
65             =over
66              
67             =item *
68              
69             C<Config::Model::TypeContraints::Path>. A C<Maybe[Path::Tiny]>
70             type. This type can be coerced from C<Str> type if C<< coerce => 1 >>
71             is used to construct the attribute.
72              
73             =back
74              
75             =head1 SEE ALSO
76              
77             L<Config::Model>,
78             L<Mouse::Util::TypeConstraints>
79              
80             =head1 AUTHOR
81              
82             Dominique Dumont
83              
84             =head1 COPYRIGHT AND LICENSE
85              
86             This software is Copyright (c) 2005-2022 by Dominique Dumont.
87              
88             This is free software, licensed under:
89              
90             The GNU Lesser General Public License, Version 2.1, February 1999
91              
92             =cut