unfinished work topic/arrayref_coercions
Karen Etheridge [Fri, 5 Jul 2013 19:01:53 +0000 (12:01 -0700)]
lib/MooseX/Types/Path/Class.pm
t/01.basic.t
t/04.arrayrefs.t [new file with mode: 0644]

index b8f75b3..8961fd3 100644 (file)
@@ -22,8 +22,12 @@ for my $type ( 'Path::Class::Dir', Dir ) {
         from ArrayRef, via { Path::Class::Dir->new(@$_) };
 
     coerce ArrayRef[$type],
-        from ArrayRef[Str], via { [ map { Path::Class::Dir->new($_) } @$_ ] },
-        from ArrayRef[ArrayRef], via { [ map { Path::Class::Dir->new(@$_) } @$_ ] };
+        from ArrayRef, via { 
+            print "### in ArrayRef[Str] -> ArrayRef[$type] coercion\n";
+            [ map { Path::Class::Dir->new($_) } @$_ ] };
+#        from ArrayRef[ArrayRef], via {
+#            print "### in ArrayRef[ArrayRef] -> ArrayRef[$type] coercion\n";
+#            [ map { Path::Class::Dir->new(@$_) } @$_ ] };
 }
 
 for my $type ( 'Path::Class::File', File ) {
@@ -31,9 +35,13 @@ for my $type ( 'Path::Class::File', File ) {
         from Str,      via { Path::Class::File->new($_) },
         from ArrayRef, via { Path::Class::File->new(@$_) };
 
-    coerce ArrayRef[$type],
-        from ArrayRef[Str], via { [ map { Path::Class::File->new($_) } @$_ ] },
-        from ArrayRef[ArrayRef], via { [ map { Path::Class::File->new(@$_) } @$_ ] };
+#    coerce ArrayRef[$type],
+#        from ArrayRef[Str], via {
+#            print "### in ArrayRef[Str] -> ArrayRef[$type] coercion\n";
+#            [ map { Path::Class::File->new($_) } @$_ ] },
+#        from ArrayRef[ArrayRef], via {
+#            print "### in ArrayRef[ArrayRef] -> ArrayRef[$type] coercion\n";
+#            [ map { Path::Class::File->new(@$_) } @$_ ] };
 }
 
 # optionally add Getopt option type
index 0295671..6cb528a 100644 (file)
@@ -7,6 +7,7 @@ use strict;
     package Foo;
     use Moose;
     use MooseX::Types::Path::Class;
+    use MooseX::Types::Moose qw(ArrayRef);
 
     has 'dir' => (
         is       => 'ro',
@@ -22,13 +23,13 @@ use strict;
 
     has 'dirs' => (
         is       => 'ro',
-        isa      => 'ArrayRef[Path::Class::Dir]',
+        isa      => ArrayRef['Path::Class::Dir'],
         coerce   => 1,
     );
 
     has 'files' => (
         is       => 'ro',
-        isa      => 'ArrayRef[Path::Class::File]',
+        isa      => ArrayRef['Path::Class::File'],
         coerce   => 1,
     );
 }
@@ -90,6 +91,10 @@ for my $class (qw(Foo Bar)) {
 
 
 
+__END__
+
+
+
 my @dirs = (dir('', 'tmp'), dir('', 'etc'));
 my @files = (dir('', 'tmp', 'foo'), dir('', 'etc', 'foo'));
 
@@ -106,11 +111,12 @@ my $check_arrays = sub {
 #    cmp_ok( ($o->files)->[$_], 'eq', "$files[$_]", "file is $files[$_]" ) foreach (0.. @files);
 };
 
-for my $class (qw(Foo Bar)) {
+# XXX Foo omitted
+for my $class (qw(Bar)) {
 
 my %args = (
 dirs => [ map { "$_" } @dirs ],
-file => [ map { [ split('/', $_->stringify) ] } @files ],
+#file => [ map { [ split('/', $_->stringify) ] } @files ],
 );
 use Data::Dumper;
 print "### constructing $class with args: ", Dumper(\%args);
@@ -123,3 +129,5 @@ print "### constructing $class with args: ", Dumper(\%args);
     $check_arrays->($o);
 }
 
+
+
diff --git a/t/04.arrayrefs.t b/t/04.arrayrefs.t
new file mode 100644 (file)
index 0000000..985e807
--- /dev/null
@@ -0,0 +1,8 @@
+use strict;
+use warnings;
+use MooseX::Types::Path::Class qw( Dir File );
+use MooseX::Types::Moose qw(ArrayRef);
+
+# just validate directly, without using a class:
+(ArrayRef[Dir])->assert_coerce(['/tmp', '/etc']);
+exit;