MooseX...h::Tiny(3pm)
π MooseX::Types::Path::Tiny π
okay bestie, gather round, because this is the MooseX::Types::Path::Tiny manual page (that's the 3pm one, section 3 for perl modules, iykyk) and it is genuinely so useful. no cap. let's get into it β¨
β¨ VERSION β¨
version 0.012 β that's the one we're talking about, periodt.
πΈ SYNOPSIS πΈ
here's the whole vibe in code, bestie:
### specification of type constraint with coercion
package Foo;
use Moose;
use MooseX::Types::Path::Tiny qw/Path Paths AbsPath/;
has filename => (
is => 'ro',
isa => Path,
coerce => 1,
);
has directory => (
is => 'ro',
isa => AbsPath,
coerce => 1,
);
has filenames => (
is => 'ro',
isa => Paths,
coerce => 1,
);
### usage in code
Foo->new( filename => 'foo.txt' ); # coerced to Path::Tiny
Foo->new( directory => '.' ); # coerced to path('.')->absolute
Foo->new( filenames => [qw/bar.txt baz.txt/] ); # coerced to ArrayRef[Path::Tiny]
likeβ¦ the attribute declaration is one thing, and then you just use it and the coercion does its little magic behind the scenes. main character behaviour tbh π
π¦ DESCRIPTION π¦
so this module hands you Path::Tiny types for Moose. it's giving "types, but make them path-aware" π
it handles two really important flavours of coercion:
- coercing objects that have overloaded stringification (so anything that knows how to stringify itself can become a path)
- coercing things into absolute paths
and it can also check that files or directories actually exist, because sometimes you truly do need that π«Ά
π SUBTYPES π
this module uses MooseX::Types to define the following subtypes, and here they all are, no skips:
Path
Path makes sure an attribute is a Path::Tiny object. strings and objects with overloaded stringification are allowed to be coerced. slay β¨
AbsPath
AbsPath is a subtype of Path (the one right above, keep up bestie π), except it coerces to an absolute path.
File, AbsFile
these are literally just like Path and AbsPath, except they run -f to make sure the file actually exists on the filesystem. vibe check, but for files π
Dir, AbsDir
same deal as Path and AbsPath, except these check -d so the directory genuinely exists on the filesystem. bestie said "prove it" π§
Paths, AbsPaths
these are arrayrefs of Path and AbsPath, and yes they include coercions from arrayrefs of strings. so you can just yeet an arrayref of plain strings at them and they'll sort themselves out π
π CAVEATS π
listen, we need to talk. these are the parts where things get real.
Path vs File vs Dir
Path only guarantees you have a Path::Tiny object. that's it. it's not checking anything.
File and Dir do check the filesystem. so like⦠don't reach for them unless that is really and truly what you want, because they're going to hit the disk and they mean it.
Usage with File::Temp
β οΈ be careful if you pass in a File::Temp object. this one matters.
because the argument gets stringified during coercion into a Path::Tiny object, no reference to the original File::Temp argument is held. so you need to hold an external reference to it yourself, otherwise the temporary file or directory gets cleaned up immediately at the end of the enclosing scope. and then you're sad π
a better approach is to use Path::Tiny's own tempfile or tempdir constructors, because those hold the reference for you. iconic of them, honestly π
Foo->new( filename => Path::Tiny->tempfile );
β SEE ALSO β
go read these too, they're part of the lore:
- Path::Tiny
- Moose::Manual::Types
- Types::Path::Tiny
π«Ά SUPPORT π«Ά
got bugs? bestie, submit them through the RT bug tracker: https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Types-Path-Tiny (or email bug-MooseX-Types-Path-Tiny@rt.cpan.org). they'll take care of you π
there's also a mailing list for users of this distribution, right here: http://lists.perl.org/list/moose.html
and there's an irc channel for users of this distribution too: #moose on irc.perl.org (that's irc://irc.perl.org/#moose) π
oh and the author is also usually hanging around on irc as 'ether' at irc.perl.org π
π AUTHOR π
David Golden <dagolden@cpan.org>
π CONTRIBUTORS π
look at this lineup, absolute legends:
- Karen Etheridge
<ether@cpan.org> - Toby Inkster
<mail@tobyinkster.co.uk> - Demian Riccardi
<dde@ornl.gov> - Gregory Oschwald
<goschwald@maxmind.com>
π COPYRIGHT AND LICENCE π
this software is Copyright (c) 2013 by David Golden.
it's free software, licensed under:
The Apache License, Version 2.0, January 2004
and that's the whole page, bestie π
this was generated by perl v5.34.0, dated 2022-06-16, for the MooseX::Types::Path::Tiny page in section 3pm. go forth and coerce your paths, you absolute icon πβ¨π¦
π¦ where this page comes from
- debian bookworm: libmoosex-types-path-tiny-perl 0.012-2 Β· Apache-2.0
- debian trixie: libmoosex-types-path-tiny-perl 0.012-2 Β· Apache-2.0
- ubuntu noble: libmoosex-types-path-tiny-perl 0.012-2 Β· Apache-2.0
- ubuntu resolute: libmoosex-types-path-tiny-perl 0.012-2 Β· Apache-2.0
- ubuntu stonking: libmoosex-types-path-tiny-perl 0.012-2 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms