| 1 | package MouseX::Types::Path::Class; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use 5.008_001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use Path::Class (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use MouseX::Types -declare => [qw(Dir File)]; # export Types | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | ▶ | use MouseX::Types::Mouse qw(Str ArrayRef); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 3 | our $VERSION = '0.07'; | |||||||||
| 11 | |||||||||||
| 12 | 3 | class_type 'Path::Class::Dir'; | |||||||||
| 13 | 3 | class_type 'Path::Class::File'; | |||||||||
| 14 | |||||||||||
| 15 | 3 | subtype Dir, as 'Path::Class::Dir'; | |||||||||
| 16 | 3 | subtype File, as 'Path::Class::File'; | |||||||||
| 17 | |||||||||||
| 18 | 3 | for my $type ( 'Path::Class::Dir', Dir ) { | |||||||||
| 19 | coerce $type, | ||||||||||
| 20 | 6 | ▶ | from Str, via { Path::Class::Dir->new($_) }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 0 | ▶ | from ArrayRef, via { Path::Class::Dir->new(@$_) }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 3 | for my $type ( 'Path::Class::File', File ) { | |||||||||
| 25 | coerce $type, | ||||||||||
| 26 | 2 | ▶ | from Str, via { Path::Class::File->new($_) }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 4 | ▶ | from ArrayRef, via { Path::Class::File->new(@$_) }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | # optionally add Getopt option type | ||||||||||
| 31 | 3 | eval { require MouseX::Getopt }; | |||||||||
| 32 | 3 | ▶ | unless ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | MouseX::Getopt::OptionTypeMap->add_option_type_to_map($_, '=s') | ||||||||||
| 34 | 3 | for ( 'Path::Class::Dir', 'Path::Class::File', Dir, File ); | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 3 | 1; | |||||||||
| 38 | |||||||||||
| 39 | =head1 NAME | ||||||||||
| 40 | |||||||||||
| 41 | MouseX::Types::Path::Class - A Path::Class type library for Mouse | ||||||||||
| 42 | |||||||||||
| 43 | =head1 SYNOPSIS | ||||||||||
| 44 | |||||||||||
| 45 | =head2 CLASS TYPES | ||||||||||
| 46 | |||||||||||
| 47 | package MyApp; | ||||||||||
| 48 | use Mouse; | ||||||||||
| 49 | use MouseX::Types::Path::Class; | ||||||||||
| 50 | |||||||||||
| 51 | has 'dir' => ( | ||||||||||
| 52 | is => 'ro', | ||||||||||
| 53 | isa => 'Path::Class::Dir', | ||||||||||
| 54 | required => 1, | ||||||||||
| 55 | coerce => 1, | ||||||||||
| 56 | ); | ||||||||||
| 57 | |||||||||||
| 58 | has 'file' => ( | ||||||||||
| 59 | is => 'ro', | ||||||||||
| 60 | isa => 'Path::Class::File', | ||||||||||
| 61 | required => 1, | ||||||||||
| 62 | coerce => 1, | ||||||||||
| 63 | ); | ||||||||||
| 64 | |||||||||||
| 65 | =head2 CUSTOM TYPES | ||||||||||
| 66 | |||||||||||
| 67 | package MyApp; | ||||||||||
| 68 | use Mouse; | ||||||||||
| 69 | use MouseX::Types::Path::Class qw(Dir File); | ||||||||||
| 70 | |||||||||||
| 71 | has 'dir' => ( | ||||||||||
| 72 | is => 'ro', | ||||||||||
| 73 | isa => Dir, | ||||||||||
| 74 | required => 1, | ||||||||||
| 75 | coerce => 1, | ||||||||||
| 76 | ); | ||||||||||
| 77 | |||||||||||
| 78 | has 'file' => ( | ||||||||||
| 79 | is => 'ro', | ||||||||||
| 80 | isa => File, | ||||||||||
| 81 | required => 1, | ||||||||||
| 82 | coerce => 1, | ||||||||||
| 83 | ); | ||||||||||
| 84 | |||||||||||
| 85 | =head1 DESCRIPTION | ||||||||||
| 86 | |||||||||||
| 87 | MouseX::Types::Path::Class creates common L<Mouse> types, | ||||||||||
| 88 | coercions and option specifications useful for dealing | ||||||||||
| 89 | with L<Path::Class> objects as L<Mouse> attributes. | ||||||||||
| 90 | |||||||||||
| 91 | Coercions (see L<Mouse::Util::TypeConstraints>) are made | ||||||||||
| 92 | from both C<Str> and C<ArrayRef> to both L<Path::Class::Dir> and | ||||||||||
| 93 | L<Path::Class::File> objects. | ||||||||||
| 94 | If you have L<MouseX::Getopt> installed, | ||||||||||
| 95 | the Getopt option type ("=s") will be added for both | ||||||||||
| 96 | L<Path::Class::Dir> and L<Path::Class::File>. | ||||||||||
| 97 | |||||||||||
| 98 | =head1 TYPES | ||||||||||
| 99 | |||||||||||
| 100 | =head2 Dir | ||||||||||
| 101 | |||||||||||
| 102 | =over 4 | ||||||||||
| 103 | |||||||||||
| 104 | A L<Path::Class::Dir> class type. | ||||||||||
| 105 | |||||||||||
| 106 | Coerces from C<Str> and C<ArrayRef> via L<Path::Class::Dir/new>. | ||||||||||
| 107 | |||||||||||
| 108 | =back | ||||||||||
| 109 | |||||||||||
| 110 | =head2 File | ||||||||||
| 111 | |||||||||||
| 112 | =over 4 | ||||||||||
| 113 | |||||||||||
| 114 | A L<Path::Class::File> class type. | ||||||||||
| 115 | |||||||||||
| 116 | Coerces from C<Str> and C<ArrayRef> via L<Path::Class::File/new>. | ||||||||||
| 117 | |||||||||||
| 118 | =back | ||||||||||
| 119 | |||||||||||
| 120 | =head1 AUTHOR | ||||||||||
| 121 | |||||||||||
| 122 | NAKAGAWA Masaki E<lt>masaki@cpan.orgE<gt> | ||||||||||
| 123 | |||||||||||
| 124 | =head1 THANKS TO | ||||||||||
| 125 | |||||||||||
| 126 | L<MooseX::Types::Path::Class/AUTHOR> | ||||||||||
| 127 | |||||||||||
| 128 | =head1 LICENSE | ||||||||||
| 129 | |||||||||||
| 130 | This library is free software; you can redistribute it and/or modify | ||||||||||
| 131 | it under the same terms as Perl itself. | ||||||||||
| 132 | |||||||||||
| 133 | =head1 SEE ALSO | ||||||||||
| 134 | |||||||||||
| 135 | L<Mouse>, L<MouseX::Types>, | ||||||||||
| 136 | |||||||||||
| 137 | L<Path::Class>, | ||||||||||
| 138 | |||||||||||
| 139 | L<MooseX::Types::Path::Class> | ||||||||||
| 140 | |||||||||||
| 141 | =cut | ||||||||||