1Types::Path::Tiny(3)  User Contributed Perl Documentation Types::Path::Tiny(3)
2
3
4

NAME

6       Types::Path::Tiny - Path::Tiny types and coercions for Moose and Moo
7

VERSION

9       version 0.006
10

SYNOPSIS

12       Example with Moose:
13
14         ### specification of type constraint with coercion
15
16         package Foo;
17
18         use Moose;
19         use Types::Path::Tiny qw/Path AbsPath/;
20
21         has filename => (
22           is => 'ro',
23           isa => Path,
24           coerce => 1,
25         );
26
27         has directory => (
28           is => 'ro',
29           isa => AbsPath,
30           coerce => 1,
31         );
32
33         ### usage in code
34
35         Foo->new( filename => 'foo.txt' ); # coerced to Path::Tiny
36         Foo->new( directory => '.' ); # coerced to path('.')->absolute
37
38       Example with Moo:
39
40           ### specification of type constraint with coercion
41
42           package Foo;
43
44           use Moo;
45           use Types::Path::Tiny qw/Path AbsPath/;
46
47           has 'directory' => (
48               is       => 'rw',
49               isa      => AbsPath,
50               required => 1,
51               coerce   => AbsPath->coercion,
52           );
53
54           ### usage in code
55
56           Foo->new( directory => '.' ); # coerced to path('.')->absolute
57

DESCRIPTION

59       This module provides Path::Tiny types for Moose, Moo, etc.
60
61       It handles two important types of coercion:
62
63       ·   coercing objects with overloaded stringification
64
65       ·   coercing to absolute paths
66
67       It also can check to ensure that files or directories exist.
68

SUBTYPES

70       This module uses Type::Tiny to define the following subtypes.
71
72   Path
73       "Path" ensures an attribute is a Path::Tiny object.  Strings and
74       objects with overloaded stringification may be coerced.
75
76   AbsPath
77       "AbsPath" is a subtype of "Path" (above), but coerces to an absolute
78       path.
79
80   File, AbsFile
81       These are just like "Path" and "AbsPath", except they check "-f" to
82       ensure the file actually exists on the filesystem.
83
84   Dir, AbsDir
85       These are just like "Path" and "AbsPath", except they check "-d" to
86       ensure the directory actually exists on the filesystem.
87

CAVEATS

89   Path vs File vs Dir
90       "Path" just ensures you have a Path::Tiny object.
91
92       "File" and "Dir" check the filesystem.  Don't use them unless that's
93       really what you want.
94
95   Usage with File::Temp
96       Be careful if you pass in a File::Temp object. Because the argument is
97       stringified during coercion into a Path::Tiny object, no reference to
98       the original File::Temp argument is held.  Be sure to hold an external
99       reference to it to avoid immediate cleanup of the temporary file or
100       directory at the end of the enclosing scope.
101
102       A better approach is to use Path::Tiny's own "tempfile" or "tempdir"
103       constructors, which hold the reference for you.
104
105           Foo->new( filename => Path::Tiny->tempfile );
106

SEE ALSO

108       ·   Path::Tiny
109
110       ·   Moose::Manual::Types
111

SUPPORT

113   Bugs / Feature Requests
114       Please report any bugs or feature requests through the issue tracker at
115       <https://github.com/dagolden/types-path-tiny/issues>.  You will be
116       notified automatically of any progress on your issue.
117
118   Source Code
119       This is open source software.  The code repository is available for
120       public review and contribution under the terms of the license.
121
122       <https://github.com/dagolden/types-path-tiny>
123
124         git clone https://github.com/dagolden/types-path-tiny.git
125

AUTHOR

127       David Golden <dagolden@cpan.org>
128

CONTRIBUTORS

130       ·   Hobbestigrou <hobbestigrou@erakis.eu>
131
132       ·   Hobbestigrou <natal.ngetal@novapost.fr>
133
134       ·   Toby Inkster <tobyink@cpan.org>
135
137       This software is Copyright (c) 2013 by David Golden.
138
139       This is free software, licensed under:
140
141         The Apache License, Version 2.0, January 2004
142
143
144
145perl v5.32.0                      2020-07-28              Types::Path::Tiny(3)
Impressum