File Coverage

blib/lib/MooseX/Types/Path/Class.pm
Criterion Covered Total %
statement 18 18 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 24 24 100.0


line stmt bran cond sub pod time code
1 2     2   362872 use strict;
  2         4  
  2         45  
2 2     2   6 use warnings;
  2         2  
  2         113  
3             package MooseX::Types::Path::Class; # git description: v0.08-5-gc1e201f
4             # ABSTRACT: A Path::Class type library for Moose
5              
6             our $VERSION = '0.09';
7              
8 2     2   718 use Path::Class 0.16 ();
  2         59600  
  2         69  
9              
10             use MooseX::Types
11 2     2   898 -declare => [qw( Dir File )];
  2         411343  
  2         12  
12              
13 2     2   6185 use MooseX::Types::Moose qw(Str ArrayRef);
  2         18621  
  2         12  
14 2     2   6304 use if MooseX::Types->VERSION >= 0.42, 'namespace::autoclean';
  2         2  
  2         37  
15              
16             class_type('Path::Class::Dir');
17             class_type('Path::Class::File');
18              
19             subtype Dir, as 'Path::Class::Dir';
20             subtype File, as 'Path::Class::File';
21              
22             for my $type ( 'Path::Class::Dir', Dir ) {
23             coerce $type,
24             from Str, via { Path::Class::Dir->new($_) },
25             from ArrayRef, via { Path::Class::Dir->new(@$_) };
26             }
27              
28             for my $type ( 'Path::Class::File', File ) {
29             coerce $type,
30             from Str, via { Path::Class::File->new($_) },
31             from ArrayRef, via { Path::Class::File->new(@$_) };
32             }
33              
34             # optionally add Getopt option type
35             eval { require MooseX::Getopt; };
36             if ( !$@ ) {
37             MooseX::Getopt::OptionTypeMap->add_option_type_to_map( $_, '=s', )
38             for ( 'Path::Class::Dir', 'Path::Class::File', Dir, File, );
39             }
40              
41             1;
42              
43             __END__
44              
45             =pod
46              
47             =encoding UTF-8
48              
49             =head1 NAME
50              
51             MooseX::Types::Path::Class - A Path::Class type library for Moose
52              
53             =head1 VERSION
54              
55             version 0.09
56              
57             =head1 SYNOPSIS
58              
59             package MyClass;
60             use Moose;
61             use MooseX::Types::Path::Class;
62             with 'MooseX::Getopt'; # optional
63              
64             has 'dir' => (
65             is => 'ro',
66             isa => 'Path::Class::Dir',
67             required => 1,
68             coerce => 1,
69             );
70              
71             has 'file' => (
72             is => 'ro',
73             isa => 'Path::Class::File',
74             required => 1,
75             coerce => 1,
76             );
77              
78             # these attributes are coerced to the
79             # appropriate Path::Class objects
80             MyClass->new( dir => '/some/directory/', file => '/some/file' );
81              
82             =head1 DESCRIPTION
83              
84             MooseX::Types::Path::Class creates common L<Moose> types,
85             coercions and option specifications useful for dealing
86             with L<Path::Class> objects as L<Moose> attributes.
87              
88             Coercions (see L<Moose::Util::TypeConstraints>) are made
89             from both C<Str> and C<ArrayRef> to both L<Path::Class::Dir> and
90             L<Path::Class::File> objects. If you have L<MooseX::Getopt> installed,
91             the C<Getopt> option type ("=s") will be added for both
92             L<Path::Class::Dir> and L<Path::Class::File>.
93              
94             =head1 EXPORTS
95              
96             None of these are exported by default. They are provided via
97             L<MooseX::Types>.
98              
99             =over
100              
101             =item Dir, File
102              
103             These exports can be used instead of the full class names. Example:
104              
105             package MyClass;
106             use Moose;
107             use MooseX::Types::Path::Class qw(Dir File);
108              
109             has 'dir' => (
110             is => 'ro',
111             isa => Dir,
112             required => 1,
113             coerce => 1,
114             );
115              
116             has 'file' => (
117             is => 'ro',
118             isa => File,
119             required => 1,
120             coerce => 1,
121             );
122              
123             Note that there are no quotes around C<Dir> or C<File>.
124              
125             =item is_Dir($value), is_File($value)
126              
127             Returns true or false based on whether $value is a valid C<Dir> or C<File>.
128              
129             =item to_Dir($value), to_File($value)
130              
131             Attempts to coerce $value to a C<Dir> or C<File>. Returns the coerced value
132             or false if the coercion failed.
133              
134             =back
135              
136             =head1 SEE ALSO
137              
138             L<MooseX::Types::Path::Class::MoreCoercions>, L<MooseX::FileAttribute>, L<MooseX::Types::URI>
139              
140             =head1 DEPENDENCIES
141              
142             L<Moose>, L<MooseX::Types>, L<Path::Class>
143              
144             =head1 SUPPORT
145              
146             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Types-Path-Class>
147             (or L<bug-MooseX-Types-Path-Class@rt.cpan.org|mailto:bug-MooseX-Types-Path-Class@rt.cpan.org>).
148              
149             There is also a mailing list available for users of this distribution, at
150             L<http://lists.perl.org/list/moose.html>.
151              
152             There is also an irc channel available for users of this distribution, at
153             L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>.
154              
155             =head1 AUTHOR
156              
157             Todd Hepler <thepler@employees.org>
158              
159             =head1 CONTRIBUTORS
160              
161             =for stopwords Karen Etheridge Jonathan Rockway Yuval Kogman
162              
163             =over 4
164              
165             =item *
166              
167             Karen Etheridge <ether@cpan.org>
168              
169             =item *
170              
171             Jonathan Rockway <jon@jrock.us>
172              
173             =item *
174              
175             Yuval Kogman <nothingmuch@woobling.org>
176              
177             =back
178              
179             =head1 COPYRIGHT AND LICENSE
180              
181             This software is copyright (c) 2007 by Todd Hepler.
182              
183             This is free software; you can redistribute it and/or modify it under
184             the same terms as the Perl 5 programming language system itself.
185              
186             =cut