MooseX...:Class(3pm)

πŸ“¦
version 0.09 Β· 7 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

MooseX::Types::Path::Class β€” a Path::Class type library for Moose πŸ’–

(also living its best life as MooseX...:Class(3pm) in the User Contributed Perl Documentation, iykyk)


🌸 VERSION 🌸

version 0.09 β€” yes bestie, that's the one


πŸ¦‹ SYNOPSIS πŸ¦‹

okay so here's the whole vibe, copy-paste ready:

package MyClass;
use Moose;
use MooseX::Types::Path::Class;
with 'MooseX::Getopt';  # optional

has 'dir' => (
    is       => 'ro',
    isa      => 'Path::Class::Dir',
    required => 1,
    coerce   => 1,
);

has 'file' => (
    is       => 'ro',
    isa      => 'Path::Class::File',
    required => 1,
    coerce   => 1,
);

# these attributes are coerced to the
# appropriate Path::Class objects
MyClass->new( dir => '/some/directory/', file => '/some/file' );

like… you hand it a plain string and it hands you back a whole Path::Class object. the glow-up is real πŸ˜­πŸ’…


πŸŽ€ DESCRIPTION πŸŽ€

MooseX::Types::Path::Class creates common Moose types, coercions and option specifications that are, lowkey, extremely useful for dealing with Path::Class objects as Moose attributes. it's giving "I made your life easier and I didn't even ask for credit" πŸ’œ

So. The coercions (peep Moose::Util::TypeConstraints if you wanna know the mechanics) go from Str and from ArrayRef β†’ both Path::Class::Dir and Path::Class::File objects. Two directions in, two types out, we love a flexible queen πŸ‘‘

And β€” bonus round β€” if you have MooseX::Getopt installed, the Getopt option type (=s) gets added for both Path::Class::Dir and Path::Class::File. So your command line just… understands. iconic, no notes. ✨


πŸ’… EXPORTS πŸ’…

first things first: none of these are exported by default. they come to you via MooseX::Types. so don't be surprised when you don't get them for free, bestie πŸ™ˆ

  • Dir, File β€” these exports can be used instead of the full class names. example:
package MyClass;
use Moose;
use MooseX::Types::Path::Class qw(Dir File);

has 'dir' => (
    is       => 'ro',
    isa      => Dir,
    required => 1,
    coerce   => 1,
);

has 'file' => (
    is       => 'ro',
    isa      => File,
    required => 1,
    coerce   => 1,
);
🚨 bestie listen to me: there are no quotes around Dir or File. it's a bareword situation. do not quote them. I'm begging 🫢
  • is_Dir($value), is_File($value) β€” returns true or false depending on whether $value is a valid Dir or File. a little vibe check, if you will ⭐
  • to_Dir($value), to_File($value) β€” attempts to coerce $value to a Dir or a File. gives you the coerced value back, or false if the coercion failed. no drama, just a falsy result πŸ’€

🌈 SEE ALSO 🌈

go read these next, they're the friend group:

  • MooseX::Types::Path::Class::MoreCoercions
  • MooseX::FileAttribute
  • MooseX::Types::URI

🧚 DEPENDENCIES 🧚

the squad you need on deck: Moose, MooseX::Types, Path::Class.


πŸ“ SUPPORT πŸ“

Got bugs? Same. πŸ› Send them through the RT bug tracker at <https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Types-Path-Class> β€” or, if email is your thing, bug-MooseX-Types-Path-Class@rt.cpan.org.

There's also a mailing list for users of this distribution, hanging out at <http://lists.perl.org/list/moose.html>. come vibe with us πŸ’Œ

And there's an irc channel too, for users of this distribution, at #moose on irc.perl.org β€” that's <irc://irc.perl.org/#moose>. real ones know. πŸ‘‘


πŸ‘‘ AUTHOR πŸ‘‘

Todd Hepler <thepler@employees.org> β€” the original main character πŸ’–


✨ CONTRIBUTORS ✨

  • Karen Etheridge <ether@cpan.org>
  • Jonathan Rockway <jon@jrock.us>
  • Yuval Kogman <nothingmuch@woobling.org>

the way they all pulled up and made this better… we stan 🫢


This software is copyright (c) 2007 by Todd Hepler.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. so like, go forth and remix, responsibly 🌸


okay that's the whole page bestie, you're so welcome πŸ’œ β€” this was perl v5.34.0, dated 2022-06-30, MooseX...:Class(3pm), and I hope your paths are always coerced and your types always valid. mwah πŸ˜­πŸŽ€

πŸ“¦ where this page comes from