Show
Ignore:
Timestamp:
01/08/09 01:59:53 (4 years ago)
Author:
masaki
Message:

add tests

Location:
lang/perl/MouseX-Types-URI/trunk
Files:
1 added
4 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/MouseX-Types-URI/trunk/MANIFEST

    r28070 r28138  
    2424README 
    2525t/00_compile.t 
     26t/01_basic.t 
    2627xt/01_pod.t 
    2728xt/02_podcoverage.t 
  • lang/perl/MouseX-Types-URI/trunk/Makefile.PL

    r28070 r28138  
    1010requires 'URI::FromHash'; 
    1111 
     12recommends 'MouseX::Getopt'; 
     13 
    1214tests 't/*.t'; 
    1315test_requires 'Test::More'; 
  • lang/perl/MouseX-Types-URI/trunk/lib/MouseX/Types/URI.pm

    r28070 r28138  
    55use 5.8.1; 
    66use URI; 
     7use URI::WithBase; 
     8use URI::FromHash qw(uri); 
     9use URI::file; 
    710use URI::data; 
    8 use URI::file; 
    9 use URI::FromHash qw(uri); 
    10 use URI::WithBase; 
    1111use Mouse::TypeRegistry; 
    1212use MouseX::Types::Mouse qw(Str ScalarRef HashRef); 
     
    1515 
    1616use MouseX::Types 
    17     -declare => [qw(Uri DataUri FileUri)]; # export Types 
     17    -declare => [qw(Uri FileUri DataUri)]; # export Types 
    1818require Mouse;                             # for Mouse::TypeRegistry (Mouse::load_class) 
    1919 
    2020our $VERSION = '0.01'; 
    2121 
    22 class_type $_ => { class => $_ } 
    23     for qw( URI URI::WithBase URI::data URI::file ); 
     22subtype 'URI', # doesn't use class_type for 'URI' 
     23    where { $_->isa('URI') or $_->isa('URI::WithBase') }; 
     24class_type $_ => { class => $_ } for qw( URI::file URI::data ); 
    2425 
    25 subtype Uri,     where { $_->isa('URI') or $_->isa('URI::WithBase') }; 
     26subtype Uri,     as 'URI'; 
     27subtype FileUri, as 'URI::file'; 
    2628subtype DataUri, as 'URI::data'; 
    27 subtype FileUri, as 'URI::file'; 
    2829 
    2930for my $type ( 'URI', Uri ) { 
    3031    coerce $type, 
    3132        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 }, 
    3334        from HashRef,             via { uri(%$_) }, 
    3435        from 'Path::Class::Dir',  via { URI::file->new($_) }, 
    3536        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 }; 
    4237} 
    4338 
     
    4742        from 'Path::Class::Dir',  via { URI::file->new($_) }, 
    4843        from 'Path::Class::File', via { URI::file->new($_) }; 
     44} 
     45 
     46for 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 
     57eval { require MouseX::Getopt::OptionTypeMap }; 
     58unless ($@) { 
     59    MouseX::Getopt::OptionTypeMap->add_option_type_to_map($_, '=s') 
     60        for ( 'URI', 'URI::data', 'URI::file', Uri, DataUri, FileUri ); 
    4961} 
    5062 
     
    5769=head1 SYNOPSIS 
    5870 
     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 
    5998  package MyApp; 
    6099  use Mouse; 
    61100  use MouseX::Types::URI qw(Uri DataUri FileUri); 
     101  with 'MouseX::Getopt'; # optional 
    62102 
    63103  has 'uri' => ( 
     
    84124coercions and option specifications useful for dealing 
    85125with L<URI>s as L<Mouse> attributes. 
     126 
     127Coercions (see L<Mouse::TypeRegistry>) are made from 
     128C<Str>, C<ScalarRef>, C<HashRef>, 
     129L<Path::Class::Dir> and L<Path::Class::File> to 
     130L<URI>, L<URI::data> and L<URI::file> objects. 
     131 
     132If you have L<MouseX::Getopt> installed, 
     133the Getopt option type ("=s") will be added 
     134for L<URI>, L<URI::data> and L<URI::file>. 
    86135 
    87136=head1 TYPES 
  • lang/perl/MouseX-Types-URI/trunk/xt/03_podspell.t

    r28070 r28138  
    2222Yuval Kogman 
    2323Uri DataUri FileUri 
     24Getopt