pod update
[gitmo/MooseX-Types-Path-Class.git] / lib / MooseX / Types / Path / Class.pm
CommitLineData
fd56ddb6 1package MooseX::Types::Path::Class;
2
3use warnings FATAL => 'all';
4use strict;
5
6our $VERSION = '0.01';
7
8use MooseX::Getopt;
9use Path::Class ();
10
11use MooseX::Types
12 -declare => [qw( Dir File )];
13
14use MooseX::Types::Moose qw(Object Str ArrayRef);
15
16subtype Dir,
17 as Object, where { $_->isa('Path::Class::Dir') };
18
19coerce Dir,
20 from Str, via { Path::Class::Dir->new($_) },
21 from ArrayRef, via { Path::Class::Dir->new(@$_) };
22
23MooseX::Getopt::OptionTypeMap->add_option_type_to_map(
24 Dir, '=s',
25);
26
27
28subtype 'Path::Class::Dir',
29 as Object, where { $_->isa('Path::Class::Dir') };
30
31coerce 'Path::Class::Dir',
32 from Str, via { Path::Class::Dir->new($_) },
33 from ArrayRef, via { Path::Class::Dir->new(@$_) };
34
35MooseX::Getopt::OptionTypeMap->add_option_type_to_map(
36 'Path::Class::Dir', '=s',
37);
38
39
40subtype File,
41 as Object, where { $_->isa('Path::Class::File') };
42
43coerce File,
44 from Str, via { Path::Class::File->new($_) },
45 from ArrayRef, via { Path::Class::File->new(@$_) };
46
47MooseX::Getopt::OptionTypeMap->add_option_type_to_map(
48 File, '=s',
49);
50
51
52subtype 'Path::Class::File',
53 as Object, where { $_->isa('Path::Class::File') };
54
55coerce 'Path::Class::File',
56 from Str, via { Path::Class::File->new($_) },
57 from ArrayRef, via { Path::Class::File->new(@$_) };
58
59MooseX::Getopt::OptionTypeMap->add_option_type_to_map(
60 'Path::Class::File', '=s',
61);
62
63
641;
65__END__
66
67=head1 NAME
68
69MooseX::Types::Path::Class - A Path::Class type library for Moose
70
71
72=head1 SYNOPSIS
73
74 package MyClass;
75 use Moose;
76 use MooseX::Types::Path::Class qw( Dir File );
77 with 'MooseX::Getopt'; # if you want the Getopt Role
78
79 has 'dir' => (
80 is => 'ro',
81 isa => Dir,
82 required => 1,
83 coerce => 1,
84 );
85
86 has 'file' => (
87 is => 'ro',
88 isa => File,
89 required => 1,
90 coerce => 1,
91 );
92
93 # these attributes are coerced to the
94 # appropriate Path::Class objects
255a36e7 95 MyClass->new( dir => '/some/directory/', file => '/some/file' );
fd56ddb6 96
97
98=head1 DESCRIPTION
99
100This is a utility that creates common L<Moose> subtypes, coercions and
101option specifications useful for dealing with L<Path::Class> objects
102as L<Moose> attributes.
103
104This module constructs coercions (see L<Moose::Util::TypeConstraints>)
105from both 'Str' and 'ArrayRef' to both L<Path::Class::Dir> and
106L<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>).
109
110This is just meant to be a central place for these constructs, so you
111don't have to worry about whether they've been created or not, and you're
112not tempted to copy them into yet another class (like I was).
113
114=head1 EXPORTS
115
116See L<MooseX::Types> for how these exports work.
117
118=over
119
120=item Dir is_Dir to_Dir
121
122=item File is_File to_File
123
124=back
125
126
127=head1 DEPENDENCIES
128
129L<Moose>, L<MooseX::Types>, L<MooseX::Getopt>, L<Path::Class>
130
131
132=head1 BUGS AND LIMITATIONS
133
134No bugs have been reported.
135
136
137=head1 AUTHOR
138
139Todd Hepler C<< <thepler@employees.org> >>
140
141
142=head1 LICENCE AND COPYRIGHT
143
144Copyright (c) 2007, Todd Hepler C<< <thepler@employees.org> >>. All rights reserved.
145
146This module is free software; you can redistribute it and/or
147modify it under the same terms as Perl itself. See L<perlartistic>.
148
149