Changeset 28138 for lang/perl/MouseX-Types-URI
- Timestamp:
- 01/08/09 01:59:53 (4 years ago)
- Location:
- lang/perl/MouseX-Types-URI/trunk
- Files:
-
- 1 added
- 4 modified
-
MANIFEST (modified) (1 diff)
-
Makefile.PL (modified) (1 diff)
-
lib/MouseX/Types/URI.pm (modified) (5 diffs)
-
t/01_basic.t (added)
-
xt/03_podspell.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/MouseX-Types-URI/trunk/MANIFEST
r28070 r28138 24 24 README 25 25 t/00_compile.t 26 t/01_basic.t 26 27 xt/01_pod.t 27 28 xt/02_podcoverage.t -
lang/perl/MouseX-Types-URI/trunk/Makefile.PL
r28070 r28138 10 10 requires 'URI::FromHash'; 11 11 12 recommends 'MouseX::Getopt'; 13 12 14 tests 't/*.t'; 13 15 test_requires 'Test::More'; -
lang/perl/MouseX-Types-URI/trunk/lib/MouseX/Types/URI.pm
r28070 r28138 5 5 use 5.8.1; 6 6 use URI; 7 use URI::WithBase; 8 use URI::FromHash qw(uri); 9 use URI::file; 7 10 use URI::data; 8 use URI::file;9 use URI::FromHash qw(uri);10 use URI::WithBase;11 11 use Mouse::TypeRegistry; 12 12 use MouseX::Types::Mouse qw(Str ScalarRef HashRef); … … 15 15 16 16 use MouseX::Types 17 -declare => [qw(Uri DataUri FileUri)]; # export Types17 -declare => [qw(Uri FileUri DataUri)]; # export Types 18 18 require Mouse; # for Mouse::TypeRegistry (Mouse::load_class) 19 19 20 20 our $VERSION = '0.01'; 21 21 22 class_type $_ => { class => $_ } 23 for qw( URI URI::WithBase URI::data URI::file ); 22 subtype 'URI', # doesn't use class_type for 'URI' 23 where { $_->isa('URI') or $_->isa('URI::WithBase') }; 24 class_type $_ => { class => $_ } for qw( URI::file URI::data ); 24 25 25 subtype Uri, where { $_->isa('URI') or $_->isa('URI::WithBase') }; 26 subtype Uri, as 'URI'; 27 subtype FileUri, as 'URI::file'; 26 28 subtype DataUri, as 'URI::data'; 27 subtype FileUri, as 'URI::file';28 29 29 30 for my $type ( 'URI', Uri ) { 30 31 coerce $type, 31 32 from Str, via { URI->new($_) }, 32 from ScalarRef, via { my $u = URI->new( "data:"); $u->data($$_); $u },33 from ScalarRef, via { my $u = URI->new('data:'); $u->data($$_); $u }, 33 34 from HashRef, via { uri(%$_) }, 34 35 from 'Path::Class::Dir', via { URI::file->new($_) }, 35 36 from 'Path::Class::File', via { URI::file->new($_) }; 36 }37 38 for my $type ( 'URI::data', DataUri ) {39 coerce $type,40 from Str, via { my $u = URI->new("data:"); $u->data($_); $u },41 from ScalarRef, via { my $u = URI->new("data:"); $u->data($$_); $u };42 37 } 43 38 … … 47 42 from 'Path::Class::Dir', via { URI::file->new($_) }, 48 43 from 'Path::Class::File', via { URI::file->new($_) }; 44 } 45 46 for my $type ( 'URI::data', DataUri ) { 47 coerce $type, 48 from Str, via { 49 /^data:/ ? URI->new($_) : do { my $u = URI->new('data:'); $u->data($_); $u } 50 }, 51 from ScalarRef, via { 52 $$_ =~ /^data:/ ? URI->new($$_) : do { my $u = URI->new('data:'); $u->data($$_); $u } 53 }; 54 } 55 56 # optionally add Getopt option type 57 eval { require MouseX::Getopt::OptionTypeMap }; 58 unless ($@) { 59 MouseX::Getopt::OptionTypeMap->add_option_type_to_map($_, '=s') 60 for ( 'URI', 'URI::data', 'URI::file', Uri, DataUri, FileUri ); 49 61 } 50 62 … … 57 69 =head1 SYNOPSIS 58 70 71 =head2 CLASS TYPES 72 73 package MyApp; 74 use Mouse; 75 use MouseX::Types::URI; 76 with 'MouseX::Getopt'; # optional 77 78 has 'uri' => ( 79 is => 'rw', 80 isa => 'URI', 81 coerce => 1, 82 ); 83 84 has 'data' => ( 85 is => 'rw', 86 isa => 'URI::data', 87 coerce => 1, 88 ); 89 90 has 'file' => ( 91 is => 'rw', 92 isa => 'URI::file', 93 coerce => 1, 94 ); 95 96 =head2 CUSTOM TYPES 97 59 98 package MyApp; 60 99 use Mouse; 61 100 use MouseX::Types::URI qw(Uri DataUri FileUri); 101 with 'MouseX::Getopt'; # optional 62 102 63 103 has 'uri' => ( … … 84 124 coercions and option specifications useful for dealing 85 125 with L<URI>s as L<Mouse> attributes. 126 127 Coercions (see L<Mouse::TypeRegistry>) are made from 128 C<Str>, C<ScalarRef>, C<HashRef>, 129 L<Path::Class::Dir> and L<Path::Class::File> to 130 L<URI>, L<URI::data> and L<URI::file> objects. 131 132 If you have L<MouseX::Getopt> installed, 133 the Getopt option type ("=s") will be added 134 for L<URI>, L<URI::data> and L<URI::file>. 86 135 87 136 =head1 TYPES -
lang/perl/MouseX-Types-URI/trunk/xt/03_podspell.t
r28070 r28138 22 22 Yuval Kogman 23 23 Uri DataUri FileUri 24 Getopt
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)