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