1 package MooseX::Types::Path::Class;
3 use warnings FATAL => 'all';
12 -declare => [qw( Dir File )];
14 use MooseX::Types::Moose qw(Object Str ArrayRef);
17 as Object, where { $_->isa('Path::Class::Dir') };
20 from Str, via { Path::Class::Dir->new($_) },
21 from ArrayRef, via { Path::Class::Dir->new(@$_) };
23 MooseX::Getopt::OptionTypeMap->add_option_type_to_map(
28 subtype 'Path::Class::Dir',
29 as Object, where { $_->isa('Path::Class::Dir') };
31 coerce 'Path::Class::Dir',
32 from Str, via { Path::Class::Dir->new($_) },
33 from ArrayRef, via { Path::Class::Dir->new(@$_) };
35 MooseX::Getopt::OptionTypeMap->add_option_type_to_map(
36 'Path::Class::Dir', '=s',
41 as Object, where { $_->isa('Path::Class::File') };
44 from Str, via { Path::Class::File->new($_) },
45 from ArrayRef, via { Path::Class::File->new(@$_) };
47 MooseX::Getopt::OptionTypeMap->add_option_type_to_map(
52 subtype 'Path::Class::File',
53 as Object, where { $_->isa('Path::Class::File') };
55 coerce 'Path::Class::File',
56 from Str, via { Path::Class::File->new($_) },
57 from ArrayRef, via { Path::Class::File->new(@$_) };
59 MooseX::Getopt::OptionTypeMap->add_option_type_to_map(
60 'Path::Class::File', '=s',
69 MooseX::Types::Path::Class - A Path::Class type library for Moose
76 use MooseX::Types::Path::Class qw( Dir File );
77 with 'MooseX::Getopt'; # if you want the Getopt Role
93 # these attributes are coerced to the
94 # appropriate Path::Class objects
95 MyClass->new( dir => '/some/directory/', file => '/some/file' );
100 This is a utility that creates common L<Moose> subtypes, coercions and
101 option specifications useful for dealing with L<Path::Class> objects
102 as L<Moose> attributes.
104 This module constructs coercions (see L<Moose::Util::TypeConstraints>)
105 from both 'Str' and 'ArrayRef' to both L<Path::Class::Dir> and
106 L<Path::Class::File> objects. It also adds the Getopt option type
107 ("=s") for both L<Path::Class::Dir> and L<Path::Class::File>
108 (see L<MooseX::Getopt>).
110 This is just meant to be a central place for these constructs, so you
111 don't have to worry about whether they've been created or not, and you're
112 not tempted to copy them into yet another class (like I was).
116 See L<MooseX::Types> for how these exports work.
120 =item Dir is_Dir to_Dir
122 =item File is_File to_File
129 L<Moose>, L<MooseX::Types>, L<MooseX::Getopt>, L<Path::Class>
132 =head1 BUGS AND LIMITATIONS
134 No bugs have been reported.
139 Todd Hepler C<< <thepler@employees.org> >>
142 =head1 LICENCE AND COPYRIGHT
144 Copyright (c) 2007, Todd Hepler C<< <thepler@employees.org> >>. All rights reserved.
146 This module is free software; you can redistribute it and/or
147 modify it under the same terms as Perl itself. See L<perlartistic>.