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