1 package MooseX::Types::Path::Class;
3 use warnings FATAL => 'all';
9 -declare => [qw( Dir File )];
11 use MooseX::Types::Moose qw(Str ArrayRef);
13 class_type('Path::Class::Dir');
14 class_type('Path::Class::File');
16 subtype Dir, as 'Path::Class::Dir';
17 subtype File, as 'Path::Class::File';
19 for my $type ( 'Path::Class::Dir', Dir ) {
21 from Str, via { Path::Class::Dir->new($_) },
22 from ArrayRef, via { Path::Class::Dir->new(@$_) };
25 for my $type ( 'Path::Class::File', File ) {
27 from Str, via { Path::Class::File->new($_) },
28 from ArrayRef, via { Path::Class::File->new(@$_) };
31 # optionally add Getopt option type
32 eval { require MooseX::Getopt; };
34 MooseX::Getopt::OptionTypeMap->add_option_type_to_map( $_, '=s', )
35 for ( 'Path::Class::Dir', 'Path::Class::File', Dir, File, );
44 MooseX::Types::Path::Class - A Path::Class type library for Moose
51 use MooseX::Types::Path::Class;
52 with 'MooseX::Getopt'; # optional
56 isa => 'Path::Class::Dir',
63 isa => 'Path::Class::File',
68 # these attributes are coerced to the
69 # appropriate Path::Class objects
70 MyClass->new( dir => '/some/directory/', file => '/some/file' );
75 MooseX::Types::Path::Class creates common L<Moose> types,
76 coercions and option specifications useful for dealing
77 with L<Path::Class> objects as L<Moose> attributes.
79 Coercions (see L<Moose::Util::TypeConstraints>) are made
80 from both 'Str' and 'ArrayRef' to both L<Path::Class::Dir> and
81 L<Path::Class::File> objects. If you have L<MooseX::Getopt> installed,
82 the Getopt option type ("=s") will be added for both
83 L<Path::Class::Dir> and L<Path::Class::File>.
88 None of these are exported by default. They are provided via
95 These exports can be used instead of the full class names. Example:
99 use MooseX::Types::Path::Class qw(Dir File);
115 Note that there are no quotes around Dir or File.
117 =item is_Dir($value), is_File($value)
119 Returns true or false based on whether $value is a valid Dir or File.
121 =item to_Dir($value), to_File($value)
123 Attempts to coerce $value to a Dir or File. Returns the coerced value
124 or false if the coercion failed.
131 L<MooseX::Types::Path::Class::MoreCoercions>, L<MooseX::FileAttribute>, L<MooseX::Types::URI>
136 L<Moose>, L<MooseX::Types>, L<Path::Class>
139 =head1 BUGS AND LIMITATIONS
141 If you find a bug please either email the author, or add
142 the bug to cpan-RT L<http://rt.cpan.org>.
147 Todd Hepler C<< <thepler@employees.org> >>
150 =head1 LICENCE AND COPYRIGHT
152 Copyright (c) 2007-2012, Todd Hepler C<< <thepler@employees.org> >>.
154 This module is free software; you can redistribute it and/or
155 modify it under the same terms as Perl itself. See L<perlartistic>.