r42565 - in /branches/upstream/libmoosex-types-perl/current: Changes MANIFEST META.yml Makefile.PL README lib/MooseX/Types.pm t/21_coerce_parameterized_types.t

gregoa at users.alioth.debian.org gregoa at users.alioth.debian.org
Sun Aug 23 17:24:04 UTC 2009


Author: gregoa
Date: Sun Aug 23 17:23:59 2009
New Revision: 42565

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=42565
Log:
[svn-upgrade] Integrating new upstream version, libmoosex-types-perl (0.18)

Added:
    branches/upstream/libmoosex-types-perl/current/t/21_coerce_parameterized_types.t
Modified:
    branches/upstream/libmoosex-types-perl/current/Changes
    branches/upstream/libmoosex-types-perl/current/MANIFEST
    branches/upstream/libmoosex-types-perl/current/META.yml
    branches/upstream/libmoosex-types-perl/current/Makefile.PL
    branches/upstream/libmoosex-types-perl/current/README
    branches/upstream/libmoosex-types-perl/current/lib/MooseX/Types.pm

Modified: branches/upstream/libmoosex-types-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-perl/current/Changes?rev=42565&op=diff
==============================================================================
--- branches/upstream/libmoosex-types-perl/current/Changes (original)
+++ branches/upstream/libmoosex-types-perl/current/Changes Sun Aug 23 17:23:59 2009
@@ -1,4 +1,7 @@
 Revision history for MooseX-Types
+
+0.18    Sat Aug 22 12:50:42 EDT 2009
+        - fix coercions on parameterized types (Hans Dieter Pearcey).
 
 0.17    Tue Aug 18 02:32:31 EDT 2009
         - Documentation typo fix (Dave Rolsky).

Modified: branches/upstream/libmoosex-types-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-perl/current/MANIFEST?rev=42565&op=diff
==============================================================================
--- branches/upstream/libmoosex-types-perl/current/MANIFEST (original)
+++ branches/upstream/libmoosex-types-perl/current/MANIFEST Sun Aug 23 17:23:59 2009
@@ -35,6 +35,7 @@
 t/18_combined_libs.t
 t/19_typelib_with_role.t
 t/20_union_with_string_type.t
+t/21_coerce_parameterized_types.t
 t/lib/Combined.pm
 t/lib/DecoratorLibrary.pm
 t/lib/IntrospectTypeExports.pm

Modified: branches/upstream/libmoosex-types-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-perl/current/META.yml?rev=42565&op=diff
==============================================================================
--- branches/upstream/libmoosex-types-perl/current/META.yml (original)
+++ branches/upstream/libmoosex-types-perl/current/META.yml Sun Aug 23 17:23:59 2009
@@ -5,6 +5,7 @@
 build_requires:
   ExtUtils::MakeMaker: 6.42
   FindBin: 0
+  Test::Exception: 0
   Test::Moose: 0
   Test::More: 0.80
 configure_requires:
@@ -23,7 +24,7 @@
 provides:
   MooseX::Types:
     file: lib/MooseX/Types.pm
-    version: 0.17
+    version: 0.18
   MooseX::Types::Base:
     file: lib/MooseX/Types/Base.pm
   MooseX::Types::CheckedUtilExports:
@@ -51,4 +52,4 @@
   perl: 5.8.0
 resources:
   license: http://dev.perl.org/licenses/
-version: 0.17
+version: 0.18

Modified: branches/upstream/libmoosex-types-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-perl/current/Makefile.PL?rev=42565&op=diff
==============================================================================
--- branches/upstream/libmoosex-types-perl/current/Makefile.PL (original)
+++ branches/upstream/libmoosex-types-perl/current/Makefile.PL Sun Aug 23 17:23:59 2009
@@ -12,6 +12,7 @@
 build_requires  q{Test::More},                  '0.80';
 build_requires  q{FindBin},                     0;
 build_requires  q{Test::Moose},                 0;
+build_requires  q{Test::Exception},             0;
 
 requires        q{Moose},                       '0.61';
 requires        q{Sub::Install},                '0.924';

Modified: branches/upstream/libmoosex-types-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-perl/current/README?rev=42565&op=diff
==============================================================================
--- branches/upstream/libmoosex-types-perl/current/README (original)
+++ branches/upstream/libmoosex-types-perl/current/README Sun Aug 23 17:23:59 2009
@@ -11,6 +11,7 @@
             PositiveInt NegativeInt
             ArrayRefOfPositiveInt ArrayRefOfAtLeastThreeNegativeInts
             LotsOfInnerConstraints StrOrArrayRef
+            MyDateTime
         )];
 
       # import builtin types
@@ -21,8 +22,8 @@
           as Int, 
           where { $_ > 0 },
           message { "Int is not larger than 0" };
-      
-  subtype NegativeInt,
+  
+      subtype NegativeInt,
           as Int,
           where { $_ < 0 },
           message { "Int is not smaller than 0" };
@@ -33,25 +34,31 @@
               via { 1 };
 
       # with parameterized constraints.
-      
-  subtype ArrayRefOfPositiveInt,
+  
+      subtype ArrayRefOfPositiveInt,
         as ArrayRef[PositiveInt];
-        
-  subtype ArrayRefOfAtLeastThreeNegativeInts,
+    
+      subtype ArrayRefOfAtLeastThreeNegativeInts,
         as ArrayRef[NegativeInt],
         where { scalar(@$_) > 2 };
 
       subtype LotsOfInnerConstraints,
         as ArrayRef[ArrayRef[HashRef[Int]]];
-        
-  # with TypeConstraint Unions
-      
-  subtype StrOrArrayRef,
+    
+      # with TypeConstraint Unions
+  
+      subtype StrOrArrayRef,
         as Str|ArrayRef;
 
+      # class types
+
       class_type 'DateTime';
 
-      coerce 'DateTime',
+      # or better
+
+      class_type MyDateTime, { class => 'DateTime' };
+
+      coerce MyDateTime,
         from HashRef,
         via { DateTime->new(%$_) };
 
@@ -252,8 +259,8 @@
 
         use Moose;
         use MooseX::Types::Moose qw(HashRef Int);
-        
-    has 'attr' => (isa=>HashRef|Int);
+    
+        has 'attr' => (isa=>HashRef|Int);
 
     And everything should just work as you'd think.
 
@@ -324,21 +331,21 @@
     additional export targets. For example if you do:
 
         package TypeAndSubExporter; {
-            
-        use MooseX::Types::Moose qw(Str);
+        
+            use MooseX::Types::Moose qw(Str);
             use MooseX::Types -declare => [qw(MyStr)];
             use Sub::Exporter -setup => { exports => [ qw(something) ] };
-            
-        subtype MyStr,
+        
+            subtype MyStr,
              as Str;
-             
-        sub something {
+         
+            sub something {
                 return 1;
             }    
-            
-    } 1;
         
-    package Foo; {
+        } 1;
+    
+        package Foo; {
             use TypeAndSubExporter qw(MyStr);
         } 1;
 
@@ -370,6 +377,8 @@
 
     rafl: Florian Ragwitz <rafl at debian.org>
 
+    hdp: Hans Dieter Pearcey <hdp at cpan.org>
+
 COPYRIGHT & LICENSE
     Copyright (c) 2007-2009 Robert Sedlacek
 

Modified: branches/upstream/libmoosex-types-perl/current/lib/MooseX/Types.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-perl/current/lib/MooseX/Types.pm?rev=42565&op=diff
==============================================================================
--- branches/upstream/libmoosex-types-perl/current/lib/MooseX/Types.pm (original)
+++ branches/upstream/libmoosex-types-perl/current/lib/MooseX/Types.pm Sun Aug 23 17:23:59 2009
@@ -20,7 +20,7 @@
 use namespace::clean -except => [qw( meta )];
 
 use 5.008;
-our $VERSION = '0.17';
+our $VERSION = '0.18';
 my $UndefMsg = q{Action for type '%s' not yet defined in library '%s'};
 
 =head1 SYNOPSIS
@@ -35,6 +35,7 @@
         PositiveInt NegativeInt
         ArrayRefOfPositiveInt ArrayRefOfAtLeastThreeNegativeInts
         LotsOfInnerConstraints StrOrArrayRef
+	MyDateTime
     )];
 
   # import builtin types
@@ -73,9 +74,15 @@
   subtype StrOrArrayRef,
     as Str|ArrayRef;
 
+  # class types
+
   class_type 'DateTime';
 
-  coerce 'DateTime',
+  # or better
+
+  class_type MyDateTime, { class => 'DateTime' };
+
+  coerce MyDateTime,
     from HashRef,
     via { DateTime->new(%$_) };
 
@@ -420,7 +427,16 @@
 sub create_arged_type_constraint {
     my ($class, $name, @args) = @_;  
     my $type_constraint = Moose::Util::TypeConstraints::find_or_create_type_constraint("$name");
-	return $type_constraint->parameterize(@args);
+    my $parameterized = $type_constraint->parameterize(@args);
+    # It's obnoxious to have to parameterize before looking for the TC, but the
+    # alternative is to hard-code the assumption that the name is
+    # "$name[$args[0]]", which would be worse.
+    if (my $existing =
+        Moose::Util::TypeConstraints::find_type_constraint($parameterized->name)) {
+        return $existing;
+    }
+    Moose::Util::TypeConstraints::register_type_constraint($parameterized);
+    return $parameterized;
 }
 
 =head2 create_base_type_constraint ($name)
@@ -577,6 +593,8 @@
 
 rafl: Florian Ragwitz <rafl at debian.org>
 
+hdp: Hans Dieter Pearcey <hdp at cpan.org>
+
 =head1 COPYRIGHT & LICENSE
 
 Copyright (c) 2007-2009 Robert Sedlacek

Added: branches/upstream/libmoosex-types-perl/current/t/21_coerce_parameterized_types.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libmoosex-types-perl/current/t/21_coerce_parameterized_types.t?rev=42565&op=file
==============================================================================
--- branches/upstream/libmoosex-types-perl/current/t/21_coerce_parameterized_types.t (added)
+++ branches/upstream/libmoosex-types-perl/current/t/21_coerce_parameterized_types.t Sun Aug 23 17:23:59 2009
@@ -1,0 +1,52 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::Exception;
+
+use Test::More tests => 2;
+
+BEGIN {
+    package TypeLib;
+    use MooseX::Types -declare => [qw/
+	MyChar MyDigit ArrayRefOfMyCharOrDigit
+    /];
+    use MooseX::Types::Moose qw/ArrayRef Str Int/;
+
+    subtype MyChar, as Str, where {
+	length == 1
+    };
+
+    subtype MyDigit, as Int, where {
+	length == 1
+    };
+
+    coerce ArrayRef[MyChar|MyDigit], from Str, via {
+	[split //]
+    };
+
+# same thing with an explicit subtype
+    subtype ArrayRefOfMyCharOrDigit, as ArrayRef[MyChar|MyDigit];
+
+    coerce ArrayRefOfMyCharOrDigit, from Str, via {
+	[split //]
+    };
+}
+{
+    package AClass;
+    use Moose;
+    BEGIN { TypeLib->import(qw/
+	MyChar MyDigit ArrayRefOfMyCharOrDigit/
+    ) };
+    use MooseX::Types::Moose 'ArrayRef';
+
+    has parameterized => (is => 'rw', isa => ArrayRef[MyChar|MyDigit], coerce => 1);
+    has subtype_parameterized => (is => 'rw', isa => ArrayRefOfMyCharOrDigit, coerce => 1);
+}
+
+my $instance = AClass->new;
+
+lives_ok { $instance->parameterized('foo') }
+    'coercion applied to parameterized type';
+
+lives_ok { $instance->subtype_parameterized('foo') }
+    'coercion applied to subtype';




More information about the Pkg-perl-cvs-commits mailing list